wangchuanjin 1 éve
szülő
commit
3e0821da69
2 módosított fájl, 44 hozzáadás és 22 törlés
  1. 39 17
      api/internal/service/network.go
  2. 5 5
      api/internal/service/network_test.go

+ 39 - 17
api/internal/service/network.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"database/sql"
 	"fmt"
+	"log"
 	"math"
 	"sort"
 	"strings"
@@ -482,6 +483,10 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 	}
 	sqlAppendArgs := []interface{}{}
 	sqlAppend1 := ""
+	if in.Type != "" {
+		sqlAppend1 += ` and a.itype=?`
+		sqlAppendArgs = append(sqlAppendArgs, n.TypeStrConvert(in.Type))
+	}
 	if in.Starttime != "" {
 		sqlAppend1 += ` and a.create_time>=?`
 		sqlAppendArgs = append(sqlAppendArgs, in.Starttime+" 00:00:00")
@@ -502,19 +507,36 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 	var count int64
 	start := (in.Current_page - 1) * in.Page_size
 	end := start + in.Page_size
-	dbPaging := in.Buyercount_start == 0 && in.Buyercount_end == 0 && in.Monitor == 0 && in.Monitorcount_start == 0 && in.Monitorcount_end == 0 && in.Project_matchme == 0 && in.Order_amount == 0 && in.Type == ""
+	dbPaging := in.Buyercount_start == 0 && in.Buyercount_end == 0 && in.Monitor == 0 && in.Monitorcount_start == 0 && in.Monitorcount_end == 0 && in.Project_matchme == 0 && in.Order_amount == 0
 	args := []interface{}{in.PositionId, in.PositionId, in.PositionId}
 	args = append(args, sqlAppendArgs...)
 	sqlAppend2 := ""
+	firstparty_count, supplier_count, adiffb_count, middleman_count, agency_count := 0, 0, 0, 0, 0
 	if dbPaging {
 		newArgs := []interface{}{in.PositionId}
 		newArgs = append(newArgs, sqlAppendArgs...)
 		count = CrmMysql.CountBySql(`select count(1) as count from crm.connection a where a.position_id=?`+sqlAppend1, newArgs...)
 		sqlAppend2 = ` limit ?,?`
 		args = append(args, start, end)
+		items := CrmMysql.SelectBySql(`SELECT itype,SUM(1) AS sum FROM crm.connection WHERE position_id=?`+sqlAppend1+` GROUP BY itype`, newArgs...)
+		if items != nil {
+			for _, v := range *items {
+				switch Int64All(v["itype"]) {
+				case 1:
+					firstparty_count = IntAll(v["sum"])
+				case 2:
+					supplier_count = IntAll(v["sum"])
+				case 3:
+					adiffb_count = IntAll(v["sum"])
+				case 4:
+					middleman_count = IntAll(v["sum"])
+				case 5:
+					agency_count = IntAll(v["sum"])
+				}
+			}
+		}
 	}
 	//
-	firstparty_count, supplier_count, adiffb_count, middleman_count, agency_count := 0, 0, 0, 0, 0
 	list := []*map[string]interface{}{}
 	isTjProject := true
 	probusfors := []string{}
@@ -526,6 +548,7 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 	}
 	if isTjProject {
 		entMonitor := NetworkCom.EntMonitor(in.UserId)
+		log.Println(entMonitor)
 		aio := n.AllIntroduceOwner(sqlAppend1, sqlAppend2, args, isTjProject, probusfors, entMonitor)
 		for _, v := range aio.Networks {
 			itype := ""
@@ -622,20 +645,19 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 			} else if in.Project_matchme == 1 && project_count == 0 {
 				continue
 			}
-			switch v.Itype {
-			case 1:
-				firstparty_count++
-			case 2:
-				supplier_count++
-			case 3:
-				adiffb_count++
-			case 4:
-				middleman_count++
-			case 5:
-				agency_count++
-			}
-			if in.Type != "" && v.Itype != n.TypeStrConvert(in.Type) {
-				continue
+			if !dbPaging {
+				switch v.Itype {
+				case 1:
+					firstparty_count++
+				case 2:
+					supplier_count++
+				case 3:
+					adiffb_count++
+				case 4:
+					middleman_count++
+				case 5:
+					agency_count++
+				}
 			}
 			export_url := ""
 			if len(export_id) > 0 {
@@ -968,7 +990,7 @@ func (n *network) Introduce_Middleman(values []string, entMonitor map[string]boo
 }
 
 //
-func (n *network) TypeStrConvert(itype string) int64 {
+func (n *network) TypeStrConvert(itype string) int {
 	//firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
 	switch itype {
 	case "firstparty":

+ 5 - 5
api/internal/service/network_test.go

@@ -106,13 +106,13 @@ func TestNetWorkList(t *testing.T) {
 	initDb()
 	//类型;firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
 	res := Network.List(&types.NetWorkListReq{
-		UserId:     "1205591997",
-		PositionId: 1205591997,
+		UserId: "1205591997",
+		//PositionId: 1205591997,
+		PositionId: 1205592003,
 		//PositionId:   935,
 		Current_page: 1,
 		Page_size:    10,
 		//PositionId: 935,
-		//PositionId: 1205591998,
 		//Order_amount: -1,
 		// Monitorcount_start: 1,
 		// Monitorcount_end:   1,
@@ -120,8 +120,8 @@ func TestNetWorkList(t *testing.T) {
 		//Project_matchme: 1,
 		//Starttime: "2024-04-23",
 		//Endtime:   "2024-04-23",
-		Type: "supplier",
-		Name: "四川",
+		//Type: "supplier",
+		//Name: "四川",
 	})
 	for k, v := range res.Data.(map[string]interface{}) {
 		if k == "list" {