Browse Source

feat:xiugai

wangchuanjin 9 months ago
parent
commit
ba70de034d
1 changed files with 60 additions and 30 deletions
  1. 60 30
      api/internal/service/network.go

+ 60 - 30
api/internal/service/network.go

@@ -340,7 +340,7 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 		if in.Type == "firstparty" {
 		if in.Type == "firstparty" {
 			fpn := n.FirstpartyNetwork(in.Name, []string{in.Id})
 			fpn := n.FirstpartyNetwork(in.Name, []string{in.Id})
 			if fpn[in.Id] != nil {
 			if fpn[in.Id] != nil {
-				firstparty, firstpartyPio = n.Introduce_Firstparty(fpn, businessType)
+				firstparty, firstpartyPio = n.Introduce_Firstparty(fpn, businessType, false)
 				nameIndex := map[string]int{}
 				nameIndex := map[string]int{}
 				for _, v := range fpn[in.Id] {
 				for _, v := range fpn[in.Id] {
 					if _, ok := nameIndex[v.Name]; !ok {
 					if _, ok := nameIndex[v.Name]; !ok {
@@ -372,10 +372,10 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 		}
 		}
 		aio := &introduceOwnerProject{}
 		aio := &introduceOwnerProject{}
 		key := fmt.Sprintf(NetworkManageAllProjectKey, in.PositionId)
 		key := fmt.Sprintf(NetworkManageAllProjectKey, in.PositionId)
-		if rbt, rerr := redis.GetNewBytes("newother", key); rerr == nil && rbt != nil {
+		if rbt, rerr := redis.GetNewBytes("newother", key); false && rerr == nil && rbt != nil {
 			json.Unmarshal(*rbt, &aio)
 			json.Unmarshal(*rbt, &aio)
 		} else {
 		} else {
-			aio = n.AllIntroduceOwner(in.PositionId, sqlAppend1, "", args, true, businessType)
+			aio = n.AllIntroduceOwner(in.PositionId, sqlAppend1, "", args, true, businessType, false)
 			redis.Put("newother", key, aio, NetworkCom.CacheTimeout())
 			redis.Put("newother", key, aio, NetworkCom.CacheTimeout())
 		}
 		}
 		firstparty = aio.Firstparty
 		firstparty = aio.Firstparty
@@ -768,7 +768,7 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 	if aioErr == nil && aioByte != nil {
 	if aioErr == nil && aioByte != nil {
 		json.Unmarshal(*aioByte, &aio)
 		json.Unmarshal(*aioByte, &aio)
 	} else {
 	} else {
-		aio = n.AllIntroduceOwner(in.PositionId, sqlAppend1, sqlAppend2, args, isTjProject, businessType)
+		aio = n.AllIntroduceOwner(in.PositionId, sqlAppend1, sqlAppend2, args, isTjProject, businessType, true)
 		redis.Put("newother", redisKey, aio, timeOut)
 		redis.Put("newother", redisKey, aio, timeOut)
 	}
 	}
 	entMonitor := NetworkCom.EntMonitor(in.UserId)
 	entMonitor := NetworkCom.EntMonitor(in.UserId)
@@ -1026,7 +1026,7 @@ func (n *network) FirstpartyNetwork(name string, values []string) map[string][]*
 	return result
 	return result
 }
 }
 
 
-func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, businessType []string) (map[string]*projectInfo, map[string]*projectInfo) {
+func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, businessType []string, projectIdFlag bool) (map[string]*projectInfo, map[string]*projectInfo) {
 	values := []string{}
 	values := []string{}
 	vm := map[string]*projectInfo{}
 	vm := map[string]*projectInfo{}
 	for _, v := range fpn {
 	for _, v := range fpn {
@@ -1040,7 +1040,11 @@ func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, busi
 		return result, vm
 		return result, vm
 	}
 	}
 	wh, args := WhArgs(values)
 	wh, args := 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_all prewhere buyer_id in (` + wh + `) and zbtime>? and project_bidstatus>1`
+	q := `select buyer_id,count(project_id) AS project_count,sum(project_money) AS project_amount`
+	if projectIdFlag {
+		q += `,groupUniqArray(project_id)`
+	}
+	q += ` from information.transaction_info_all prewhere buyer_id in (` + wh + `) and zbtime>? and project_bidstatus>1`
 	args = append(args, NetworkCom.ProjectYearLimit())
 	args = append(args, NetworkCom.ProjectYearLimit())
 	if len(businessType) > 0 {
 	if len(businessType) > 0 {
 		newWh, newArgs := WhArgs(businessType)
 		newWh, newArgs := WhArgs(businessType)
@@ -1060,7 +1064,13 @@ func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, busi
 			project_amount decimal.Decimal
 			project_amount decimal.Decimal
 			project_id     []string
 			project_id     []string
 		)
 		)
-		if err := rows.Scan(&buyer_id, &project_count, &project_amount, &project_id); err != nil {
+		var err error
+		if projectIdFlag {
+			err = rows.Scan(&buyer_id, &project_count, &project_amount, &project_id)
+		} else {
+			err = rows.Scan(&buyer_id, &project_count, &project_amount)
+		}
+		if err != nil {
 			logx.Error(err)
 			logx.Error(err)
 			continue
 			continue
 		}
 		}
@@ -1093,7 +1103,7 @@ func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, busi
 	return result, vm
 	return result, vm
 }
 }
 
 
-func (n *network) Introduce_Supplier(values []string, businessType []string) map[string]*projectInfo {
+func (n *network) Introduce_Supplier(values []string, businessType []string, projectIdFlag bool) map[string]*projectInfo {
 	if len(values) == 0 {
 	if len(values) == 0 {
 		return map[string]*projectInfo{}
 		return map[string]*projectInfo{}
 	}
 	}
@@ -1143,10 +1153,10 @@ func (n *network) Introduce_Supplier(values []string, businessType []string) map
 	if err := rows.Err(); err != nil {
 	if err := rows.Err(); err != nil {
 		logx.Error(err)
 		logx.Error(err)
 	}
 	}
-	return n.MakeProjectInfo(nil, values, vbs, businessType)
+	return n.MakeProjectInfo(nil, values, vbs, businessType, projectIdFlag)
 }
 }
 
 
-func (n *network) Introduce_Agency(values []string, businessType []string) map[string]*projectInfo {
+func (n *network) Introduce_Agency(values []string, businessType []string, projectIdFlag bool) map[string]*projectInfo {
 	if len(values) == 0 {
 	if len(values) == 0 {
 		return map[string]*projectInfo{}
 		return map[string]*projectInfo{}
 	}
 	}
@@ -1186,11 +1196,11 @@ func (n *network) Introduce_Agency(values []string, businessType []string) map[s
 	if err := rows.Err(); err != nil {
 	if err := rows.Err(); err != nil {
 		logx.Error(err)
 		logx.Error(err)
 	}
 	}
-	return n.MakeProjectInfo(values, nil, vbs, businessType)
+	return n.MakeProjectInfo(values, nil, vbs, businessType, projectIdFlag)
 }
 }
 
 
-func (n *network) Introduce_Middleman_Buyer(values []string, businessType []string) map[string]*projectInfo {
-	return n.BuyerProjectInfo(values, businessType)
+func (n *network) Introduce_Middleman_Buyer(values []string, businessType []string, projectIdFlag bool) map[string]*projectInfo {
+	return n.BuyerProjectInfo(values, businessType, projectIdFlag)
 }
 }
 
 
 func (n *network) Introduce_Middleman_Project(values []string, businessType []string) map[string]*projectInfo {
 func (n *network) Introduce_Middleman_Project(values []string, businessType []string) map[string]*projectInfo {
@@ -1294,7 +1304,7 @@ func (n *network) GetQyxyId(ids []string) map[string]string {
 	}
 	}
 	return m
 	return m
 }
 }
-func (n *network) BuyerProjectInfo(ids []string, businessType []string) map[string]*projectInfo {
+func (n *network) BuyerProjectInfo(ids []string, businessType []string, projectIdFlag bool) map[string]*projectInfo {
 	vm := map[string]*projectInfo{}
 	vm := map[string]*projectInfo{}
 	m := map[string]bool{}
 	m := map[string]bool{}
 	newIds := []string{}
 	newIds := []string{}
@@ -1305,21 +1315,25 @@ func (n *network) BuyerProjectInfo(ids []string, businessType []string) map[stri
 		m[v] = true
 		m[v] = true
 		newIds = append(newIds, v)
 		newIds = append(newIds, v)
 		if len(newIds) == C.SelectBatchSize {
 		if len(newIds) == C.SelectBatchSize {
-			n.BuyerProjectInfoBatch(newIds, businessType, vm)
+			n.BuyerProjectInfoBatch(newIds, businessType, vm, projectIdFlag)
 			newIds = []string{}
 			newIds = []string{}
 		}
 		}
 	}
 	}
 	if len(newIds) > 0 {
 	if len(newIds) > 0 {
-		n.BuyerProjectInfoBatch(newIds, businessType, vm)
+		n.BuyerProjectInfoBatch(newIds, businessType, vm, projectIdFlag)
 	}
 	}
 	return vm
 	return vm
 }
 }
-func (n *network) BuyerProjectInfoBatch(ids []string, businessType []string, vm map[string]*projectInfo) {
+func (n *network) BuyerProjectInfoBatch(ids []string, businessType []string, vm map[string]*projectInfo, projectIdFlag bool) {
 	if len(ids) == 0 {
 	if len(ids) == 0 {
 		return
 		return
 	}
 	}
 	wh, args := WhArgs(ids)
 	wh, args := WhArgs(ids)
-	q := `select buyer_id,uniqCombined(project_id) AS project_count,sum(project_money) AS project_amount,groupUniqArray(project_id) from information.transaction_info_all prewhere buyer_id in (` + wh + `) and zbtime>? and project_bidstatus>1`
+	q := `select buyer_id,uniqCombined(project_id) AS project_count,sum(project_money) AS project_amount`
+	if projectIdFlag {
+		q += `,groupUniqArray(project_id)`
+	}
+	q += ` from information.transaction_info_all prewhere buyer_id in (` + wh + `) and zbtime>? and project_bidstatus>1`
 	args = append(args, NetworkCom.ProjectYearLimit())
 	args = append(args, NetworkCom.ProjectYearLimit())
 	if len(businessType) > 0 {
 	if len(businessType) > 0 {
 		newWh, newArgs := WhArgs(businessType)
 		newWh, newArgs := WhArgs(businessType)
@@ -1339,7 +1353,13 @@ func (n *network) BuyerProjectInfoBatch(ids []string, businessType []string, vm
 			project_amount decimal.Decimal
 			project_amount decimal.Decimal
 			project_id     []string
 			project_id     []string
 		)
 		)
-		if err := rows.Scan(&buyer_id, &project_count, &project_amount, &project_id); err != nil {
+		var err error
+		if projectIdFlag {
+			err = rows.Scan(&buyer_id, &project_count, &project_amount, &project_id)
+		} else {
+			err = rows.Scan(&buyer_id, &project_count, &project_amount)
+		}
+		if err != nil {
 			logx.Error(err)
 			logx.Error(err)
 			continue
 			continue
 		}
 		}
@@ -1363,14 +1383,18 @@ func (n *network) BuyerProjectInfoBatch(ids []string, businessType []string, vm
 	return
 	return
 }
 }
 
 
-func (n *network) TjProject(agencyIds, winnerIds []string, vbs map[string][]*idName, businessType []string) map[string]*projectInfo {
+func (n *network) TjProject(agencyIds, winnerIds []string, vbs map[string][]*idName, businessType []string, projectIdFlag bool) map[string]*projectInfo {
 	vm := map[string]*projectInfo{}
 	vm := map[string]*projectInfo{}
 	if len(agencyIds) == 0 && len(winnerIds) == 0 {
 	if len(agencyIds) == 0 && len(winnerIds) == 0 {
 		return vm
 		return vm
 	}
 	}
 	yearLimit := NetworkCom.ProjectYearLimit()
 	yearLimit := NetworkCom.ProjectYearLimit()
 	allArgs := []interface{}{}
 	allArgs := []interface{}{}
-	q := `select buyer_id,uniqCombined(project_id) AS project_count,sum(project_money) AS project_amount,groupUniqArray(project_id) from information.transaction_info_all prewhere buyer_id in (select DISTINCT buyer_id from information.transaction_info_all prewhere `
+	q := `select buyer_id,uniqCombined(project_id) AS project_count,sum(project_money) AS project_amount`
+	if projectIdFlag {
+		q += `,groupUniqArray(project_id)`
+	}
+	q += ` from information.transaction_info_all prewhere buyer_id in (select DISTINCT buyer_id from information.transaction_info_all prewhere `
 	if len(agencyIds) > 0 {
 	if len(agencyIds) > 0 {
 		wh, args := WhArgs(agencyIds)
 		wh, args := WhArgs(agencyIds)
 		allArgs = append(allArgs, args...)
 		allArgs = append(allArgs, args...)
@@ -1403,7 +1427,13 @@ func (n *network) TjProject(agencyIds, winnerIds []string, vbs map[string][]*idN
 			project_amount decimal.Decimal
 			project_amount decimal.Decimal
 			project_id     []string
 			project_id     []string
 		)
 		)
-		if err := rows.Scan(&buyer_id, &project_count, &project_amount, &project_id); err != nil {
+		var err error
+		if projectIdFlag {
+			err = rows.Scan(&buyer_id, &project_count, &project_amount, &project_id)
+		} else {
+			err = rows.Scan(&buyer_id, &project_count, &project_amount)
+		}
+		if err != nil {
 			logx.Error(err)
 			logx.Error(err)
 			continue
 			continue
 		}
 		}
@@ -1427,8 +1457,8 @@ func (n *network) TjProject(agencyIds, winnerIds []string, vbs map[string][]*idN
 	return vm
 	return vm
 }
 }
 
 
-func (n *network) MakeProjectInfo(agencyIds, winnerIds []string, vbs map[string][]*idName, businessType []string) map[string]*projectInfo {
-	pis := n.TjProject(agencyIds, winnerIds, vbs, businessType)
+func (n *network) MakeProjectInfo(agencyIds, winnerIds []string, vbs map[string][]*idName, businessType []string, projectIdFlag bool) map[string]*projectInfo {
+	pis := n.TjProject(agencyIds, winnerIds, vbs, businessType, projectIdFlag)
 	vm := map[string]*projectInfo{}
 	vm := map[string]*projectInfo{}
 	for k, v := range vbs {
 	for k, v := range vbs {
 		pi := &projectInfo{
 		pi := &projectInfo{
@@ -1454,7 +1484,7 @@ func (n *network) MakeProjectInfo(agencyIds, winnerIds []string, vbs map[string]
 	return vm
 	return vm
 }
 }
 
 
-func (n *network) AllIntroduceOwner(positionId int64, sqlAppend1, sqlAppend2 string, args []interface{}, isTjProject bool, businessType []string) *introduceOwnerProject {
+func (n *network) AllIntroduceOwner(positionId int64, sqlAppend1, sqlAppend2 string, args []interface{}, isTjProject bool, businessType []string, projectIdFlag bool) *introduceOwnerProject {
 	logx.Info(positionId, " AllIntroduceOwner start 。。。")
 	logx.Info(positionId, " AllIntroduceOwner start 。。。")
 	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=1,b.relate_name,NULL)) AS relate_buyer_name,GROUP_CONCAT(IF(b.itype=2,b.relate_id,NULL)) AS relate_project_id,a.create_time from crm.connection a 
 	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=1,b.relate_name,NULL)) AS relate_buyer_name,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
 		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
@@ -1508,15 +1538,15 @@ func (n *network) AllIntroduceOwner(positionId int64, sqlAppend1, sqlAppend2 str
 	if isTjProject {
 	if isTjProject {
 		iop.FirstpartyNetwork = n.FirstpartyNetwork("", firstparty_array)
 		iop.FirstpartyNetwork = n.FirstpartyNetwork("", firstparty_array)
 		logx.Info(positionId, " FirstpartyNetwork over 。。。")
 		logx.Info(positionId, " FirstpartyNetwork over 。。。")
-		iop.Firstparty, iop.FirstpartyPio = n.Introduce_Firstparty(iop.FirstpartyNetwork, businessType)
+		iop.Firstparty, iop.FirstpartyPio = n.Introduce_Firstparty(iop.FirstpartyNetwork, businessType, projectIdFlag)
 		logx.Info(positionId, " Introduce_Firstparty over 。。。")
 		logx.Info(positionId, " Introduce_Firstparty over 。。。")
-		iop.Supplier = n.Introduce_Supplier(supplier_array, businessType)
+		iop.Supplier = n.Introduce_Supplier(supplier_array, businessType, projectIdFlag)
 		logx.Info(positionId, " Introduce_Supplier over 。。。")
 		logx.Info(positionId, " Introduce_Supplier over 。。。")
-		iop.Adiffb = n.Introduce_Supplier(adiffb_array, businessType)
+		iop.Adiffb = n.Introduce_Supplier(adiffb_array, businessType, projectIdFlag)
 		logx.Info(positionId, " Introduce_Supplier over 。。。")
 		logx.Info(positionId, " Introduce_Supplier over 。。。")
-		iop.Agency = n.Introduce_Agency(agency_array, businessType)
+		iop.Agency = n.Introduce_Agency(agency_array, businessType, projectIdFlag)
 		logx.Info(positionId, " Introduce_Agency over 。。。")
 		logx.Info(positionId, " Introduce_Agency over 。。。")
-		iop.Middleman = n.Introduce_Middleman_Buyer(middleman_buyer_array, businessType)
+		iop.Middleman = n.Introduce_Middleman_Buyer(middleman_buyer_array, businessType, projectIdFlag)
 		logx.Info(positionId, " Introduce_Middleman_Buyer over 。。。")
 		logx.Info(positionId, " Introduce_Middleman_Buyer over 。。。")
 	}
 	}
 	return iop
 	return iop