Ver Fonte

Merge remote-tracking branch 'origin/feature/v1.0.4' into dev_v1.0.4_wh

WH01243 há 1 ano atrás
pai
commit
c772aa012f

+ 1 - 0
api/internal/logic/addorupdatelogic.go

@@ -25,6 +25,7 @@ func NewAddOrUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddOr
 }
 
 func (l *AddOrUpdateLogic) AddOrUpdate(req *types.AddOrUpdateReq) (resp *types.Reply, err error) {
+	logx.Info(fmt.Sprintf("%+v", req))
 	resp = service.Network.AddOrUpdate(req)
 	return
 }

+ 1 - 0
api/internal/logic/allprojectlogic.go

@@ -24,6 +24,7 @@ func NewAllProjectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AllPro
 }
 
 func (l *AllProjectLogic) AllProject(req *types.AllprojectReq) (resp *types.Reply, err error) {
+	logx.Info(fmt.Sprintf("%+v", req))
 	resp = service.Network.AllProject(req)
 	return
 }

+ 1 - 0
api/internal/logic/associatelogic.go

@@ -25,6 +25,7 @@ func NewAssociateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Associa
 }
 
 func (l *AssociateLogic) Associate(req *types.AssociateReq) (resp *types.Reply, err error) {
+	logx.Info(fmt.Sprintf("%+v", req))
 	resp = service.Network.Associate(req)
 	return
 }

+ 6 - 11
api/internal/logic/coophistorylistlogic.go

@@ -26,17 +26,12 @@ func NewCoopHistoryListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C
 func (l *CoopHistoryListLogic) CoopHistoryList(req *types.CoopHistoryReq) (resp *types.Reply, err error) {
 	resp = &types.Reply{}
 	result, size1, size2, size3, size4 := service.GetPrList(req)
-	if result == nil {
-		resp.Error_code = -1
-		resp.Error_msg = "查询异常"
-	} else {
-		resp.Data = map[string]interface{}{
-			"list":  result,
-			"size1": size1,
-			"size2": size2,
-			"size3": size3,
-			"size4": size4,
-		}
+	resp.Data = map[string]interface{}{
+		"list":  result,
+		"size1": size1,
+		"size2": size2,
+		"size3": size3,
+		"size4": size4,
 	}
 
 	return

+ 1 - 0
api/internal/logic/networklistlogic.go

@@ -24,6 +24,7 @@ func NewNetworkListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Netwo
 }
 
 func (l *NetworkListLogic) NetworkList(req *types.NetWorkListReq) (resp *types.Reply, err error) {
+	logx.Info(fmt.Sprintf("%+v", req))
 	resp = service.Network.List(req)
 	return
 }

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

@@ -15,16 +15,17 @@ import (
 var (
 	INDEX_1   = "transaction_info"
 	sql_2_0   = `SELECT buyer, buyer_id, agency, agency_id, property_form FROM information.transaction_info WHERE project_id = ?`
-	sql_2_1   = `SELECT project_id, project_name, zbtime FROM information.transaction_info WHERE buyer_id = ? AND has(winner_id, ?) ORDER BY zbtime DESC`
+	sql_2_1   = `SELECT project_id, project_name, zbtime FROM information.transaction_info WHERE buyer_id = ? AND has(winner, ?) 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": "%s"}}],"must_not": {"term": {"property_form": "%s"}}}},"aggs": {"winner_count": {"terms": {"field": "winner","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "bidamount"}}}}},"size": 1}`
-	es_query1 = `{"query": {"bool": {"must": [{"term": {"buyer": "%s"}}]}},"aggs": {"agency_count": {"terms": {"field": "agency","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "bidamount"}}}}},"size": 1}`
+	es_query  = `{"query": {"bool": {"must": [{"term": {"buyer_id": "%s"}}],"must_not": {"term": {"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"}}]}},"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}`
 )
 
 type ResultData struct {
 	SourceType   string  `json:"SourceType"`
 	EntName      string  `json:"EntName"`
+	EntId        string  `json:"EntId"`
 	EntPerson    string  `json:"EntPerson"`
 	Middleman    string  `json:"Middleman"`
 	ProjectNum   int     `json:"ProjectNum"`
@@ -34,6 +35,7 @@ type ResultData struct {
 	SupEnt       string  `json:"SupEnt"`       // 上级
 	NextEnt      string  `json:"NextEnt"`      // 下级
 	Relationship string  `json:"Relationship"` // 关系
+	BuyerId      string  `json:"BuyerId"`
 }
 
 type ProjectTmp struct {
@@ -51,7 +53,7 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 		return nil, 0, 0, 0, 0
 	}
 	propertyForm := ""
-	m1 := T.CrmMysql.FindOne("config_tenant", map[string]interface{}{"account_id": req.EntAccountId}, "probusfor", "")
+	m1 := T.CrmMysql.FindOne("config_tenant", map[string]interface{}{"entAccountId": req.EntAccountId}, "probusfor", "")
 	if m1 != nil && len(*m1) > 0 {
 		propertyForm = common.ObjToString((*m1)["probusfor"])
 	}
@@ -70,6 +72,7 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 					TotalAmount: common.Float64All(m["coop_amount"]),
 					RecentTime:  zbtime,
 					NearlyYears: near,
+					BuyerId:     pTmp.BuyerId,
 				}
 				result = append(result, &tmp)
 			}
@@ -85,6 +88,7 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 					TotalAmount: common.Float64All(m["coop_amount"]),
 					RecentTime:  zbtime,
 					NearlyYears: near,
+					BuyerId:     pTmp.BuyerId,
 				}
 				result = append(result, &tmp)
 			}
@@ -101,8 +105,10 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 					tmp := ResultData{
 						SourceType:   "middleman",
 						EntName:      common.ObjToString(m["b_name"]),
+						EntId:        common.ObjToString(m["b_id"]),
 						EntPerson:    common.ObjToString(m["personName"]),
 						Relationship: "业主的关系人",
+						BuyerId:      pTmp.BuyerId,
 					}
 					result = append(result, &tmp)
 				}
@@ -118,8 +124,10 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 					tmp := ResultData{
 						SourceType:   "sup_sub",
 						EntName:      common.ObjToString(m["b_name"]),
+						EntId:        common.ObjToString(m["b_id"]),
 						EntPerson:    common.ObjToString(m["personName"]),
 						Relationship: common.ObjToString(m["relationship"]),
+						BuyerId:      pTmp.BuyerId,
 					}
 					result = append(result, &tmp)
 				}
@@ -138,13 +146,19 @@ func GetData(propertyForm, bid string) (result1, result2 []map[string]interface{
 			Amount_all struct {
 				Value float64 `json:"value,omitempty"`
 			} `json:"amount_all"`
+			EntId struct {
+				Buckets []struct {
+					Key       string `json:"key,omitempty"`
+					Doc_count int64  `json:"doc_count,omitempty"`
+				} `json:"buckets"`
+			} `json:"ent_id"`
 		} `json:"buckets"`
 	}
 	m1 := make(map[string]interface{}) //采购单位-中标单位
 	m2 := make(map[string]interface{}) //采购单位-代理机构
 	if propertyForm != "" {
 		//同甲异态 中标企业
-		aggs, count, res := elastic.GetAggs("bidding", "bidding", fmt.Sprintf(es_query, propertyForm, "中国计量大学"))
+		aggs, count, res := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, bid, propertyForm))
 		logx.Info("es聚合查询结果:", aggs, count, res)
 		var m1Buckets = AggStruct{}
 		if aggs != nil && aggs["winner_count"] != nil {
@@ -159,7 +173,9 @@ func GetData(propertyForm, bid string) (result1, result2 []map[string]interface{
 					logx.Info(err)
 					if len(m1Buckets.Buckets) > 0 {
 						for _, v := range m1Buckets.Buckets {
-							m1[v.Key] = map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count}
+							if v.Key != "" {
+								m1[v.Key] = map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count}
+							}
 						}
 					}
 				}

+ 80 - 21
api/internal/service/employService.go

