ソースを参照

Merge commit '7f5761a6ce55b4f9a4de4bb5242ab52eccee753f' into hotfix/v1.0.4.2

* commit '7f5761a6ce55b4f9a4de4bb5242ab52eccee753f':
  企业业主显示不正确处理
  feat:xiugai
  条数显示不对处理
  条数显示不对处理
  日志添加
  feat:xiugai
  情报id返回
  中间人自增id返回
  中间人自增id返回
  排序处理
Jianghan 1 年間 前
コミット
b65ac9523c

+ 43 - 0
api/common/network.go

@@ -14,6 +14,49 @@ var NetworkCom = &networkCom{}
 
 type networkCom struct{}
 
+//
+func (n *networkCom) GetEntIdByName(names []string) map[string]string {
+	result := map[string]string{}
+	if len(names) == 0 {
+		return result
+	}
+	var query = func(values []string) {
+		wh, args := n.WhArgs(values)
+		rows, err := ClickhouseConn.Query(context.Background(), `select id,company_name from information.ent_info where company_name in (`+wh+`)`, args...)
+		if err != nil {
+			logx.Error(err)
+			return
+		}
+		for rows.Next() {
+			var (
+				id           string
+				company_name string
+			)
+			if err := rows.Scan(&id, &company_name); err != nil {
+				logx.Error(err)
+				continue
+			}
+			result[company_name] = id
+		}
+		rows.Close()
+		if err := rows.Err(); err != nil {
+			logx.Error(err)
+		}
+	}
+	values := []string{}
+	for _, v := range names {
+		values = append(values, v)
+		if len(values) == 200 {
+			query(values)
+			values = []string{}
+		}
+	}
+	if len(values) > 0 {
+		query(values)
+	}
+	return result
+}
+
 //根据标签类型获取标签占位
 func (n *networkCom) GetEntTagSeat(labelType int) []string {
 	rows, err := ClickhouseConn.Query(context.Background(), `select bitmap_num from information.ent_label where label_type=?`, labelType)

+ 52 - 22
api/internal/service/CoopHistoryService.go

@@ -23,8 +23,8 @@ var (
 	sql_2_1_1 = `SELECT project_id, project_name, zbtime FROM information.transaction_info WHERE buyer_id = ? AND agency = ? ORDER BY zbtime DESC`
 	sql_2_2   = `select DISTINCT  b.company_id,b.company_name,a.relate_id,a.relate_name,b.contact_person   from  connection_introduce a  INNER JOIN connection b on  a.position_id= ? and a.connection_id=b.id  and   a.relate_Id = ? and  a.itype =1  and  b.itype=4 and  b.status=1 `
 	sql_2_3   = `select a.a_id as a_id, a.b_id as b_id, a.a_name as a_name, a.b_name as b_name, a.code as code, c.legal_person as c_person, d.legal_person d_person from crm.ent_map_code a left join ent_info c on (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201') and a.a_id = c.id left join ent_info d on (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201') and a.b_id = d.id where (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201')`
-	es_query  = `{"query": {"bool": {"must": [{"term": {"buyer_id": "%s"}},{"exists": {"field": "winner_id"}}],"must_not": {"terms": {"property_form": ["%s"]}}}},"aggs": {"winner_count": {"terms": {"field": "winner","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "winner_id"}}}}},"size": 1}`
-	es_query1 = `{"query": {"bool": {"must": [{"term": {"buyer_id": "%s"}}],"must_not": [{"term": {"agency_id": {"value": ""}}}]}},"aggs": {"agency_count": {"terms": {"field": "agency","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "agency_id"}}}}},"size": 1}`
+	es_query  = `{"query": {"bool": {"must": [{"terms": {"buyer_id": ["%s"]}},{"exists": {"field": "winner_id"}}],"must_not": {"terms": {"property_form": ["%s"]}}}},"aggs": {"winner_count": {"terms": {"field": "winner","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "winner_id"}},"buyer_id": {"terms": {"field": "buyer_id"}}}}},"size": 1}`
+	es_query1 = `{"query": {"bool": {"must": [{"terms": {"buyer_id": ["%s"]}}],"must_not": [{"term": {"agency_id": {"value": ""}}}]}},"aggs": {"agency_count": {"terms": {"field": "agency","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "agency_id"}},"buyer_id": {"terms": {"field": "buyer_id"}}}}},"size": 1}`
 )
 
 type ResultData struct {
@@ -102,7 +102,9 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 				}
 			}
 		}
