wangchuanjin před 9 měsíci
rodič
revize
c525c31f6a

+ 1 - 0
api/etc/networkmanage.yaml

@@ -7,6 +7,7 @@ Gateway:
   Etcd:
     - 127.0.0.1:2379
 CacheTimeOut: 600
+BuyerBatch: 500
 EntNameList: ["思特威(上海)电子科技股份有限公司","浙江宇视科技有限公司","广州敏视数码科技有限公司","安徽创世科技股份有限公司","深圳市同为数码科技股份有限公司",
               "上海为旌科技有限公司","天地伟业技术有限公司","华为技术有限公司","安徽清新互联信息科技有限公司","杭州数尔安防科技股份有限公司","天津中安视通科技有限公司",
               "深圳市高斯贝尔家居智能电子有限公司","广州派宝智能安防科技有限公司","厦门力鼎光电股份有限公司","深圳市江波龙电子股份有限公司","南京恩博科技有限公司",

+ 1 - 0
api/internal/config/config.go

@@ -12,6 +12,7 @@ type Config struct {
 		Etcd       []string
 	}
 	CacheTimeOut int
+	BuyerBatch   int
 	EntNameList  []string
 }
 

+ 32 - 8
api/internal/service/network.go

@@ -1244,11 +1244,29 @@ func (n *network) GetQyxyId(ids []string) map[string]string {
 	}
 	return m
 }
-
 func (n *network) BuyerProjectInfo(ids []string, businessType []string) map[string]*projectInfo {
 	vm := map[string]*projectInfo{}
+	m := map[string]bool{}
+	newIds := []string{}
+	for _, v := range ids {
+		if m[v] {
+			continue
+		}
+		m[v] = true
+		newIds = append(newIds, v)
+		if len(newIds) == C.BuyerBatch {
+			n.BuyerProjectInfoBatch(newIds, businessType, vm)
+			newIds = []string{}
+		}
+	}
+	if len(newIds) > 0 {
+		n.BuyerProjectInfoBatch(newIds, businessType, vm)
+	}
+	return vm
+}
+func (n *network) BuyerProjectInfoBatch(ids []string, businessType []string, vm map[string]*projectInfo) {
 	if len(ids) == 0 {
-		return vm
+		return
 	}
 	wh, args := WhArgs(ids)
 	q := `select buyer_id,count(DISTINCT project_id) AS project_count,sum(project_money) AS project_amount,groupUniqArray(project_id) from information.transaction_info_all where buyer_id in (` + wh + `) and project_bidstatus>1`
@@ -1261,7 +1279,7 @@ func (n *network) BuyerProjectInfo(ids []string, businessType []string) map[stri
 	rows, err := ClickhouseConn.Query(context.Background(), q, args...)
 	if err != nil {
 		logx.Error(err)
-		return nil
+		return
 	}
 	for rows.Next() {
 		var (
@@ -1275,17 +1293,23 @@ func (n *network) BuyerProjectInfo(ids []string, businessType []string) map[stri
 			continue
 		}
 		pf, _ := project_amount.Float64()
-		vm[buyer_id] = &projectInfo{
-			ProjectCount:  int64(project_count),
-			ExportId:      project_id,
-			ProjectAmount: pf,
+		if vm[buyer_id] == nil {
+			vm[buyer_id] = &projectInfo{
+				ProjectCount:  int64(project_count),
+				ExportId:      project_id,
+				ProjectAmount: pf,
+			}
+		} else {
+			vm[buyer_id].ProjectAmount += pf
+			vm[buyer_id].ProjectCount += int64(project_count)
+			vm[buyer_id].ExportId = append(vm[buyer_id].ExportId, project_id...)
 		}
 	}
 	rows.Close()
 	if err := rows.Err(); err != nil {
 		logx.Error(err)
 	}
-	return vm
+	return
 }
 
 func (n *network) MakeProjectInfo(buyers []string, vbs map[string][]*idName, businessType []string) map[string]*projectInfo {