瀏覽代碼

采购单位类型处理

WH01243 1 年之前
父節點
當前提交
45a32db866
共有 1 個文件被更改,包括 18 次插入7 次删除
  1. 18 7
      api/internal/service/owner.go

+ 18 - 7
api/internal/service/owner.go

@@ -57,6 +57,7 @@ type BuyerProject struct {
 	IsIgnore         bool
 	Area             string
 	Zbtime           int64
+	BuyerType        string
 }
 type ProjectEntity struct {
 	Number          int64
@@ -551,6 +552,7 @@ func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, s
 			returnData = append(returnData, BuyerProject{
 				BuyerId:   buyerId,
 				BuyerName: buyerName,
+				BuyerType: gconv.String(buyerMap["buyerType"]),
 				Project: ProjectEntity{
 					Number:          count,
 					EstimatedAmount: money,
@@ -571,6 +573,7 @@ func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, s
 			returnData = append(returnData, BuyerProject{
 				BuyerId:   buyerId,
 				BuyerName: buyerName,
+				BuyerType: gconv.String(buyerMap["buyerType"]),
 				Project: ProjectEntity{
 					Number:          0,
 					EstimatedAmount: 0,
@@ -706,7 +709,7 @@ func BuyerList(partyA, supplier, heterotophy, intermediary, agency string, posit
 		}
 		if len(partyA) > 0 {
 			partyASql := fmt.Sprintf(`select  id as buyer_id,company_name as buyer  from  ent_info   where  id in (%s)`, strings.Join(intermediaryArr, ","))
-			FindHandle(partyASql, dataMap)
+			FindHandle(partyASql, dataMap, "firstparty")
 		}
 	}
 	//供应商 //同甲异业
@@ -718,17 +721,22 @@ func BuyerList(partyA, supplier, heterotophy, intermediary, agency string, posit
 			}
 		}
 	}
+	if len(findInSetArr) > 0 {
+		sqlStr := fmt.Sprintf(`SELECT buyer_id,buyer FROM transaction_info where  hasAny(winner_id,[%s])    `, strings.Join(findInSetArr, ","))
+		FindHandle(sqlStr, dataMap, "supplier")
+	}
 	//同甲异业
+	findheterotophyArr := []string{}
 	if heterotophy != "" {
 		for _, v := range strings.Split(heterotophy, ",") {
 			if v != "" {
-				findInSetArr = append(findInSetArr, fmt.Sprintf("'%s'", v))
+				findheterotophyArr = append(findheterotophyArr, fmt.Sprintf("'%s'", v))
 			}
 		}
 	}
-	if len(findInSetArr) > 0 {
-		sqlStr := fmt.Sprintf(`SELECT buyer_id,buyer FROM transaction_info where  hasAny(winner_id,[%s])    `, strings.Join(findInSetArr, ","))
-		FindHandle(sqlStr, dataMap)
+	if len(findheterotophyArr) > 0 {
+		sqlStr := fmt.Sprintf(`SELECT buyer_id,buyer FROM transaction_info where  hasAny(winner_id,[%s])    `, strings.Join(findheterotophyArr, ","))
+		FindHandle(sqlStr, dataMap, "adiffb")
 	}
 	//中间人
 	if intermediary != "" {
@@ -741,6 +749,7 @@ func BuyerList(partyA, supplier, heterotophy, intermediary, agency string, posit
 				buyerName := gconv.String(m["relate_name"])
 				(*dataMap)[buyerId] = map[string]interface{}{
 					"buyerName": buyerName,
+					"buyerType": "middleman",
 				}
 			}
 		}
@@ -752,7 +761,7 @@ func BuyerList(partyA, supplier, heterotophy, intermediary, agency string, posit
 			agencyArr = append(agencyArr, fmt.Sprintf("'%s'", s))
 		}
 		sqlStr := fmt.Sprintf(`SELECT  buyer_id,buyer FROM transaction_info  where agency_id in (%s) `, strings.Join(agencyArr, ","))
-		FindHandle(sqlStr, dataMap)
+		FindHandle(sqlStr, dataMap, "agency")
 	}
 	return dataMap
 }
@@ -823,6 +832,7 @@ func ProjectHandle(buyerArr []string, entAccountId int64, entName, area, project
 			}
 			(*returnMap)[buyerId] = map[string]interface{}{
 				"buyerName": buyerName,
+				"buyerType": "firstparty",
 			}
 
 		}
@@ -874,7 +884,7 @@ type BuyerAggStruct struct {
 }
 
 // 采购单位查询sql
-func FindHandle(sqlStr string, dataMap *map[string]map[string]interface{}) {
+func FindHandle(sqlStr string, dataMap *map[string]map[string]interface{}, buyerType string) {
 	rows, err := ClickhouseConn.Query(context.Background(), sqlStr)
 	if err != nil {
 		logx.Error("查询失败", sqlStr, err)
@@ -885,6 +895,7 @@ func FindHandle(sqlStr string, dataMap *map[string]map[string]interface{}) {
 		if data.BuyerId != "" {
 			(*dataMap)[data.BuyerId] = map[string]interface{}{
 				"buyerName": data.Buyer,
+				"buyerType": buyerType,
 			}
 		}
 	}