-		r1, r2 := GetData(propertyForm, pTmp.BuyerId)
+		rs1, rs2 := GetData(propertyForm, pTmp.BuyerId)
+		r1 := rs1[pTmp.BuyerId]
+		r2 := rs2[pTmp.BuyerId]
 		if r1 != nil && len(r1) > 0 {
 			size_1 = int64(len(r1))
 			if req.ChannelType == "0" || req.ChannelType == "1" {
@@ -143,7 +145,8 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 	return
 }
 
-func GetData(propertyForm []string, bid string) (result1, result2 []map[string]interface{}) {
+func GetData(propertyForm []string, bid string) (result1, result2 map[string][]map[string]interface{}) {
+	result1, result2 = map[string][]map[string]interface{}{}, map[string][]map[string]interface{}{}
 	type AggStruct struct {
 		Buckets []struct {
 			Key        string `json:"key,omitempty"`
@@ -157,14 +160,21 @@ func GetData(propertyForm []string, bid string) (result1, result2 []map[string]i
 					Doc_count int64  `json:"doc_count,omitempty"`
 				} `json:"buckets"`
 			} `json:"ent_id"`
+			BuyerId struct {
+				Buckets []struct {
+					Key       string `json:"key,omitempty"`
+					Doc_count int64  `json:"doc_count,omitempty"`
+				} `json:"buckets"`
+			} `json:"buyer_id"`
 		} `json:"buckets"`
 	}
 	m1 := make(map[string]interface{}) //采购单位-中标单位
 	m2 := make(map[string]interface{}) //采购单位-代理机构
+	noIds := []string{}
 	if len(propertyForm) > 0 {
 		//同甲异态 中标企业
-		aggs, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, bid, strings.Join(propertyForm, "\",\"")))
-		logx.Info("es聚合查询结果:", fmt.Sprintf(es_query, bid, strings.Join(propertyForm, "\",\"")))
+		aggs, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(propertyForm, "\",\"")))
+		logx.Info("es聚合查询结果:", fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(propertyForm, "\",\"")))
 		var m1Buckets = AggStruct{}
 		if aggs != nil && aggs["winner_count"] != nil {
 			bs, err := aggs["winner_count"].MarshalJSON()
@@ -178,26 +188,23 @@ func GetData(propertyForm []string, bid string) (result1, result2 []map[string]i
 					logx.Info(err)
 					if len(m1Buckets.Buckets) > 0 {
 						for _, v := range m1Buckets.Buckets {
-							if v.Key != "" {
-								m1[v.Key] = map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count, "nameId": v.EntId.Buckets[0].Key}
+							if v.Key != "" && len(v.EntId.Buckets) > 0 && len(v.BuyerId.Buckets) > 0 {
+								mv := map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count, "buyerId": v.BuyerId.Buckets[0].Key}
+								if len(v.EntId.Buckets) == 1 && v.EntId.Buckets[0].Key != "" {
+									mv["nameId"] = v.EntId.Buckets[0].Key
+								} else {
+									noIds = append(noIds, v.Key)
+								}
+								m1[v.Key] = mv
 							}
 						}
 					}
 				}
 			}
 		}
-		for k, v := range m1 {
-			v1 := v.(map[string]interface{})
-			tmp := make(map[string]interface{})
-			tmp["name"] = k
-			tmp["nameId"] = v1["nameId"]
-			tmp["coop_size"] = v1["count"]
-			tmp["coop_amount"] = v1["amount"]
-			result1 = append(result1, tmp)
-		}
 	}
 	//代理机构
