Browse Source

feat:xiugai

wangchuanjin 9 months ago
parent
commit
ac3caadff5
2 changed files with 105 additions and 38 deletions
  1. 104 37
      api/internal/service/network.go
  2. 1 1
      api/internal/service/plistService.go

+ 104 - 37
api/internal/service/network.go

@@ -1048,7 +1048,6 @@ func (n *network) Introduce_Supplier(values []string, businessType []string) map
 		return map[string]*projectInfo{}
 	}
 	wh, args := WhArgs(values)
-	vbs := map[string][]*idName{}
 	repeat := map[string]bool{}
 	whRepeat := map[string]map[string]bool{}
 	buyers := []string{}
@@ -1056,44 +1055,51 @@ func (n *network) Introduce_Supplier(values []string, businessType []string) map
 	rows, err := ClickhouseConn.Query(context.Background(), q, args...)
 	if err != nil {
 		logx.Error(err)
-	} else {
-		for rows.Next() {
-			var (
-				winner_id []string
-				buyer_id  string
-				buyer     string
-			)
-			if err := rows.Scan(&winner_id, &buyer_id, &buyer); err != nil {
-				logx.Error(err)
-				continue
+		return map[string]*projectInfo{}
+	}
+	vbs := map[string][]*idName{}
+	vm := map[string]bool{}
+	ids := []string{}
+	for rows.Next() {
+		var (
+			winner_id []string
+			buyer_id  string
+			buyer     string
+		)
+		if err := rows.Scan(&winner_id, &buyer_id, &buyer); err != nil {
+			logx.Error(err)
+			continue
+		}
+		if buyer_id == "" || buyer == "" {
+			continue
+		}
+		if !repeat[buyer_id] {
+			repeat[buyer_id] = true
+			buyers = append(buyers, buyer_id)
+		}
+		for _, v := range winner_id {
+			if !vm[v] {
+				ids = append(ids, v)
 			}
-			if buyer_id == "" || buyer == "" {
+			vm[v] = true
+			if whRepeat[v] != nil && whRepeat[v][buyer_id] {
 				continue
 			}
-			if !repeat[buyer_id] {
-				repeat[buyer_id] = true
-				buyers = append(buyers, buyer_id)
-			}
-			for _, v := range winner_id {
-				if whRepeat[v] != nil && whRepeat[v][buyer_id] {
-					continue
-				}
-				if whRepeat[v] == nil {
-					whRepeat[v] = map[string]bool{}
-				}
-				whRepeat[v][buyer_id] = true
-				vbs[v] = append(vbs[v], &idName{
-					Id:   buyer_id,
-					Name: buyer,
-				})
+			if whRepeat[v] == nil {
+				whRepeat[v] = map[string]bool{}
 			}
+			whRepeat[v][buyer_id] = true
+			vbs[v] = append(vbs[v], &idName{
+				Id:   buyer_id,
+				Name: buyer,
+			})
 		}
-		rows.Close()
-		if err := rows.Err(); err != nil {
-			logx.Error(err)
-		}
 	}
-	return n.MakeProjectInfo(buyers, vbs, businessType)
+	rows.Close()
+	if err := rows.Err(); err != nil {
+		logx.Error(err)
+	}
+	return n.MakeProjectInfo(nil, ids, vbs, businessType)
 }
 
 func (n *network) Introduce_Agency(values []string, businessType []string) map[string]*projectInfo {
@@ -1105,9 +1111,10 @@ func (n *network) Introduce_Agency(values []string, businessType []string) map[s
 	rows, err := ClickhouseConn.Query(context.Background(), q, args...)
 	if err != nil {
 		logx.Error(err)
-		return nil
+		return map[string]*projectInfo{}
 	}
 	vbs := map[string][]*idName{}
+	ids := []string{}
 	buyers := []string{}
 	repeat := map[string]bool{}
 	for rows.Next() {
@@ -1123,6 +1130,7 @@ func (n *network) Introduce_Agency(values []string, businessType []string) map[s
 		if buyer_id == "" || buyer == "" {
 			continue
 		}
+		ids = append(ids, agency_id)
 		vbs[agency_id] = append(vbs[agency_id], &idName{
 			Id:   buyer_id,
 			Name: buyer,
@@ -1136,7 +1144,7 @@ func (n *network) Introduce_Agency(values []string, businessType []string) map[s
 	if err := rows.Err(); err != nil {
 		logx.Error(err)
 	}
-	return n.MakeProjectInfo(buyers, vbs, businessType)
+	return n.MakeProjectInfo(ids, nil, vbs, businessType)
 }
 
 func (n *network) Introduce_Middleman_Buyer(values []string, businessType []string) map[string]*projectInfo {
@@ -1312,8 +1320,67 @@ func (n *network) BuyerProjectInfoBatch(ids []string, businessType []string, vm
 	return
 }
 
-func (n *network) MakeProjectInfo(buyers []string, vbs map[string][]*idName, businessType []string) map[string]*projectInfo {
-	pis := n.BuyerProjectInfo(buyers, businessType)
+func (n *network) TjProject(agencyIds, winnerIds []string, vbs map[string][]*idName, businessType []string) map[string]*projectInfo {
+	vm := map[string]*projectInfo{}
+	if len(agencyIds) == 0 && len(winnerIds) == 0 {
+		return vm
+	}
+	allArgs := []interface{}{}
+	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 (select DISTINCT buyer_id from information.transaction_info_all where `
+	if len(agencyIds) > 0 {
+		wh, args := WhArgs(agencyIds)
+		allArgs = append(allArgs, args...)
+		q += `agency_id in (` + wh + `) and buyer_id<>''`
+	} else if len(winnerIds) > 0 {
+		wh, args := WhArgs(winnerIds)
+		allArgs = append(allArgs, args...)
+		q += `hasAny(winner_id,[` + wh + `]) and buyer_id<>''`
+	}
+	q += `) and project_bidstatus>1`
+	if len(businessType) > 0 {
+		newWh, newArgs := WhArgs(businessType)
+		q += ` and hasAny(topscopeclass,[` + newWh + `])`
+		allArgs = append(allArgs, newArgs...)
+	}
+	q += ` group by buyer_id`
+	rows, err := ClickhouseConn.Query(context.Background(), q, allArgs...)
+	if err != nil {
+		logx.Error(err)
+		return vm
+	}
+	for rows.Next() {
+		var (
+			buyer_id       string
+			project_count  uint64
+			project_amount decimal.Decimal
+			project_id     []string
+		)
+		if err := rows.Scan(&buyer_id, &project_count, &project_amount, &project_id); err != nil {
+			logx.Error(err)
+			continue
+		}
+		pf, _ := project_amount.Float64()
+		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
+}
+
+func (n *network) MakeProjectInfo(agencyIds, winnerIds []string, vbs map[string][]*idName, businessType []string) map[string]*projectInfo {
+	pis := n.TjProject(agencyIds, winnerIds, vbs, businessType)
 	vm := map[string]*projectInfo{}
 	for k, v := range vbs {
 		pi := &projectInfo{

+ 1 - 1
api/internal/service/plistService.go

@@ -201,7 +201,7 @@ func getQuerySql(req *types.ProjectListReq, plist []string, businessStr string)
 		allArgs = append(allArgs, args...)
 	}
 	if len(ors2) > 0 {
-		ors1 = append(ors1, `(buyer_id in (select buyer_id from transaction_info_all where (`+strings.Join(ors2, " or ")+`) and buyer_id<>''))`)
+		ors1 = append(ors1, `(buyer_id in (select DISTINCT buyer_id from transaction_info_all where (`+strings.Join(ors2, " or ")+`) and buyer_id<>''))`)
 	}
 	ands := []string{}
 	//业务类型