Browse Source

数据重复处理

WH01243 1 năm trước cách đây
mục cha
commit
ef375bfe0b
2 tập tin đã thay đổi với 61 bổ sung72 xóa
  1. 60 71
      api/internal/service/owner.go
  2. 1 1
      api/internal/service/plistService.go

+ 60 - 71
api/internal/service/owner.go

@@ -205,14 +205,15 @@ func ConnectionsHandle(buyerArr []string, positionId int64, isAll bool) []map[st
 	}
 	a5 := time.Now().Unix()
 
-	returnData = Findwinner(buyerArr, returnData)
+	returnData = append(returnData, Findwinner(buyerArr)...)
 	a6 := time.Now().Unix()
 	logx.Info("供应商", a6-a5)
 	return returnData
 }
 
 // 供应商处理
-func Findwinner(buyerArr []string, returnData []map[string]interface{}) []map[string]interface{} {
+func Findwinner(buyerArr []string) []map[string]interface{} {
+	returnData := []map[string]interface{}{}
 	if len(buyerArr) == 0 {
 		return returnData
 	}
@@ -226,10 +227,10 @@ func Findwinner(buyerArr []string, returnData []map[string]interface{}) []map[st
 			buyer,
 			agency_id,
 			agency,
-			winner_id,
+			winnerId,
 			winner
 	from
-			transaction_info     
+			transaction_info      ARRAY JOIN  winner_id as  winnerId
 	where
 		buyer_id in (%s) order by  zbtime DESC,project_id DESC  `, strings.Join(buyerArr, ","))
 	winnerArr := SupplierFindConnectionsHandle(winnerSql)
@@ -265,7 +266,7 @@ func Findwinner(buyerArr []string, returnData []map[string]interface{}) []map[st
 		agencyIdMap := map[string]bool{}
 		for _, m := range winnerArr {
 			buyerId := m.Buyer_id
-			winner := m.Winner
+			winner := entNameMap[m.WinnerId]
 			buyer := m.Buyer
 			winnerId := m.WinnerId
 			agency := m.Agency
@@ -274,44 +275,47 @@ func Findwinner(buyerArr []string, returnData []map[string]interface{}) []map[st
 			projectName := m.Project_name
 			zbtime := m.Zbtime
 			key := fmt.Sprintf("%s_%s", buyerId, winnerId)
-			if winnerId != "" {
-				if _, ok := winnerMap[key]; ok {
-					data := winnerMap[key]
-					data["count"] = gconv.Int64(data["data"]) + 1
-					dataList := gconv.Maps(data["list"])
-					dataList = append(dataList, map[string]interface{}{
-						"zbtime":      zbtime,
-						"projectId":   projectId,
-						"projectName": projectName,
-					})
-					data["list"] = dataList
-					winnerMap[key] = data
-				} else {
-					winnerMap[key] = map[string]interface{}{
-						"b_id":       winnerId,
-						"b_name":     winner,
-						"a_name":     buyer,
-						"a_id":       buyerId,
-						"sourceType": "supplier",
-						"personName": gconv.String(personMap[winnerId]),
-						"count":      1,
-						"list": []map[string]interface{}{
-							{
-								"zbtime":      zbtime,
-								"entName":     winner,
-								"projectId":   projectId,
-								"projectName": projectName,
-							},
+			if winnerId == "" {
+				continue
+			}
+			if _, ok := winnerMap[key]; ok {
+				data := winnerMap[key]
+				data["count"] = gconv.Int64(data["count"]) + 1
+				dataList := gconv.Maps(data["list"])
+				dataList = append(dataList, map[string]interface{}{
+					"zbtime":      zbtime,
+					"projectId":   projectId,
+					"projectName": projectName,
+				})
+				data["list"] = dataList
+				data["zbtime"] = zbtime
+				winnerMap[key] = data
+			} else {
+				winnerMap[key] = map[string]interface{}{
+					"b_id":       winnerId,
+					"b_name":     winner,
+					"a_name":     buyer,
+					"a_id":       buyerId,
+					"sourceType": "supplier",
+					"zbtime":     zbtime,
+					"personName": gconv.String(personMap[winnerId]),
+					"count":      1,
+					"list": []map[string]interface{}{
+						{
+							"zbtime":      zbtime,
+							"entName":     winner,
+							"projectId":   projectId,
+							"projectName": projectName,
 						},
-					}
+					},
 				}
 			}
 			if agencyId != "" && buyerId != "" && projectId != "" {
-				key = fmt.Sprintf("%s_%s_%s", buyerId, agencyId, projectId)
-				key1 := fmt.Sprintf("%s_%s_%s", buyerId, agencyId, projectId)
+				key = fmt.Sprintf("%s_%s", buyerId, agencyId)
+				//key1 := fmt.Sprintf("%s_%s_%s", buyerId, agencyId, projectId)
 				if _, ok := agencyIdMap[key]; ok {
 					data := agencyMap[key]
-					data["count"] = gconv.Int64(data["data"]) + 1
+					data["count"] = gconv.Int64(data["count"]) + 1
 					dataList := gconv.Maps(data["list"])
 					dataList = append(dataList, map[string]interface{}{
 						"zbtime":      zbtime,
@@ -319,16 +323,18 @@ func Findwinner(buyerArr []string, returnData []map[string]interface{}) []map[st
 						"projectName": projectName,
 					})
 					data["list"] = dataList
+					data["zbtime"] = zbtime
 					agencyMap[key] = data
 				} else {
 					agencyIdMap[key] = true
-					agencyMap[key1] = map[string]interface{}{
+					agencyMap[key] = map[string]interface{}{
 						"b_id":       agencyId,
 						"b_name":     agency,
 						"a_name":     buyer,
 						"a_id":       buyerId,
 						"sourceType": "agency",
 						"count":      1,
+						"zbtime":     zbtime,
 						"personName": gconv.String(personMap[agencyId]),
 						"list": []map[string]interface{}{
 							{
@@ -367,6 +373,10 @@ func Findwinner(buyerArr []string, returnData []map[string]interface{}) []map[st
 			})
 		}
 	}
+	sort.Slice(returnData, func(i, j int) bool {
+		return gconv.Int64(returnData[i]["zbtime"]) > gconv.Int64(returnData[j]["zbtime"])
+	})
+
 	return returnData
 }
 
@@ -896,7 +906,7 @@ type SupplierConnectionsEntity struct {
 	Buyer        string   `ch:"buyer"`
 	Agency_id    string   `ch:"agency_id"`
 	Agency       string   `ch:"agency"`
-	WinnerId     []string `ch:"winner_id"`
+	WinnerId     string   `ch:"winnerId"`
 	Winner       []string `ch:"winner"`
 }
 type SupplierConnectionsEntitys struct {
@@ -958,38 +968,17 @@ func SupplierFindConnectionsHandle(sqlStr string) []SupplierConnectionsEntitys {
 		if err != nil {
 			logx.Error(err)
 		}
-		if len(data.Winner) == 0 {
-			returnData = append(returnData, SupplierConnectionsEntitys{
-				Zbtime:       data.Zbtime,
-				Project_id:   data.Project_id,
-				Project_name: data.Project_name,
-				Buyer_id:     data.Buyer_id,
-				Buyer:        data.Buyer,
-				Agency_id:    data.Agency_id,
-				Agency:       data.Agency,
-				WinnerId:     "",
-				Winner:       "",
-			})
-		} else {
-
-			for k, v := range data.WinnerId {
-				fmt.Println(k, len(data.Winner))
-				if k+1 > len(data.Winner) {
-					continue
-				}
-				returnData = append(returnData, SupplierConnectionsEntitys{
-					Zbtime:       data.Zbtime,
-					Project_id:   data.Project_id,
-					Project_name: data.Project_name,
-					Buyer_id:     data.Buyer_id,
-					Buyer:        data.Buyer,
-					Agency_id:    data.Agency_id,
-					Agency:       data.Agency,
-					WinnerId:     gconv.String(v),
-					Winner:       gconv.String(data.Winner[k]),
-				})
-			}
-		}
+		returnData = append(returnData, SupplierConnectionsEntitys{
+			Zbtime:       data.Zbtime,
+			Project_id:   data.Project_id,
+			Project_name: data.Project_name,
+			Buyer_id:     data.Buyer_id,
+			Buyer:        data.Buyer,
+			Agency_id:    data.Agency_id,
+			Agency:       data.Agency,
+			WinnerId:     data.WinnerId,
+			Winner:       "",
+		})
 	}
 	return returnData
 }

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

@@ -360,7 +360,7 @@ func moreInfo(req *types.ProjectListReq, list []*ProjectEntry) (result []*Projec
 			}
 		}
 	} else {
-		companyList = Findwinner(bArr, nil)
+		companyList = Findwinner(bArr)
 		if companyList != nil && len(companyList) > 0 {
 			for _, m := range list {
 				if m.MyConn == false {