-	aggs1, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query1, bid))
+	aggs1, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query1, strings.ReplaceAll(bid, ",", `","`)))
 	var m2Buckets = AggStruct{}
 	if aggs1 != nil && aggs1["agency_count"] != nil {
 		bs, err := aggs1["agency_count"].MarshalJSON()
@@ -211,22 +218,45 @@ func GetData(propertyForm []string, bid string) (result1, result2 []map[string]i
 				logx.Info(err)
 				if len(m2Buckets.Buckets) > 0 {
 					for _, v := range m2Buckets.Buckets {
-						if v.Key != "" {
-							m2[v.Key] = map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count, "nameId": v.EntId.Buckets[0].Key}
+						if v.Key != "" && len(v.EntId.Buckets) > 0 && len(v.BuyerId.Buckets) > 0 {
+							if v.EntId.Buckets[0].Key == "" {
+								noIds = append(noIds, v.Key)
+							}
+							m2[v.Key] = map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count, "nameId": v.EntId.Buckets[0].Key, "buyerId": v.BuyerId.Buckets[0].Key}
 						}
 					}
 				}
 			}
 		}
 	}
+	idName := T.NetworkCom.GetEntIdByName(noIds)
+	for k, v := range m1 {
+		v1 := v.(map[string]interface{})
+		tmp := make(map[string]interface{})
+		tmp["name"] = k
+		nameId, _ := v1["nameId"].(string)
+		if nameId == "" {
+			nameId = idName[k]
+		}
+		tmp["nameId"] = nameId
+		tmp["coop_size"] = v1["count"]
+		tmp["coop_amount"] = v1["amount"]
+		buyerId, _ := v1["buyerId"].(string)
+		result1[buyerId] = append(result1[buyerId], tmp)
+	}
 	for k, v := range m2 {
 		v1 := v.(map[string]interface{})
 		tmp := make(map[string]interface{})
 		tmp["name"] = k
-		tmp["nameId"] = v1["nameId"]
+		nameId, _ := v1["nameId"].(string)
+		if nameId == "" {
+			nameId = idName[k]
+		}
+		tmp["nameId"] = nameId
 		tmp["coop_size"] = v1["count"]
 		tmp["coop_amount"] = v1["amount"]
-		result2 = append(result2, tmp)
+		buyerId, _ := v1["buyerId"].(string)
+		result2[buyerId] = append(result2[buyerId], tmp)
 	}
 	return
 }

+ 8 - 6
api/internal/service/employService.go