@@ -670,19 +670,19 @@ func employInfoPerson(table, employKey, findKey string, in *types.InfoEmployinfo
 	wuyeData1 := &[]map[string]interface{}{}
 	wuyeData2 := &[]map[string]interface{}{}
 	if len(infoId1Arr) > 0 {
-		infoData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select   %s, is_ignore,status,id,type from  %s   where position_id =? and  %s in ('%s')    GROUP BY %s ", employKey, table, employKey, strings.Join(infoId1Arr, "','"), employKey), in.PositionId)
+		infoData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select   %s, is_ignore,status,id,type from  %s   where position_id =? and  %s in ('%s')    GROUP BY %s ,type  order  by type", employKey, table, employKey, strings.Join(infoId1Arr, "','"), employKey), in.PositionId)
 	}
 	if len(infoId2Arr) > 0 {
-		infoData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  %s,  is_ignore,status,id,type from  %s   where position_id =? and  %s in '%s')    GROUP BY %s ", employKey, table, employKey, strings.Join(infoId2Arr, "','"), employKey), in.PositionId)
+		infoData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  %s,  is_ignore,status,id,type from  %s   where position_id =? and  %s in '%s')    GROUP BY %s ,type order  by type ", employKey, table, employKey, strings.Join(infoId2Arr, "','"), employKey), in.PositionId)
 	}
 	if len(niJianIdArr) > 0 {
-		niJianData = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s,   is_ignore,status,id,type from  %s   where position_id =? and  %s in ('%s')    GROUP BY %s ", employKey, table, employKey, strings.Join(niJianIdArr, "','"), employKey), in.PositionId)
+		niJianData = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s,   is_ignore,status,id,type from  %s   where position_id =? and  %s in ('%s')    GROUP BY %s  ,type order  by type", employKey, table, employKey, strings.Join(niJianIdArr, "','"), employKey), in.PositionId)
 	}
 	if len(wuye1Arr) > 0 {
-		wuyeData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  %s,  is_ignore,status,id,type from  %s   where position_id =? and  %s in ('%s')  GROUP BY %s ", employKey, table, employKey, strings.Join(wuye1Arr, "','"), employKey), in.PositionId)
+		wuyeData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select  %s,  is_ignore,status,id,type from  %s   where position_id =? and  %s in ('%s')  GROUP BY %s  ,type order  by type", employKey, table, employKey, strings.Join(wuye1Arr, "','"), employKey), in.PositionId)
 	}
 	if len(wuye2Arr) > 0 {
-		wuyeData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select   %s, is_ignore,status,id,type from  %s   where position_id =? and  %s in ('%s')    GROUP BY %s ", employKey, table, employKey, strings.Join(wuye2Arr, "','"), employKey), in.PositionId)
+		wuyeData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select   %s, is_ignore,status,id,type from  %s   where position_id =? and  %s in ('%s')    GROUP BY %s ,type order  by type ", employKey, table, employKey, strings.Join(wuye2Arr, "','"), employKey), in.PositionId)
 	}
 	for _, v := range *infoData1 {
 		valueMap := map[string]interface{}{
@@ -695,7 +695,12 @@ func employInfoPerson(table, employKey, findKey string, in *types.InfoEmployinfo
 			"type":        1,
 		}
 		sourceId := gconv.String(v[employKey])
-		data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+		if _, ok := data[sourceId]; ok {
+			data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+		} else {
+			data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		}
 	}
 	for _, v := range *infoData2 {
 		valueMap := map[string]interface{}{
@@ -708,7 +713,13 @@ func employInfoPerson(table, employKey, findKey string, in *types.InfoEmployinfo
 			"type":        1,
 		}
 		sourceId := gconv.String(v[employKey])
-		data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+		if _, ok := data[sourceId]; ok {
+			data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		} else {
+			data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		}
 	}
 	for _, v := range *niJianData {
 		valueMap := map[string]interface{}{
@@ -721,7 +732,13 @@ func employInfoPerson(table, employKey, findKey string, in *types.InfoEmployinfo
 			"type":        1,
 		}
 		sourceId := gconv.String(v[employKey])
-		data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+		if _, ok := data[sourceId]; ok {
+			data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		} else {
+			data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		}
 	}
 	for _, v := range *wuyeData1 {
 		valueMap := map[string]interface{}{
@@ -734,7 +751,13 @@ func employInfoPerson(table, employKey, findKey string, in *types.InfoEmployinfo
 			"type":        1,
 		}
 		sourceId := gconv.String(v[employKey])
-		data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+		if _, ok := data[sourceId]; ok {
+			data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		} else {
+			data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		}
 	}
 	for _, v := range *wuyeData2 {
 		valueMap := map[string]interface{}{
@@ -747,7 +770,13 @@ func employInfoPerson(table, employKey, findKey string, in *types.InfoEmployinfo
 			"type":        1,
 		}
 		sourceId := gconv.String(v[employKey])
-		data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+		if _, ok := data[sourceId]; ok {
+			data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		} else {
+			data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		}
 	}
 	return data
 }
@@ -761,19 +790,19 @@ func employInfoEnt(table, employKey, findKey, depIDArr string, in *types.InfoEmp
 	wuyeData1 := &[]map[string]interface{}{}
 	wuyeData2 := &[]map[string]interface{}{}
 	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 ", employKey, table, employKey, strings.Join(infoId1Arr, "','"), depIDArr, employKey), 1)
+		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 ,type order  by type", employKey, table, employKey, strings.Join(infoId1Arr, "','"), depIDArr, employKey), 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 ", employKey, table, employKey, strings.Join(infoId2Arr, "','"), depIDArr, employKey), 2)
+		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 ,type order  by type", employKey, table, employKey, strings.Join(infoId2Arr, "','"), depIDArr, employKey), 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 ", employKey, table, employKey, strings.Join(niJianIdArr, "','"), depIDArr, employKey), 2)
+		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 ,type order  by type", employKey, table, employKey, strings.Join(niJianIdArr, "','"), depIDArr, employKey), 2)
 	}
 	if len(wuye1Arr) > 0 {
-		wuyeData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s,  id,is_ignore,status ,type  from  %s   where %s in ('%s')  and status =1 and  source=? and    ent_dept_id in  (%s)  GROUP BY %s  ", employKey, table, employKey, strings.Join(wuye1Arr, "','"), depIDArr, employKey), 1)
+		wuyeData1 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s,  id,is_ignore,status ,type  from  %s   where %s in ('%s')  and status =1 and  source=? and    ent_dept_id in  (%s)  GROUP BY %s  ,type order  by type", employKey, table, employKey, strings.Join(wuye1Arr, "','"), depIDArr, employKey), 1)
 	}
 	if len(wuye2Arr) > 0 {
-		wuyeData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s id,is_ignore,status ,type  from  %s   where %s  in ('%s')  and status =1 and  source=? and    ent_dept_id in  (%s) GROUP BY %s ", employKey, table, employKey, strings.Join(wuye2Arr, "','"), depIDArr, employKey), 2)
+		wuyeData2 = MC.CrmMysql.SelectBySql(fmt.Sprintf("select %s id,is_ignore,status ,type  from  %s   where %s  in ('%s')  and status =1 and  source=? and    ent_dept_id in  (%s) GROUP BY %s ,type order  by type", employKey, table, employKey, strings.Join(wuye2Arr, "','"), depIDArr, employKey), 2)
 	}
 	for _, v := range *infoData1 {
 		valueMap := map[string]interface{}{
@@ -786,7 +815,13 @@ func employInfoEnt(table, employKey, findKey, depIDArr string, in *types.InfoEmp
 			"type":        1,
 		}
 		sourceId := gconv.String(v[employKey])
-		data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+		if _, ok := data[sourceId]; ok {
+			data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		} else {
+			data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		}
 	}
 	for _, v := range *infoData2 {
 		valueMap := map[string]interface{}{
@@ -799,7 +834,13 @@ func employInfoEnt(table, employKey, findKey, depIDArr string, in *types.InfoEmp
 			"type":        1,
 		}
 		sourceId := gconv.String(v[employKey])
-		data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+		if _, ok := data[sourceId]; ok {
+			data[sourceId] = EmployHandle(data[sourceId], v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		} else {
+			data[sourceId] = EmployHandle(valueMap, v, 0, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		}
 	}
 	for _, v := range *niJianData {
 		valueMap := map[string]interface{}{
@@ -812,7 +853,13 @@ func employInfoEnt(table, employKey, findKey, depIDArr string, in *types.InfoEmp
 			"type":        1,
 		}
 		sourceId := gconv.String(v[employKey])
-		data[sourceId] = EmployHandle(valueMap, v, version, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+		if _, ok := data[sourceId]; ok {
+			data[sourceId] = EmployHandle(data[sourceId], v, version, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		} else {
+			data[sourceId] = EmployHandle(valueMap, v, version, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		}
 	}
 	for _, v := range *wuyeData1 {
 		valueMap := map[string]interface{}{
@@ -825,7 +872,13 @@ func employInfoEnt(table, employKey, findKey, depIDArr string, in *types.InfoEmp
 			"type":        1,
 		}
 		sourceId := gconv.String(v[employKey])
-		data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+		if _, ok := data[sourceId]; ok {
+			data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		} else {
+			data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		}
 	}
 	for _, v := range *wuyeData2 {
 		valueMap := map[string]interface{}{
@@ -838,7 +891,13 @@ func employInfoEnt(table, employKey, findKey, depIDArr string, in *types.InfoEmp
 			"type":        1,
 		}
 		sourceId := gconv.String(v[employKey])
-		data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+		if _, ok := data[sourceId]; ok {
+			data[sourceId] = EmployHandle(data[sourceId], v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		} else {
+			data[sourceId] = EmployHandle(valueMap, v, 1, in.From, len(strings.Split(in.IdArr, ",")) == 1, findKey, in.PositionId, in.PositionType, in.EmployType)
+
+		}
 	}
 	return data
 }
@@ -863,7 +922,7 @@ func EmployHandle(valueMap map[string]interface{}, employData map[string]interfa
 			}
 		case 3:
 			if valueMap["employ2"] != nil {
-				employ3 = gconv.Bool(valueMap["employ2"])
+				employ2 = gconv.Bool(valueMap["employ2"])
 			}
 			if employStatus == 1 {
 				employ3 = true

+ 427 - 275
api/internal/service/network.go

@@ -7,7 +7,6 @@ import (
 	"math"
 	"sort"
 	"strings"
-	"sync"
 	"time"
 
 	. "app.yhyue.com/moapp/jybase/common"
@@ -74,6 +73,33 @@ type firstpartyNetwork struct {
 	CompanyName string
 	Name        string
 }
+type idName struct {
+	Id   string
+	Name string
+}
+type introduceOwnerProject struct {
+	Networks          []*myNetwork
+	FirstpartyNetwork map[string][]*firstpartyNetwork
+	Firstparty        map[string]*projectInfo
+	Supplier          map[string]*projectInfo
+	Adiffb            map[string]*projectInfo
+	Agency            map[string]*projectInfo
+	Middleman         map[string]*projectInfo
+}
+type myNetwork struct {
+	Id                int64
+	Company_id        string
+	Company_name      string
+	Qyxy_id           string
+	Itype             int64
+	Person            string
+	Phone             string
+	Buyer_count       int64
+	Project_count     int64
+	Relate_buyer_id   string
+	Relate_project_id string
+	Create_time       string
+}
 
 //人脉库-添加/修改人脉
 func (n *network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
@@ -83,6 +109,9 @@ func (n *network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
 	if in.Type != "middleman" && in.Company_id == "" {
 		return reply
 	}
+	if in.Company_name == "" {
+		in.Company_name = "未填写"
+	}
 	nowFormat := NowFormat(Date_Full_Layout)
 	var saveIntroduce = func(tx *sql.Tx, cid int64, isUpdate bool) bool {
 		if in.Type != "middleman" {
@@ -255,62 +284,47 @@ func (n *network) Associate(in *types.AssociateReq) (reply *types.Reply) {
 
 //人脉库-全部人脉项目
 func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
-	pool := make(chan bool, 5)
-	wait := &sync.WaitGroup{}
-	lock := &sync.Mutex{}
 	reply = &types.Reply{}
-	wh, newArgs := NetworkCom.WhArgs(NetworkCom.GetMyProbusfor(in.EntAccountId))
+	probusfors := NetworkCom.GetMyProbusfor(in.EntAccountId)
 	var count int64
 	var list []*networkTree
+	firstpartyChild := map[string][]*firstpartyNetwork{}
 	if in.Id != "" {
 		if in.Type == "firstparty" {
-			result := n.FirstpartyNetwork(in.Name, []string{in.Id})
-			if result[in.Id] != nil {
+			fpn := n.FirstpartyNetwork(in.Name, []string{in.Id})
+			if fpn[in.Id] != nil {
+				firstparty := n.Introduce_Firstparty(fpn, map[string]bool{}, probusfors)
 				nameIndex := map[string]int{}
-				for _, v := range result[in.Id] {
+				for _, v := range fpn[in.Id] {
 					if _, ok := nameIndex[v.Name]; !ok {
 						nameIndex[v.Name] = len(list)
 						list = append(list, &networkTree{
 							Name: v.Name,
 						})
 					}
-					pool <- true
-					wait.Add(1)
-					go func(cIndex int, cId, cName string) {
-						defer func() {
-							<-pool
-							wait.Done()
-						}()
-						ntc := &networkTreeChild{
-							CompanyName: cName,
-							CompanyId:   cId,
-							Type:        "firstparty",
-						}
-						if wh != "" {
-							thisArgs := []interface{}{ntc.CompanyId}
-							thisArgs = append(thisArgs, newArgs...)
-							ntc.Count = NetworkCom.Count(`select count(1) from information.transaction_info where buyer_id=? and hasAny(property_form,[`+wh+`])`, thisArgs...)
-						}
-						lock.Lock()
-						count++
-						list[cIndex].Count += ntc.Count
-						list[cIndex].Children = append(list[cIndex].Children, ntc)
-						lock.Unlock()
-					}(nameIndex[v.Name], v.CompanyId, v.CompanyName)
+					ntc := &networkTreeChild{
+						CompanyName: v.CompanyName,
+						CompanyId:   v.CompanyId,
+						Type:        "firstparty",
+					}
+					if firstparty[v.CompanyId] != nil {
+						ntc.Count = firstparty[v.CompanyId].ProjectCount
+					}
+					count++
+					list[nameIndex[v.Name]].Count += ntc.Count
+					list[nameIndex[v.Name]].Children = append(list[nameIndex[v.Name]].Children, ntc)
 				}
-				wait.Wait()
 			}
 		}
 	} else {
-		q := `SELECT a.id,a.company_id,a.company_name,a.itype,a.create_time,COUNT(b.id) AS ipc FROM crm.connection a 
-			LEFT JOIN crm.connection_introduce b ON (b.position_id=? AND b.itype=2 AND a.id=b.connection_id) WHERE a.position_id=?`
-		args := []interface{}{in.PositionId, in.PositionId}
+		args := []interface{}{in.PositionId, in.PositionId, in.PositionId}
+		sqlAppend1 := ""
 		if in.Name != "" {
-			q += ` and company_name like ?`
+			sqlAppend1 += ` and a.company_name like ?`
 			args = append(args, "%"+in.Name+"%")
 		}
-		q += ` GROUP BY a.id ORDER BY a.create_time DESC`
-		datas := CrmMysql.SelectBySql(q, args...)
+		aio := n.AllIntroduceOwner(sqlAppend1, "", args, true, probusfors, map[string]bool{})
+		firstpartyChild = aio.FirstpartyNetwork
 		list = []*networkTree{
 			&networkTree{
 				Name:     "甲方",
@@ -334,50 +348,47 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 			},
 		}
 		//
-		for _, vt := range *datas {
-			pool <- true
-			wait.Add(1)
-			go func(v map[string]interface{}) {
-				defer func() {
-					<-pool
-					wait.Done()
-				}()
-				itype := IntAll(v["itype"])
-				if itype <= 0 || itype > len(list) {
-					return
+		for _, v := range aio.Networks {
+			if v.Itype <= 0 || v.Itype > int64(len(list)) {
+				return
+			}
+			ntc := &networkTreeChild{
+				Id:          v.Id,
+				CompanyName: v.Company_name,
+				CompanyId:   v.Company_id,
+				Type:        n.TypeIntConvert(v.Itype),
+				CreateTime:  v.Create_time,
+			}
+			switch v.Itype {
+			case 1:
+				if aio.Firstparty[v.Company_id] != nil {
+					ntc.Count = aio.Firstparty[v.Company_id].ProjectCount
 				}
-				company_name := ObjToString(v["company_name"])
-				if company_name == "" {
-					company_name = "未填写"
+			case 2:
+				if aio.Supplier[v.Company_id] != nil {
+					ntc.Count = aio.Supplier[v.Company_id].ProjectCount
 				}
-				ntc := &networkTreeChild{
-					Id:          Int64All(v["id"]),
-					CompanyName: company_name,
-					CompanyId:   ObjToString(v["company_id"]),
-					Type:        n.TypeIntConvert(Int64All(v["itype"])),
-					CreateTime:  ObjToString(v["create_time"]),
+			case 3:
+				if aio.Adiffb[v.Company_id] != nil {
+					ntc.Count = aio.Adiffb[v.Company_id].ProjectCount
 				}
-				if wh != "" {
-					thisArgs := []interface{}{ntc.CompanyId}
-					thisArgs = append(thisArgs, newArgs...)
-					if itype == 1 {
-						ntc.Count = NetworkCom.Count(`select count(1) from information.transaction_info where buyer_id=? and hasAny(property_form,[`+wh+`])`, thisArgs...)
-					} else if itype == 2 || itype == 3 {
-						ntc.Count = NetworkCom.Count(`select count(1) from information.transaction_info where has(winner_id,?) and hasAny(property_form,[`+wh+`])`, thisArgs...)
-					} else if itype == 4 {
-						ntc.Count = Int64All(v["ipc"])
-					} else if itype == 5 {
-						ntc.Count = NetworkCom.Count(`select count(1) from information.transaction_info where agency_id=? and hasAny(property_form,[`+wh+`])`, thisArgs...)
+			case 4:
+				if v.Relate_project_id != "" {
+					for _, v := range strings.Split(v.Relate_project_id, ",") {
+						if aio.Middleman[v] != nil {
+							ntc.Count++
+						}
 					}
 				}
-				lock.Lock()
-				count += ntc.Count
-				list[itype-1].Count += ntc.Count
-				list[itype-1].Children = append(list[itype-1].Children, ntc)
-				lock.Unlock()
-			}(vt)
+			case 5:
+				if aio.Agency[v.Company_id] != nil {
+					ntc.Count = aio.Agency[v.Company_id].ProjectCount
+				}
+			}
+			count += ntc.Count
+			list[v.Itype-1].Count += ntc.Count
+			list[v.Itype-1].Children = append(list[v.Itype-1].Children, ntc)
 		}
-		wait.Wait()
 	}
 	convList := []map[string]interface{}{}
 	for _, v := range list {
@@ -393,25 +404,53 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 		} else {
 			pm["SZ_LEAF"] = 1
 		}
-		ID := ""
-		pType := ""
 		sort.Sort(v)
+		id := ""
+		pType := ""
 		for _, vv := range v.Children {
-			if ID != "" {
-				ID += ","
-			}
-			if pType != "" {
-				pType += ","
-			}
 			tempId := vv.CompanyId
 			if vv.Type == "middleman" {
 				tempId = fmt.Sprint(vv.Id)
 			}
-			ID += tempId
-			pType += vv.Type
+			myChildIds, myChildTypes := "", ""
+			if in.Id == "" && v.Name == "甲方" {
+				for _, vvv := range firstpartyChild[vv.CompanyId] {
+					if id != "" {
+						id += ","
+					}
+					id += vvv.CompanyId
+					if pType != "" {
+						pType += ","
+					}
+					pType += vv.Type
+					if myChildIds != "" {
+						myChildIds += ","
+					}
+					myChildIds += vvv.CompanyId
+					if myChildTypes != "" {
+						myChildTypes += ","
+					}
+					myChildTypes += vv.Type
+				}
+			} else {
+				if id != "" {
+					id += ","
+				}
+				id += tempId
+				if pType != "" {
+					pType += ","
+				}
+				pType += vv.Type
+			}
+			if myChildIds == "" {
+				myChildIds = tempId
+			}
+			if myChildTypes == "" {
+				myChildTypes = vv.Type
+			}
 			cm := map[string]interface{}{
 				"NAME":      vv.CompanyName,
-				"ID":        tempId,
+				"ID":        myChildIds,
 				"SZ_PID0":   v.Name,
 				"SZ_PID1":   v.Name + ":" + tempId,
 				"CODE":      v.Name + ":" + tempId,
@@ -419,11 +458,12 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 				"DATACOUNT": vv.Count,
 				"SZ_LEVEL":  1,
 				"SZ_LEAF":   1,
-				"TYPE":      vv.Type,
+				"TYPE":      myChildTypes,
+				"MYID":      tempId,
 			}
 			convList = append(convList, cm)
 		}
-		pm["ID"] = ID
+		pm["ID"] = id
 		pm["TYPE"] = pType
 		convList = append(convList, pm)
 	}
@@ -438,19 +478,25 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 
 //人脉库-列表
 func (n *network) List(in *types.NetWorkListReq) *types.Reply {
-	q := `select a.id,a.company_id,a.company_name,a.qyxy_id,a.itype,a.contact_person as person,a.contact_phone as phone,count(DISTINCT if(b.itype=1,b.relate_id,null)) as buyer_count,count(DISTINCT if(b.itype=2,b.relate_id,null)) as project_count,GROUP_CONCAT(IF(b.itype=1,b.relate_id,NULL)) AS relate_buyer_id,GROUP_CONCAT(IF(b.itype=2,b.relate_id,NULL)) AS relate_project_id,a.create_time from crm.connection a 
-		left join crm.connection_introduce b on (a.id=b.connection_id) where a.position_id=?`
-	args := []interface{}{in.PositionId}
+	if in.Page_size <= 0 {
+		in.Page_size = 10
+	}
+	if in.Current_page <= 0 {
+		in.Current_page = 1
+	}
+	logx.Info(fmt.Sprintf("%+v", in))
+	args := []interface{}{in.PositionId, in.PositionId, in.PositionId}
+	sqlAppend1 := ""
 	if in.Type != "" {
-		q += ` and a.itype=?`
+		sqlAppend1 += ` and a.itype=?`
 		args = append(args, n.TypeStrConvert(in.Type))
 	}
 	if in.Starttime != "" {
-		q += ` and a.create_time>=?`
+		sqlAppend1 += ` and a.create_time>=?`
 		args = append(args, in.Starttime+" 00:00:00")
 	}
 	if in.Endtime != "" {
-		q += ` and a.create_time<=?`
+		sqlAppend1 += ` and a.create_time<=?`
 		if in.Starttime == in.Endtime {
 			in.Endtime += " 23:59:59"
 		} else {
@@ -459,104 +505,88 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 		args = append(args, in.Endtime)
 	}
 	if in.Name != "" {
-		q += ` and a.company_name like ?`
+		sqlAppend1 += ` and a.company_name like ?`
 		args = append(args, "%"+in.Name+"%")
 	}
-	q += ` GROUP BY a.id order by a.create_time desc`
-	listTemp := CrmMysql.SelectBySql(q, args...)
-	firstparty_array, supplier_array, adiffb_array, agency_array, middleman_project_array := []string{}, []string{}, []string{}, []string{}, []string{}
-	for _, v := range *listTemp {
-		switch Int64All(v["itype"]) {
-		case 1:
-			firstparty_array = append(firstparty_array, ObjToString(v["company_id"]))
-		case 2:
-			supplier_array = append(supplier_array, ObjToString(v["company_id"]))
-		case 3:
-			adiffb_array = append(adiffb_array, ObjToString(v["company_id"]))
-		case 4:
-			if relate_project_id := ObjToString(v["relate_project_id"]); relate_project_id != "" {
-				middleman_project_array = append(middleman_project_array, strings.Split(relate_project_id, ",")...)
-			}
-		case 5:
-			agency_array = append(agency_array, ObjToString(v["company_id"]))
-		}
+	var count int64
+	start := (in.Current_page - 1) * in.Page_size
+	end := start + in.Page_size
+	dbPaging := in.Buyercount_start == 0 && in.Buyercount_end == 0 && in.Monitor == 0 && in.Monitorcount_start == 0 && in.Monitorcount_end == 0 && in.Project_matchme == 0 && in.Order_amount == 0
+	sqlAppend2 := ""
+	if dbPaging {
+		count = CrmMysql.CountBySql(`select count(1) as count from crm.connection a where a.position_id=?`+sqlAppend1, args...)
+		sqlAppend2 = ` limit ?,?`
+		args = append(args, start, end)
 	}
 	//
 	firstparty_count, supplier_count, adiffb_count, middleman_count, agency_count := 0, 0, 0, 0, 0
 	list := []*map[string]interface{}{}
-	isGoNextSetp := true
+	isTjProject := true
 	probusfors := []string{}
 	if in.Project_matchme == 1 {
 		probusfors = NetworkCom.GetMyProbusfor(in.EntAccountId)
 		if len(probusfors) == 0 {
-			isGoNextSetp = false
+			isTjProject = false
 		}
 	}
-	if isGoNextSetp {
+	if isTjProject {
 		entMonitor := NetworkCom.EntMonitor(in.UserId)
-		fpn := n.FirstpartyNetwork("", firstparty_array)
-		firstparty_project := n.Introduce_Firstparty(fpn, entMonitor, in.Project_matchme, probusfors)
-		supplier_project := n.Introduce_Supplier(supplier_array, entMonitor, in.Project_matchme, probusfors)
-		adiffb_project := n.Introduce_Supplier(adiffb_array, entMonitor, in.Project_matchme, probusfors)
-		agency_project := n.Introduce_Agency(agency_array, entMonitor, in.Project_matchme, probusfors)
-		middleman_project := n.Introduce_Middleman(middleman_project_array, entMonitor, in.Project_matchme, probusfors)
-		for _, v := range *listTemp {
+		aio := n.AllIntroduceOwner(sqlAppend1, sqlAppend2, args, isTjProject, probusfors, entMonitor)
+		for _, v := range aio.Networks {
 			itype := ""
 			buyer_count, project_count, expect_amount, monitor_count := int64(0), int64(0), float64(0), int64(0)
-			company_id := ObjToString(v["company_id"])
 			export_id := []string{}
 			jump_type, jump_id := "", ""
-			switch Int64All(v["itype"]) {
+			switch v.Itype {
 			case 1:
 				itype = "甲方"
 				jump_type = "firstparty"
-				for _, vv := range fpn[company_id] {
+				for _, vv := range aio.FirstpartyNetwork[v.Company_id] {
 					if jump_id != "" {
 						jump_id += ","
 					}
 					jump_id += vv.CompanyId
 				}
 				firstparty_count++
-				if firstparty_project[company_id] != nil {
-					buyer_count = firstparty_project[company_id].BuyerCount
-					project_count = firstparty_project[company_id].ProjectCount
-					expect_amount = firstparty_project[company_id].ProjectAmount
-					monitor_count = firstparty_project[company_id].MonitorCount
-					export_id = firstparty_project[company_id].ExportId
+				if aio.Firstparty[v.Company_id] != nil {
+					buyer_count = aio.Firstparty[v.Company_id].BuyerCount
+					project_count = aio.Firstparty[v.Company_id].ProjectCount
+					expect_amount = aio.Firstparty[v.Company_id].ProjectAmount
+					monitor_count = aio.Firstparty[v.Company_id].MonitorCount
+					export_id = aio.Firstparty[v.Company_id].ExportId
 				}
 			case 2:
 				itype = "供应商"
 				jump_type = "supplier"
-				jump_id = company_id
+				jump_id = v.Company_id
 				supplier_count++
-				if supplier_project[company_id] != nil {
-					buyer_count = supplier_project[company_id].BuyerCount
-					project_count = supplier_project[company_id].ProjectCount
-					expect_amount = supplier_project[company_id].ProjectAmount
-					monitor_count = supplier_project[company_id].MonitorCount
-					export_id = supplier_project[company_id].ExportId
+				if aio.Supplier[v.Company_id] != nil {
+					buyer_count = aio.Supplier[v.Company_id].BuyerCount
+					project_count = aio.Supplier[v.Company_id].ProjectCount
+					expect_amount = aio.Supplier[v.Company_id].ProjectAmount
+					monitor_count = aio.Supplier[v.Company_id].MonitorCount
+					export_id = aio.Supplier[v.Company_id].ExportId
 				}
 			case 3:
 				itype = "同甲异业渠道"
 				jump_type = "adiffb"
-				jump_id = company_id
+				jump_id = v.Company_id
 				adiffb_count++
-				if adiffb_project[company_id] != nil {
-					buyer_count = adiffb_project[company_id].BuyerCount
-					project_count = adiffb_project[company_id].ProjectCount
-					expect_amount = adiffb_project[company_id].ProjectAmount
-					monitor_count = adiffb_project[company_id].MonitorCount
-					export_id = adiffb_project[company_id].ExportId
+				if aio.Adiffb[v.Company_id] != nil {
+					buyer_count = aio.Adiffb[v.Company_id].BuyerCount
+					project_count = aio.Adiffb[v.Company_id].ProjectCount
+					expect_amount = aio.Adiffb[v.Company_id].ProjectAmount
+					monitor_count = aio.Adiffb[v.Company_id].MonitorCount
+					export_id = aio.Adiffb[v.Company_id].ExportId
 				}
 			case 4:
 				itype = "中间人"
 				jump_type = "middleman"
-				jump_id = fmt.Sprint(Int64All(v["id"]))
+				jump_id = fmt.Sprint(v.Id)
 				middleman_count++
-				buyer_count = Int64All(v["buyer_count"])
-				project_count = Int64All(v["project_count"])
-				if relate_buyer_id := ObjToString(v["relate_buyer_id"]); relate_buyer_id != "" {
-					for _, v := range strings.Split(relate_buyer_id, ",") {
+				buyer_count = v.Buyer_count
+				if v.Relate_buyer_id != "" {
+					for _, v := range strings.Split(v.Relate_buyer_id, ",") {
 						if v == "" {
 							continue
 						}
@@ -565,25 +595,26 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 						}
 					}
 				}
-				if relate_project_id := ObjToString(v["relate_project_id"]); relate_project_id != "" {
-					export_id = strings.Split(relate_project_id, ",")
+				if v.Relate_project_id != "" {
+					export_id = strings.Split(v.Relate_project_id, ",")
 					for _, v := range export_id {
-						if middleman_project[v] != nil {
-							expect_amount += middleman_project[v].ProjectAmount
+						if aio.Middleman[v] != nil {
+							project_count++
+							expect_amount += aio.Middleman[v].ProjectAmount
 						}
 					}
 				}
 			case 5:
 				itype = "招标代理机构"
 				jump_type = "agency"
-				jump_id = company_id
+				jump_id = v.Company_id
 				agency_count++
-				if agency_project[company_id] != nil {
-					buyer_count = agency_project[company_id].BuyerCount
-					project_count = agency_project[company_id].ProjectCount
-					expect_amount = agency_project[company_id].ProjectAmount
-					monitor_count = agency_project[company_id].MonitorCount
-					export_id = agency_project[company_id].ExportId
+				if aio.Agency[v.Company_id] != nil {
+					buyer_count = aio.Agency[v.Company_id].BuyerCount
+					project_count = aio.Agency[v.Company_id].ProjectCount
+					expect_amount = aio.Agency[v.Company_id].ProjectAmount
+					monitor_count = aio.Agency[v.Company_id].MonitorCount
+					export_id = aio.Agency[v.Company_id].ExportId
 				}
 			}
 			if buyer_count < in.Buyercount_start {
@@ -606,28 +637,24 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 				export_url = "/subscribepay/network/projectExport?export_id=" + encrypt.SE.EncodeStringByCheck(strings.Join(export_id, ","))
 			}
 			url := ""
-			company_name, _ := v["company_name"].(string)
-			if company_name == "" {
-				company_name = "未填写"
-			}
-			if qyxy_id := ObjToString(v["qyxy_id"]); qyxy_id != "" && (jump_type == "supplier" || jump_type == "adiffb") {
-				url = "/swordfish/page_big_pc/ent_portrait/" + encrypt.EncodeArticleId2ByCheck(qyxy_id)
-			} else if jump_type == "firstparty" && company_name != "" {
-				url = "/swordfish/page_big_pc/unit_portrayal/" + company_name
+			if v.Qyxy_id != "" && (jump_type == "supplier" || jump_type == "adiffb") {
+				url = "/swordfish/page_big_pc/ent_portrait/" + encrypt.EncodeArticleId2ByCheck(v.Qyxy_id)
+			} else if jump_type == "firstparty" && v.Company_name != "" {
+				url = "/swordfish/page_big_pc/unit_portrayal/" + v.Company_name
 			}
 			list = append(list, &map[string]interface{}{
-				"company_id":    company_id,
-				"company_name":  company_name,
+				"company_id":    v.Company_id,
+				"company_name":  v.Company_name,
 				"type":          itype,
 				"jump_type":     jump_type,
 				"jump_id":       jump_id,
-				"person":        v["person"],
-				"phone":         v["phone"],
+				"person":        v.Person,
+				"phone":         v.Phone,
 				"buyer_count":   buyer_count,
 				"monitor_count": 0,
 				"expect_amount": RetainDecimal(expect_amount/10000, 2),
 				"project_count": project_count,
-				"create_time":   v["create_time"],
+				"create_time":   v.Create_time,
 				"export_url":    export_url,
 				"url":           url,
 			})
@@ -649,29 +676,22 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 	if in.Order_amount != 0 {
 		sort.Sort(csList)
 	}
-	length := int64(len(csList.List))
-	if in.Page_size <= 0 {
-		in.Page_size = 10
-	}
-	total_page := int64(math.Ceil(float64(length) / float64(in.Page_size)))
 	finalList := []*map[string]interface{}{}
-	if length > 0 {
-		if in.Current_page <= 0 {
-			in.Current_page = 1
-		}
-		if in.Current_page > total_page {
-			in.Current_page = total_page
-		}
-		start := (in.Current_page - 1) * in.Page_size
-		end := start + in.Page_size
-		if end > length {
-			end = length
+	if !dbPaging {
+		count = int64(len(csList.List))
+		if count > 0 && start < count {
+			if end > count {
+				end = count
+			}
+			finalList = csList.List[start:end]
 		}
-		finalList = csList.List[start:end]
+	} else {
+		finalList = csList.List
 	}
+	total_page := int64(math.Ceil(float64(count) / float64(in.Page_size)))
 	return &types.Reply{
 		Data: map[string]interface{}{
-			"count":            length,
+			"count":            count,
 			"total_page":       total_page,
 			"firstparty_count": firstparty_count,
 			"supplier_count":   supplier_count,
@@ -710,6 +730,9 @@ func (n *network) FirstpartyNetwork(name string, values []string) map[string][]*
 			logx.Error(err)
 			continue
 		}
+		if company_id == "" || company_name == "" {
+			continue
+		}
 		result[a_id] = append(result[a_id], &firstpartyNetwork{
 			CompanyId:   company_id,
 			CompanyName: company_name,
@@ -720,7 +743,7 @@ func (n *network) FirstpartyNetwork(name string, values []string) map[string][]*
 }
 
 //
-func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entMonitor map[string]bool, matchme int64, probusfors []string) map[string]*projectInfo {
+func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
 	values := []string{}
 	vm := map[string]*projectInfo{}
 	for _, v := range fpn {
@@ -729,9 +752,13 @@ func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entM
 			values = append(values, vv.CompanyId)
 		}
 	}
+	result := map[string]*projectInfo{}
+	if len(values) == 0 {
+		return result
+	}
 	wh, args := NetworkCom.WhArgs(values)
 	q := `select buyer_id,count(project_id) AS project_count,sum(project_money) AS project_amount,groupUniqArray(project_id) from information.transaction_info where buyer_id in (` + wh + `)`
-	if matchme == 1 {
+	if len(probusfors) > 0 {
 		newWh, newArgs := NetworkCom.WhArgs(probusfors)
 		q += ` and hasAny(property_form,[` + newWh + `])`
 		args = append(args, newArgs...)
@@ -765,7 +792,6 @@ func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entM
 	if err := rows.Err(); err != nil {
 		logx.Error(err)
 	}
-	result := map[string]*projectInfo{}
 	for k, v := range fpn {
 		if result[k] == nil {
 			result[k] = &projectInfo{}
@@ -786,120 +812,117 @@ func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entM
 }
 
 //
-func (n *network) Introduce_Supplier(values []string, entMonitor map[string]bool, matchme int64, probusfors []string) map[string]*projectInfo {
-	vm := map[string]*projectInfo{}
-	for _, v := range values {
-		vm[v] = &projectInfo{}
+func (n *network) Introduce_Supplier(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
+	if len(values) == 0 {
+		return map[string]*projectInfo{}
 	}
 	wh, args := NetworkCom.WhArgs(values)
-	q := `select a.winner_id,count(DISTINCT b.buyer_id) AS buyer_count,count(DISTINCT b.project_id) AS project_count,sum(b.project_money) AS project_amount,groupUniqArray(b.buyer),groupUniqArray(b.project_id) from information.transaction_info a 
-		inner join information.transaction_info b on (hasAny(a.winner_id,[` + wh + `]) and a.buyer_id<>'' and a.buyer_id=b.buyer_id`
-	if matchme == 1 {
-		newWh, newArgs := NetworkCom.WhArgs(probusfors)
-		q += ` and hasAny(b.property_form,[` + newWh + `])`
-		args = append(args, newArgs...)
-	}
-	q += `) group by a.winner_id`
+	vbs := map[string][]*idName{}
+	repeat := map[string]bool{}
+	whRepeat := map[string]map[string]bool{}
+	buyers := []string{}
+	q := `select winner_id,buyer_id,buyer from information.transaction_info where hasAny(winner_id,[` + wh + `])`
 	rows, err := ClickhouseConn.Query(context.Background(), q, args...)
 	if err != nil {
 		logx.Error(err)
-		return nil
-	}
-	for rows.Next() {
-		var (
-			winner_id      []string
-			buyer_count    uint64
-			project_count  uint64
-			project_amount decimal.Decimal
-			buyers         []string
-			project_id     []string
-		)
-		if err := rows.Scan(&winner_id, &buyer_count, &project_count, &project_amount, &buyers, &project_id); err != nil {
-			logx.Error(err)
-			continue
-		}
-		for _, v := range winner_id {
-			if vm[v] == nil {
+	} 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
 			}
-			vm[v].BuyerCount += int64(buyer_count)
-			vm[v].ProjectCount += int64(project_count)
-			pf, _ := project_amount.Float64()
-			vm[v].ProjectAmount += pf
-			vm[v].ExportId = project_id
-			for _, v := range buyers {
-				if entMonitor[v] {
-					vm[v].MonitorCount++
+			if buyer_id == "" || buyer == "" {
+				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,
+				})
 			}
 		}
+		rows.Close()
+		if err := rows.Err(); err != nil {
+			logx.Error(err)
+		}
 	}
-	rows.Close()
-	if err := rows.Err(); err != nil {
-		logx.Error(err)
-	}
-	return vm
+	return n.MakeProjectInfo(buyers, vbs, probusfors, entMonitor)
 }
 
 //
-func (n *network) Introduce_Agency(values []string, entMonitor map[string]bool, matchme int64, probusfors []string) map[string]*projectInfo {
-	vm := map[string]*projectInfo{}
-	for _, v := range values {
-		vm[v] = &projectInfo{}
+func (n *network) Introduce_Agency(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
+	if len(values) == 0 {
+		return map[string]*projectInfo{}
 	}
 	wh, args := NetworkCom.WhArgs(values)
-	q := `select a.agency_id,count(DISTINCT b.buyer_id) AS buyer_count,count(DISTINCT b.project_id) AS project_count,sum(b.project_money) AS project_amount,groupUniqArray(b.buyer),groupUniqArray(b.project_id) from information.transaction_info a 
-		inner join information.transaction_info b on (a.agency_id in (` + wh + `) and a.buyer_id<>'' and a.buyer_id=b.buyer_id`
-	if matchme == 1 {
-		newWh, newArgs := NetworkCom.WhArgs(probusfors)
-		q += ` and hasAny(b.property_form,[` + newWh + `])`
-		args = append(args, newArgs...)
-	}
-	q += `) group by a.agency_id`
+	q := `select DISTINCT agency_id,buyer_id,buyer from information.transaction_info where agency_id in (` + wh + `)`
 	rows, err := ClickhouseConn.Query(context.Background(), q, args...)
 	if err != nil {
 		logx.Error(err)
 		return nil
 	}
+	vbs := map[string][]*idName{}
+	buyers := []string{}
+	repeat := map[string]bool{}
 	for rows.Next() {
 		var (
-			agency_id      string
-			buyer_count    uint64
-			project_count  uint64
-			project_amount decimal.Decimal
-			buyers         []string
-			project_id     []string
+			agency_id string
+			buyer_id  string
+			buyer     string
 		)
-		if err := rows.Scan(&agency_id, &buyer_count, &project_count, &project_amount, &buyers, &project_id); err != nil {
+		if err := rows.Scan(&agency_id, &buyer_id, &buyer); err != nil {
 			logx.Error(err)
 			continue
 		}
-		if vm[agency_id] == nil {
+		if buyer_id == "" || buyer == "" {
 			continue
 		}
-		vm[agency_id].BuyerCount += int64(buyer_count)
-		vm[agency_id].ProjectCount += int64(project_count)
-		pf, _ := project_amount.Float64()
-		vm[agency_id].ProjectAmount += pf
-		vm[agency_id].ExportId = project_id
-		for _, v := range buyers {
-			if entMonitor[v] {
-				vm[agency_id].MonitorCount++
-			}
+		vbs[agency_id] = append(vbs[agency_id], &idName{
+			Id:   buyer_id,
+			Name: buyer,
+		})
+		if !repeat[buyer_id] {
+			repeat[buyer_id] = true
+			buyers = append(buyers, buyer_id)
 		}
 	}
 	rows.Close()
 	if err := rows.Err(); err != nil {
 		logx.Error(err)
 	}
-	return vm
+	return n.MakeProjectInfo(buyers, vbs, probusfors, entMonitor)
 }
 
 //
-func (n *network) Introduce_Middleman(values []string, entMonitor map[string]bool, matchme int64, probusfors []string) map[string]*projectInfo {
-	vm := map[string]*projectInfo{}
-	wh, newArgs := NetworkCom.WhArgs(values)
-	rows, err := ClickhouseConn.Query(context.Background(), `select project_id,project_money from information.transaction_info where project_id in (`+wh+`)`, newArgs...)
+func (n *network) Introduce_Middleman(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
+	result := map[string]*projectInfo{}
+	if len(values) == 0 {
+		return result
+	}
+	wh, args := NetworkCom.WhArgs(values)
+	q := `select DISTINCT project_id,project_money from information.transaction_info where project_id in (` + wh + `)`
+	if len(probusfors) > 0 {
+		newWh, newArgs := NetworkCom.WhArgs(probusfors)
+		q += ` and hasAny(property_form,[` + newWh + `])`
+		args = append(args, newArgs...)
+	}
+	rows, err := ClickhouseConn.Query(context.Background(), q, args...)
 	if err != nil {
 		logx.Error(err)
 		return nil
@@ -914,7 +937,7 @@ func (n *network) Introduce_Middleman(values []string, entMonitor map[string]boo
 			continue
 		}
 		pf, _ := project_money.Float64()
-		vm[project_id] = &projectInfo{
+		result[project_id] = &projectInfo{
 			ProjectAmount: pf,
 		}
 	}
@@ -922,7 +945,7 @@ func (n *network) Introduce_Middleman(values []string, entMonitor map[string]boo
 	if err := rows.Err(); err != nil {
 		logx.Error(err)
 	}
-	return vm
+	return result
 }
 
 //
@@ -988,3 +1011,132 @@ func (n *network) GetQyxyId(ids []string) map[string]string {
 	}
 	return m
 }
+
+//
+func (n *network) BuyerProjectInfo(ids []string, probusfors []string) map[string]*projectInfo {
+	vm := map[string]*projectInfo{}
+	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 {
+		newWh, newArgs := NetworkCom.WhArgs(probusfors)
+		q += ` and hasAny(property_form,[` + newWh + `])`
+		args = append(args, newArgs...)
+	}
+	q += ` group by buyer_id`
+	rows, err := ClickhouseConn.Query(context.Background(), q, args...)
+	if err != nil {
+		logx.Error(err)
+		return nil
+	}
+	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()
+		vm[buyer_id] = &projectInfo{
+			ProjectCount:  int64(project_count),
+			ExportId:      project_id,
+			ProjectAmount: pf,
+		}
+	}
+	rows.Close()
+	if err := rows.Err(); err != nil {
+		logx.Error(err)
+	}
+	return vm
+}
+
+//
+func (n *network) MakeProjectInfo(buyers []string, vbs map[string][]*idName, probusfors []string, entMonitor map[string]bool) map[string]*projectInfo {
+	pis := n.BuyerProjectInfo(buyers, probusfors)
+	vm := map[string]*projectInfo{}
+	for k, v := range vbs {
+		pi := &projectInfo{
+			BuyerCount: int64(len(v)),
+		}
+		re := map[string]bool{}
+		for _, vv := range v {
+			if pis[vv.Id] != nil {
+				pi.ProjectCount += pis[vv.Id].ProjectCount
+				pi.ProjectAmount += pis[vv.Id].ProjectAmount
+				for _, vvv := range pis[vv.Id].ExportId {
+					if re[vvv] {
+						continue
+					}
+					pi.ExportId = append(pi.ExportId, vvv)
+					re[vvv] = true
+				}
+			}
+			if entMonitor[vv.Name] {
+				pi.MonitorCount++
+			}
+		}
+		vm[k] = pi
+	}
+	return vm
+}
+
+//
+func (n *network) AllIntroduceOwner(sqlAppend1, sqlAppend2 string, args []interface{}, isTjProject bool, probusfors []string, entMonitor map[string]bool) *introduceOwnerProject {
+	q := `select a.id,a.company_id,a.company_name,a.qyxy_id,a.itype,a.contact_person as person,a.contact_phone as phone,count(DISTINCT if(b.itype=1,b.relate_id,null)) as buyer_count,count(DISTINCT if(b.itype=2,b.relate_id,null)) as project_count,GROUP_CONCAT(IF(b.itype=1,b.relate_id,NULL)) AS relate_buyer_id,GROUP_CONCAT(IF(b.itype=2,b.relate_id,NULL)) AS relate_project_id,a.create_time from crm.connection a 
+		left join crm.connection_introduce b on (a.position_id=? and b.position_id=? and a.id=b.connection_id) where a.position_id=?` + sqlAppend1 + ` GROUP BY a.id order by a.create_time desc` + sqlAppend2
+	listTemp := CrmMysql.SelectBySql(q, args...)
+	firstparty_array, supplier_array, adiffb_array, agency_array, middleman_project_array := []string{}, []string{}, []string{}, []string{}, []string{}
+	myNetworks := []*myNetwork{}
+	for _, v := range *listTemp {
+		myNetwork := &myNetwork{
+			Id:                Int64All(v["id"]),
+			Company_id:        ObjToString(v["company_id"]),
+			Company_name:      ObjToString(v["company_name"]),
+			Qyxy_id:           ObjToString(v["qyxy_id"]),
+			Itype:             Int64All(v["itype"]),
+			Person:            ObjToString(v["person"]),
+			Phone:             ObjToString(v["phone"]),
+			Buyer_count:       Int64All(v["buyer_count"]),
+			Project_count:     Int64All(v["project_count"]),
+			Relate_buyer_id:   ObjToString(v["relate_buyer_id"]),
+			Relate_project_id: ObjToString(v["relate_project_id"]),
+			Create_time:       ObjToString(v["create_time"]),
+		}
+		switch myNetwork.Itype {
+		case 1:
+			firstparty_array = append(firstparty_array, myNetwork.Company_id)
+		case 2:
+			supplier_array = append(supplier_array, myNetwork.Company_id)
+		case 3:
+			adiffb_array = append(adiffb_array, myNetwork.Company_id)
+		case 4:
+			if myNetwork.Relate_project_id != "" {
+				middleman_project_array = append(middleman_project_array, strings.Split(myNetwork.Relate_project_id, ",")...)
+			}
+		case 5:
+			agency_array = append(agency_array, myNetwork.Company_id)
+		}
+		myNetworks = append(myNetworks, myNetwork)
+	}
+	iop := &introduceOwnerProject{
+		Networks:          myNetworks,
+		FirstpartyNetwork: map[string][]*firstpartyNetwork{},
+		Firstparty:        map[string]*projectInfo{},
+		Supplier:          map[string]*projectInfo{},
+		Adiffb:            map[string]*projectInfo{},
+		Agency:            map[string]*projectInfo{},
+		Middleman:         map[string]*projectInfo{},
+	}
+	if isTjProject {
+		iop.FirstpartyNetwork = n.FirstpartyNetwork("", firstparty_array)
+		iop.Firstparty = n.Introduce_Firstparty(iop.FirstpartyNetwork, entMonitor, probusfors)
+		iop.Supplier = n.Introduce_Supplier(supplier_array, entMonitor, probusfors)
+		iop.Adiffb = n.Introduce_Supplier(adiffb_array, entMonitor, probusfors)
+		iop.Agency = n.Introduce_Agency(agency_array, entMonitor, probusfors)
+		iop.Middleman = n.Introduce_Middleman(middleman_project_array, entMonitor, probusfors)
+	}
+	return iop
+}

+ 12 - 8
api/internal/service/network_test.go

@@ -16,7 +16,7 @@ import (
 
 func initDb() {
 	CrmMysql = &mysql.Mysql{
-		Address:      "192.168.3.14:4000",
+		Address:      "192.168.3.217:4000",
 		UserName:     "root",
 		PassWord:     "=PDT49#80Z!RVv52_z",
 		DBName:       "crm",
@@ -33,6 +33,7 @@ func initDb() {
 		MaxOpenConns: 2,
 	})
 	es.NewEs("v7", "http://192.168.3.149:9200", 5, "", "")
+	log.Println("ccccccc")
 	Mgo = MongodbSim{
 		MongodbAddr: "192.168.3.206:27080",
 		Size:        2,
@@ -105,17 +106,19 @@ func TestNetWorkList(t *testing.T) {
 	initDb()
 	//类型;firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
 	res := Network.List(&types.NetWorkListReq{
-		//PositionId: 1205591997,
+		PositionId:   1205591997,
+		Current_page: 1,
+		Page_size:    10,
 		//PositionId: 935,
-		PositionId: 1205591998,
-		// Order_amount:       1,
+		//PositionId: 1205591998,
+		Order_amount: -1,
 		// Monitorcount_start: 1,
 		// Monitorcount_end:   1,
 		//Monitor:      0,
 		//Project_matchme: 1,
 		//Starttime: "2024-04-23",
 		//Endtime:   "2024-04-23",
-		//Type: "agency",
+		Type: "middleman",
 		//Name: "三亚市",
 	})
 	for k, v := range res.Data.(map[string]interface{}) {
@@ -132,9 +135,10 @@ func TestAllProject(t *testing.T) {
 	initDb()
 	res := Network.AllProject(&types.AllprojectReq{
 		EntAccountId: 64,
-		PositionId:   935,
-		//Id:           "wcj_11111111a",
-		//Type:         1,
+		//PositionId:   935,
+		PositionId: 1205591997,
+		//Id:         "wcj_11111111a",
+		//Type:       "firstparty",
 	})
 	b, _ := json.Marshal(res.Data)
 	log.Println(string(b))

+ 50 - 39
api/internal/service/plistService.go

@@ -2,6 +2,7 @@ package service
 
 import (
 	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/encrypt"
 	"app.yhyue.com/moapp/jypkg/ent/util"
 	T "bp.jydev.jianyu360.cn/CRM/application/api/common"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
@@ -25,42 +26,43 @@ type ProjectData struct {
 }
 
 type ProjectEntry struct {
-	ProjectId    string          `ch:"project_id"`
-	ProjectName  string          `ch:"project_name"`
-	BusinessType string          `ch:"business_type"`
-	Buyer        string          `ch:"buyer"`
-	BuyerId      string          `ch:"buyer_id"`
-	Area         string          `ch:"area"`
-	City         string          `ch:"city"`
-	District     string          `ch:"district"`
-	ZbTime       int64           `ch:"zbtime"`
-	EndTime      int64           `ch:"endtime"`
-	ProjectMoney decimal.Decimal `ch:"project_money"`
-	InfoId       string          `ch:"info_id"`
-	IsHandle     int             `json:"IsHandle"`
-	IsIgnore     int             `json:"IsIgnore"`
-	IsCreate     int             `json:"IsCreate"`
-	MyConn       bool            `json:"MyConn"`
-	ConnType     int             `json:"ConnType"`
-	HighSuccess  bool            `json:"HighSuccess"`
-	BId          string          `json:"BId"`
-	BName        string          `json:"BName"`
-	RelationShip string          `json:"RelationShip"`
-	SourceType   string          `json:"SourceType"` // firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
-	Person       string          `json:"Person"`
-	Num          string          `json:"Num"`
-	FocusId      string          `json:"FocusId"`
+	ProjectId     string          `ch:"project_id"`
+	ProjectName   string          `ch:"project_name"`
+	BusinessType  string          `ch:"business_type"`
+	Buyer         string          `ch:"buyer"`
+	BuyerId       string          `ch:"buyer_id"`
+	Area          string          `ch:"area"`
+	City          string          `ch:"city"`
+	District      string          `ch:"district"`
+	ZbTime        int64           `ch:"zbtime"`
+	EndTime       int64           `ch:"endtime"`
+	ProjectMoney  decimal.Decimal `ch:"project_money"`
+	InfoId        string          `ch:"info_id"`
+	InformationId string          `ch:"information_id"`
+	InfoIds       string          `ch:"info_ids"`
+	Href          string          `json:"Href"`
+	IsHandle      int             `json:"IsHandle"`
+	IsIgnore      int             `json:"IsIgnore"`
+	IsCreate      int             `json:"IsCreate"`
+	MyConn        bool            `json:"MyConn"`
+	ConnType      int             `json:"ConnType"`
+	HighSuccess   bool            `json:"HighSuccess"`
+	BId           string          `json:"BId"`
+	BName         string          `json:"BName"`
+	RelationShip  string          `json:"RelationShip"`
+	SourceType    string          `json:"SourceType"` // firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
+	Person        string          `json:"Person"`
+	Num           int             `json:"Num"`
+	FocusId       string          `json:"FocusId"`
 }
 
 func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasNextPage bool, total int) {
-
 	buyerM := BuyerList(req.PartyA, req.Supplier, req.Heterotophy, req.Intermediary, req.Agency, req.PositionId)
 	mmp := MonitorStatus(req.UserId) // 项目监控
-	buyerArr := make([]string, len(*buyerM))
+	var buyerArr []string
 	for b := range *buyerM {
 		buyerArr = append(buyerArr, b)
 	}
-
 	preSales := preSalesStatus(req.PositionId)
 	isSqlPage := false
 	if req.SaleStatus == "0" {
@@ -76,7 +78,7 @@ func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasN
 		project := ProjectEntry{}
 		_ = rows.ScanStruct(&project)
 		//project.ProjectId = encrypt.CommonEncodeArticle("content", project.ProjectId)
-		project.ProjectId = util.EncodeId(project.ProjectId)
+		//project.ProjectId = util.EncodeId(project.ProjectId)
 		resultList = append(resultList, &project)
 	}
 
@@ -123,7 +125,11 @@ func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr []string) (cou
 	querys := []string{}
 	// 左侧选中的业主id
 	if len(buyerArr) > 0 {
-		querys = append(querys, fmt.Sprintf(" a.buyer_id in (%s) ", strings.Join(buyerArr, ",")))
+		var arr []string
+		for _, s := range buyerArr {
+			arr = append(arr, fmt.Sprintf("'%s'", s))
+		}
+		querys = append(querys, fmt.Sprintf(" a.buyer_id in (%s) ", strings.Join(arr, ",")))
 	}
 	//	商机类型
 	if req.BusinessType != "" && req.BusinessType != "全部" {
@@ -172,9 +178,9 @@ func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr []string) (cou
 	if req.SubClass != "" {
 		arr := []string{}
 		for _, v := range strings.Split(req.SubClass, ",") {
-			arr = append(arr, fmt.Sprintf(`"物业_%s"`, v))
+			arr = append(arr, fmt.Sprintf("has(a.subclass, '%s')", v))
 		}
-		querys = append(querys, fmt.Sprintf(" a.subclass in (%s) ", strings.Join(regionArr, ",")))
+		querys = append(querys, arr...)
 	}
 	// 项目金额
 	if req.Amount != "" && strings.Contains(req.Amount, "-") {
@@ -193,11 +199,11 @@ func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr []string) (cou
 	if req.PropertyForm != "" {
 		arr := []string{}
 		for _, v := range strings.Split(req.PropertyForm, ",") {
-			arr = append(arr, fmt.Sprintf(`"%s"`, v))
+			arr = append(arr, fmt.Sprintf("has(a.property_form, '%s')", v))
 		}
-		querys = append(querys, fmt.Sprintf(" a.property_form in (%s) ", strings.Join(arr, ",")))
+		querys = append(querys, arr...)
 	}
-	findSql = "select a.project_id, a.project_name, a.business_type, a.buyer, a.buyer_id, a.area, a.city, a.district, a.zbtime, a.endtime, a.project_money, a.info_id "
+	findSql = "select a.project_id, a.project_name, a.business_type, a.buyer, a.buyer_id, a.area, a.city, a.district, a.zbtime, a.endtime, a.project_money, a.info_id, a.information_id, a.info_ids "
 	if len(querys) > 0 {
 		countSql = fmt.Sprintf("select count(1) from %s a where %s ", "information.transaction_info", strings.Join(querys, " and "))
 		findSql = fmt.Sprintf("%s from %s  a  where  %s order by zbtime", findSql, "information.transaction_info", strings.Join(querys, " and "))
@@ -294,6 +300,11 @@ func moreInfo(req *types.ProjectListReq, list []*ProjectEntry) (result []*Projec
 		}
 	}
 	for _, m := range list {
+		// 补充跳转链接
+		if m.BusinessType == "采购意向" || m.BusinessType == "招标项目" {
+			m.Href = fmt.Sprintf("/article/content/%s.html", encrypt.CommonEncodeArticle("content", m.ProjectId))
+		}
+		m.ProjectId = util.EncodeId(m.ProjectId)
 		// 人脉、人脉所在单位项目 conn_type: 1 人脉可转介绍项目; conn_type: 2 人脉所在单位项目
 		if connMap[m.BuyerId] == 1 {
 			m.MyConn = true // 我的人脉
@@ -328,13 +339,13 @@ func moreInfo(req *types.ProjectListReq, list []*ProjectEntry) (result []*Projec
 		for _, m := range list {
 			if m.MyConn == false {
 				for _, m1 := range companyList {
-					if m.BuyerId == common.ObjToString(m1["b_id"]) {
+					if m.BuyerId == common.ObjToString(m1["a_id"]) {
 						m.BId = common.ObjToString(m1["b_id"])
 						m.BName = common.ObjToString(m1["b_name"])
 						m.RelationShip = common.ObjToString(m1["relationship"])
 						m.SourceType = common.ObjToString(m1["sourceType"])
 						m.Person = common.ObjToString(m1["person"])
-						m.Num = common.ObjToString(m1["count"])
+						m.Num = common.IntAll(m1["count"])
 						break
 					}
 				}
@@ -346,13 +357,13 @@ func moreInfo(req *types.ProjectListReq, list []*ProjectEntry) (result []*Projec
 			for _, m := range list {
 				if m.MyConn == false {
 					for _, m1 := range companyList {
-						if m.BuyerId == common.ObjToString(m1["b_id"]) {
+						if m.BuyerId == common.ObjToString(m1["a_id"]) {
 							m.BId = common.ObjToString(m1["b_id"])
 							m.BName = common.ObjToString(m1["b_name"])
 							m.RelationShip = common.ObjToString(m1["relationship"])
 							m.SourceType = common.ObjToString(m1["sourceType"])
 							m.Person = common.ObjToString(m1["person"])
-							m.Num = common.ObjToString(m1["count"])
+							m.Num = common.IntAll(m1["count"])
 							break
 						}
 					}