@@ -798,19 +798,19 @@ func employInfoEnt(table, employKey, findKey, depIDArr string, in *types.InfoEmp
 		orderKey = "source"
 	}
 	if len(infoId1Arr) > 0 {
-		infoData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  %s,GROUP_CONCAT(id) as  employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status from  %s   where %s in ('%s') and  source=? and    ent_dept_id in  (%s) GROUP BY %s ,%s order  by %s", employKey, table, employKey, strings.Join(infoId1Arr, "','"), depIDArr, employKey, orderKey, orderKey), 1)
+		infoData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  %s,GROUP_CONCAT(id) as  employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status,%s from  %s   where %s in ('%s') and  source=? and    ent_dept_id in  (%s) GROUP BY %s ,%s order  by %s", employKey, orderKey, table, employKey, strings.Join(infoId1Arr, "','"), depIDArr, employKey, orderKey, orderKey), 1)
 	}
 	if len(infoId2Arr) > 0 {
-		infoData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, GROUP_CONCAT(id) as  employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status from  %s   where %s in ('%s') and  source=? and    ent_dept_id in  (%s)  GROUP BY %s ,%s order  by %s", employKey, table, employKey, strings.Join(infoId2Arr, "','"), depIDArr, employKey, orderKey, orderKey), 2)
+		infoData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, GROUP_CONCAT(id) as  employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status,%s from  %s   where %s in ('%s') and  source=? and    ent_dept_id in  (%s)  GROUP BY %s ,%s order  by %s", employKey, orderKey, table, employKey, strings.Join(infoId2Arr, "','"), depIDArr, employKey, orderKey, orderKey), 2)
 	}
 	if len(niJianIdArr) > 0 {
-		niJianData = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, GROUP_CONCAT(id) as  employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status from  %s   where %s  in ('%s') and  source=? and    ent_dept_id in  (%s) GROUP BY %s ,%s order  by %s", employKey, table, employKey, strings.Join(niJianIdArr, "','"), depIDArr, employKey, orderKey, orderKey), 2)
+		niJianData = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, GROUP_CONCAT(id) as  employIdArr,MAX(is_ignore) as is_ignore,MAX(status) as status,%s from  %s   where %s  in ('%s') and  source=? and    ent_dept_id in  (%s) GROUP BY %s ,%s order  by %s", employKey, orderKey, table, employKey, strings.Join(niJianIdArr, "','"), depIDArr, employKey, orderKey, orderKey), 2)
 	}
 	if len(wuye1Arr) > 0 {
-		wuyeData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s,  id,is_ignore,status   from  %s   where %s in ('%s')  and status =1 and  source=? and    ent_dept_id in  (%s)  GROUP BY %s  ,%s order  by %s", employKey, table, employKey, strings.Join(wuye1Arr, "','"), depIDArr, employKey, orderKey, orderKey), 1)
+		wuyeData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s,  id,is_ignore,status,%s   from  %s   where %s in ('%s')  and status =1 and  source=? and    ent_dept_id in  (%s)  GROUP BY %s  ,%s order  by %s", employKey, orderKey, table, employKey, strings.Join(wuye1Arr, "','"), depIDArr, employKey, orderKey, orderKey), 1)
 	}
 	if len(wuye2Arr) > 0 {
-		wuyeData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, id,is_ignore,status   from  %s   where %s  in ('%s')  and status =1 and  source=? and    ent_dept_id in  (%s) GROUP BY %s ,%s order  by %s", employKey, table, employKey, strings.Join(wuye2Arr, "','"), depIDArr, employKey, orderKey, orderKey), 2)
+		wuyeData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s, id,is_ignore,status,%s   from  %s   where %s  in ('%s')  and status =1 and  source=? and    ent_dept_id in  (%s) GROUP BY %s ,%s order  by %s", employKey, orderKey, table, employKey, strings.Join(wuye2Arr, "','"), depIDArr, employKey, orderKey, orderKey), 2)
 	}
 	for _, v := range *infoData1 {
 		valueMap := map[string]interface{}{
@@ -937,7 +937,6 @@ func EmployHandle(valueMap map[string]interface{}, employData map[string]interfa
 			if employStatus == 1 {
 				employ2 = true
 			}
-			valueMap["intelligenceId"] = employId
 		case 3:
 			if valueMap["employ2"] != nil {
 				employ2 = gconv.Bool(valueMap["employ2"])
@@ -967,6 +966,9 @@ func EmployHandle(valueMap map[string]interface{}, employData map[string]interfa
 		valueMap["type"] = common.Int64All(employData["type"])
 		valueMap["employId"] = employId
 	}
+	if employType == 2 {
+		valueMap["intelligenceId"] = employId
+	}
 	if single && employArrStr != "" {
 		//列表查询
 		//是否忽略处理

+ 98 - 29
api/internal/service/network.go

@@ -4,7 +4,6 @@ import (
 	"context"
 	"database/sql"
 	"fmt"
-	"log"
 	"math"
 	"sort"
 	"strings"
@@ -103,6 +102,23 @@ type myNetwork struct {
 	Create_time       string
 }
 
+type nodeTree struct {
+	NAME      string
+	ID        string
+	SZ_PID0   string
+	SZ_PID1   string
+	SZ_PID2   string
+	SZ_PID3   string
+	CODE      string
+	PCODE     string
+	DATACOUNT int64
+	SZ_LEVEL  int
+	SZ_LEAF   int
+	TYPE      string
+	MYID      string
+	MYTYPE    string
+}
+
 //人脉库-添加/修改人脉
 func (n *network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
 	reply := &types.Reply{Data: map[string]interface{}{
@@ -392,19 +408,19 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 			list[v.Itype-1].Children = append(list[v.Itype-1].Children, ntc)
 		}
 	}
-	convList := []map[string]interface{}{}
+	convList := []*nodeTree{}
 	for _, v := range list {
-		pm := map[string]interface{}{
-			"CODE":      v.Name,
-			"NAME":      v.Name,
-			"SZ_PID0":   v.Name,
-			"SZ_LEVEL":  0,
-			"DATACOUNT": 0,
+		pm := &nodeTree{
+			CODE:      v.Name,
+			NAME:      v.Name,
+			SZ_PID0:   v.Name,
+			SZ_LEVEL:  0,
+			DATACOUNT: 0,
 		}
 		if len(v.Children) > 0 {
-			pm["SZ_LEAF"] = 0
+			pm.SZ_LEAF = 0
 		} else {
-			pm["SZ_LEAF"] = 1
+			pm.SZ_LEAF = 1
 		}
 		sort.Sort(v)
 		id, pType, pMyType, pMyId := "", "", "", ""
@@ -423,7 +439,34 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 			pMyType += vv.Type
 			myChildIds, myChildTypes := "", ""
 			if in.Id == "" && v.Name == "甲方" {
+				cccNodes := []*nodeTree{}
+				cccIndexMap := map[string]int{}
 				for _, vvv := range firstpartyChild[vv.CompanyId] {
+					cccIndex, cccOk := cccIndexMap[vvv.Name]
+					if cccOk {
+						cccNodes[cccIndex].ID += "," + vvv.CompanyId
+						cccNodes[cccIndex].MYID += "," + vvv.CompanyId
+						cccNodes[cccIndex].SZ_PID2 += "," + vvv.CompanyId
+						cccNodes[cccIndex].CODE += "," + vvv.CompanyId
+						cccNodes[cccIndex].TYPE += ",firstparty"
+						cccNodes[cccIndex].MYTYPE += ",firstparty"
+					} else {
+						cccNodes = append(cccNodes, &nodeTree{
+							NAME:     vvv.Name,
+							ID:       vvv.CompanyId,
+							SZ_PID0:  v.Name,
+							SZ_PID1:  v.Name + ":" + myId,
+							SZ_PID2:  v.Name + ":" + myId + ":" + vvv.Name + ":" + vvv.CompanyId,
+							CODE:     v.Name + ":" + myId + ":" + vvv.Name + ":" + vvv.CompanyId,
+							PCODE:    v.Name + ":" + myId,
+							SZ_LEVEL: 1,
+							SZ_LEAF:  1,
+							TYPE:     "firstparty",
+							MYID:     vvv.CompanyId,
+							MYTYPE:   "firstparty",
+						})
+						cccIndexMap[vvv.Name] = len(cccNodes) - 1
+					}
 					if id != "" {
 						id += ","
 					}
@@ -440,6 +483,24 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 						myChildTypes += ","
 					}
 					myChildTypes += vv.Type
+					convList = append(convList, &nodeTree{
+						NAME:     vvv.CompanyName,
+						ID:       vvv.CompanyId,
+						SZ_PID0:  v.Name,
+						SZ_PID1:  v.Name + ":" + myId,
+						SZ_PID2:  cccNodes[cccIndex].SZ_PID2,
+						SZ_PID3:  v.Name + ":" + myId + ":" + vvv.Name + ":" + vvv.CompanyId,
+						CODE:     v.Name + ":" + myId + ":" + vvv.Name + ":" + vvv.CompanyId,
+						PCODE:    cccNodes[cccIndex].PCODE,
+						SZ_LEVEL: 1,
+						SZ_LEAF:  1,
+						TYPE:     "firstparty",
+						MYID:     vvv.CompanyId,
+						MYTYPE:   "firstparty",
+					})
+				}
+				for _, cccNode := range cccNodes {
+					convList = append(convList, cccNode)
 				}
 			} else {
 				if id != "" {
@@ -453,26 +514,26 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 				myChildIds = myId
 				myChildTypes = vv.Type
 			}
-			cm := map[string]interface{}{
-				"NAME":      vv.CompanyName,
-				"ID":        myChildIds,
-				"SZ_PID0":   v.Name,
-				"SZ_PID1":   v.Name + ":" + myId,
-				"CODE":      v.Name + ":" + myId,
-				"PCODE":     v.Name,
-				"DATACOUNT": vv.Count,
-				"SZ_LEVEL":  1,
-				"SZ_LEAF":   1,
-				"TYPE":      myChildTypes,
-				"MYID":      myId,
-				"MYTYPE":    vv.Type,
+			cm := &nodeTree{
+				NAME:      vv.CompanyName,
+				ID:        myChildIds,
+				SZ_PID0:   v.Name,
+				SZ_PID1:   v.Name + ":" + myId,
+				CODE:      v.Name + ":" + myId,
+				PCODE:     v.Name,
+				DATACOUNT: vv.Count,
+				SZ_LEVEL:  1,
+				SZ_LEAF:   1,
+				TYPE:      myChildTypes,
+				MYID:      myId,
+				MYTYPE:    vv.Type,
 			}
 			convList = append(convList, cm)
 		}
-		pm["ID"] = id
-		pm["TYPE"] = pType
-		pm["MYTYPE"] = pMyType
-		pm["MYID"] = pMyId
+		pm.ID = id
+		pm.TYPE = pType
+		pm.MYTYPE = pMyType
+		pm.MYID = pMyId
 		convList = append(convList, pm)
 	}
 	reply = &types.Reply{
@@ -765,6 +826,9 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 //
 func (n *network) FirstpartyNetwork(name string, values []string) map[string][]*firstpartyNetwork {
 	result := map[string][]*firstpartyNetwork{}
+	if len(values) == 0 {
+		return result
+	}
 	wh, args := NetworkCom.WhArgs(values)
 	q := `select DISTINCT a.a_id,a.b_id as company_id,a.b_name as company_name,b.name from information.ent_map_code a 
 				inner join information.ent_code b on (a.a_id in (` + wh + `) and b.pcode in ('0100','0200') and a.code=b.code)`
@@ -857,7 +921,6 @@ func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entM
 		}
 		result[k].BuyerCount = int64(len(v))
 		for _, vv := range v {
-			log.Println(k, vv.CompanyName)
 			if entMonitor[vv.CompanyName] {
 				result[k].MonitorCount++
 			}
@@ -1047,10 +1110,13 @@ func (n *network) TypeIntConvert(itype int64) string {
 
 //
 func (n *network) GetQyxyId(ids []string) map[string]string {
+	m := map[string]string{}
+	if len(ids) == 0 {
+		return m
+	}
 	wh, args := NetworkCom.WhArgs(ids)
 	q := `select id,company_id from information.ent_info where id in (` + wh + `)`
 	rows, err := ClickhouseConn.Query(context.Background(), q, args...)
-	m := map[string]string{}
 	if err != nil {
 		logx.Error(err)
 	} else {
@@ -1076,6 +1142,9 @@ func (n *network) GetQyxyId(ids []string) map[string]string {
 //
 func (n *network) BuyerProjectInfo(ids []string, probusfors []string) map[string]*projectInfo {
 	vm := map[string]*projectInfo{}
+	if len(ids) == 0 {
+		return vm
+	}
 	wh, args := NetworkCom.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 where buyer_id in (` + wh + `)`
 	if len(probusfors) > 0 {

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

@@ -159,14 +159,14 @@ func TestAddCustomService(t *testing.T) {
 func TestCandidateChannel(t *testing.T) {
 	InitConf()
 	ownerService := &OwnerService{
-		//PartyA: "",
-		//Supplier:     req.Supplier,
-		Intermediary: "30154",
+		PartyA: "15e4d804ce194a029e9fba645fda0cf0,90e9db9308024d3782a1a03e11ccd684,ed856df4ac4f4eb78a8d1ae9a5a98006,009c313ef8e740e59d57432aea777102,9df7aa60510d45a6875205c2069d550b,2c5ecd5d2a0d4c62884c30e472c95ffe",
+		//Supplier: "0d732efa7adc40529100609e6096baad",
+		//Intermediary: "30154",
 		//Heterotophy:  req.Heterotophy,
 		//Agency:       req.Agency,
-		Type:         "middleman",
+		Type:         "adiffb",
 		EntAccountId: 64,
-		PositionId:   935,
+		PositionId:   1205591999,
 	}
 	data, a1, a2, a3, a4 := ownerService.CandidateChannel()
 	for _, v := range data {

+ 29 - 11
api/internal/service/owner.go

@@ -58,6 +58,7 @@ type BuyerProject struct {
 	Area             string
 	Zbtime           int64
 	BuyerType        string
+	CId              string
 }
 type ProjectEntity struct {
 	Number          int64
@@ -139,8 +140,8 @@ func (t *OwnerService) OwnerlList() map[string]interface{} {
 	startIndex := (t.PageIndex - 1) * t.PageSize
 	endIndex := t.PageIndex * t.PageSize
 	sort.Slice(returnData, func(i, j int) bool {
-		aa := fmt.Sprintf("%s%s", returnData[i].Zbtime, returnData[i].BuyerId)
-		bb := fmt.Sprintf("%s%s", returnData[j].Zbtime, returnData[j].BuyerId)
+		aa := fmt.Sprintf("%d%s", returnData[i].Zbtime, returnData[i].BuyerId)
+		bb := fmt.Sprintf("%d%s", returnData[j].Zbtime, returnData[j].BuyerId)
 		return aa > bb
 	})
 	if startIndex < gconv.Int64(len(returnData)) {
@@ -203,7 +204,6 @@ func ConnectionsHandle(buyerArr []string, positionId int64, isAll bool) []map[st
 		return returnData
 	}
 	a5 := time.Now().Unix()
-
 	returnData = append(returnData, Findwinner(buyerArr)...)
 	a6 := time.Now().Unix()
 	logx.Info("供应商", a6-a5)
@@ -397,7 +397,6 @@ func FindMiddleman(buyerArr []string, positionId int64, returnData []map[string]
 		companyName := gconv.String(v["company_name"])
 		relateName := gconv.String(v["relate_name"])
 		relateId := gconv.String(v["relate_id"])
-		//key := fmt.Sprintf("%s_%s", relateId, companyId)
 		returnData = append(returnData, map[string]interface{}{
 			"b_id":         companyId,
 			"b_name":       companyName,
@@ -453,7 +452,7 @@ func Findfirstparty(buyerArr []string, returnData []map[string]interface{}) []ma
 		}
 		personMap := map[string]string{}
 		if len(entIdArr) > 0 {
-			personSql := fmt.Sprintf(`select  id,name from   ent_contact    where   id in (%s)  ORDER by  name`, strings.Join(entIdArr, ","))
+			personSql := fmt.Sprintf(`select  id,name as  personName from   ent_contact    where   id in (%s)  ORDER by  name`, strings.Join(entIdArr, ","))
 			personArr := PersonFindConnectionsHandle(personSql)
 			//联系人处理
 			for _, v := range personArr {
@@ -500,7 +499,7 @@ func Findfirstparty(buyerArr []string, returnData []map[string]interface{}) []ma
 						"a_id":         v.Aid,
 						"sourceType":   "firstparty",
 						"relationship": "业主的上级机构",
-						"personName":   gconv.String(personMap[v.Aid]),
+						"personName":   gconv.String(personMap[v.Bid]),
 					})
 				}
 				if code == "0201" {
@@ -511,7 +510,7 @@ func Findfirstparty(buyerArr []string, returnData []map[string]interface{}) []ma
 						"a_id":         v.Aid,
 						"sourceType":   "firstparty",
 						"relationship": "业主的股东",
-						"personName":   gconv.String(personMap[v.Aid]),
+						"personName":   gconv.String(personMap[v.Bid]),
 					})
 				}
 
@@ -560,6 +559,7 @@ func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, s
 				IsIgnore:         gconv.Bool(buyerMap["isIgnore"]),
 				IsMonitor:        gconv.Bool(buyerMap["isMonitor"]),
 				IsCreateCustomer: gconv.Bool(buyerMap["isCreateCustomer"]),
+				CId:              gconv.String(buyerMap["cId"]),
 			})
 		} else {
 			if sourceType == "1" {
@@ -581,6 +581,7 @@ func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, s
 				IsIgnore:         gconv.Bool(buyerMap["isIgnore"]),
 				IsMonitor:        gconv.Bool(buyerMap["isMonitor"]),
 				IsCreateCustomer: gconv.Bool(buyerMap["isCreateCustomer"]),
+				CId:              gconv.String(buyerMap["cId"]),
 			})
 
 		}
@@ -739,7 +740,7 @@ func BuyerList(partyA, supplier, heterotophy, intermediary, agency string, posit
 	if intermediary != "" {
 		wh, args := common.WhArgs(strings.Split(intermediary, ","))
 		args = append(args, positionId)
-		intermediaryArr := CrmMysql.SelectBySql(`select b.relate_id as relate_id,b.relate_name as relate_name from crm.connection a inner join crm.connection_introduce b on ( a.id in (`+wh+`) and  a.position_id=?  and a.id=b.connection_id and b.itype=1)`, args...)
+		intermediaryArr := CrmMysql.SelectBySql(`select a.id,b.relate_id as relate_id,b.relate_name as relate_name from crm.connection a inner join crm.connection_introduce b on ( a.id in (`+wh+`) and  a.position_id=?  and a.id=b.connection_id and b.itype=1)`, args...)
 		if intermediaryArr != nil && len(*intermediaryArr) > 0 {
 			for _, m := range *intermediaryArr {
 				buyerId := gconv.String(m["relate_id"])
@@ -747,6 +748,7 @@ func BuyerList(partyA, supplier, heterotophy, intermediary, agency string, posit
 				(*dataMap)[buyerId] = map[string]interface{}{
 					"buyerName": buyerName,
 					"buyerType": "middleman",
+					"cId":       gconv.String(m["id"]),
 				}
 			}
 		}
@@ -1087,8 +1089,14 @@ func (t *OwnerService) CandidateChannel() ([]*ResultData, int, int, int, int) {
 	a1, a2, a3, a4 := 0, 0, 0, 0
 	if len(*dataMap) > 0 && dataMap != nil {
 		propertyForm := NetworkCom.GetMyProbusfor(t.EntAccountId)
+		buyerIds := []string{}
+		for buyerId := range *dataMap {
+			buyerIds = append(buyerIds, buyerId)
+		}
+		rs1, rs2 := GetData(propertyForm, strings.Join(buyerIds, ","))
 		for buyerId := range *dataMap {
-			r1, r2 := GetData(propertyForm, buyerId)
+			r1 := rs1[buyerId]
+			r2 := rs2[buyerId]
 			if r1 != nil && len(r1) > 0 {
 				for _, m := range r1 {
 					near, zbtime := LastTimeCoop(buyerId, common.ObjToString(m["name"]), "adiffb")
@@ -1102,6 +1110,9 @@ func (t *OwnerService) CandidateChannel() ([]*ResultData, int, int, int, int) {
 						RecentTime:  zbtime,
 						NearlyYears: near,
 					}
+					if tmp.BuyerId == "" {
+						continue
+					}
 					a1++
 					returnData = append(returnData, &tmp)
 				}
@@ -1119,6 +1130,9 @@ func (t *OwnerService) CandidateChannel() ([]*ResultData, int, int, int, int) {
 						EntId:       common.ObjToString(m["nameId"]),
 						BuyerId:     buyerId,
 					}
+					if tmp.BuyerId == "" {
+						continue
+					}
 					a2++
 					returnData = append(returnData, &tmp)
 				}
@@ -1137,6 +1151,9 @@ func (t *OwnerService) CandidateChannel() ([]*ResultData, int, int, int, int) {
 						EntId:        common.ObjToString(m["b_id"]),
 						BuyerId:      buyerId,
 					}
+					if tmp.BuyerId == "" {
+						continue
+					}
 					a3++
 					returnData = append(returnData, &tmp)
 				}
@@ -1154,6 +1171,9 @@ func (t *OwnerService) CandidateChannel() ([]*ResultData, int, int, int, int) {
 						EntId:        common.ObjToString(m["b_id"]),
 						BuyerId:      buyerId,
 					}
+					if tmp.BuyerId == "" {
+						continue
+					}
 					a4++
 					returnData = append(returnData, &tmp)
 				}
@@ -1179,8 +1199,6 @@ func (t *OwnerService) CandidateChannel() ([]*ResultData, int, int, int, int) {
 			returnData[k] = value
 			if t.Type != "" && t.Type != value.SourceType {
 				continue
-			} else if value.BuyerId == "" {
-				continue
 			}
 			result = append(result, value)
 		}