فهرست منبع

Merge branch 'feature/v1.0.4' of https://jygit.jydev.jianyu360.cn/CRM/application into feature/v1.0.4

wangchuanjin 1 سال پیش
والد
کامیت
145aff7b05
5فایلهای تغییر یافته به همراه157 افزوده شده و 122 حذف شده
  1. 30 52
      api/internal/service/CoopHistoryService.go
  2. 68 34
      api/internal/service/owner.go
  3. 56 35
      api/internal/service/plistService.go
  4. 1 1
      go.mod
  5. 2 0
      go.sum

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

@@ -87,32 +87,36 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData) {
 			result = append(result, &tmp)
 		}
 	}
-	// 中间人可介绍业主
-	//if pTmp.BuyerId != "" {
-	//	r3 := GetData1(req.PositionId, pTmp.BuyerId)
-	//	if r3 != nil && len(r3) > 0 {
-	//		tmp := ResultData{
-	//			SourceType:  "middleman",
-	//			EntName:     common.ObjToString(m["name"]),
-	//			ProjectNum:  common.IntAll(m["coop_size"]),
-	//			TotalAmount: common.Float64All(m["coop_amount"]),
-	//			RecentTime:  zbtime,
-	//			NearlyYears: near,
-	//		}
-	//		result = append(result, &tmp)
-	//	}
-	//// 关联单位
-	//r4 := GetData2(pTmp.BuyerId)
-	//if r4 != nil && len(r4) > 0 {
-	//	tmp := &ResultData{
-	//		channelType: 1,
-	//		channel:     "业主关联单位",
-	//		size:        len(r4),
-	//		data:        r4,
-	//	}
-	//	result = append(result, tmp)
-	//}
-	//}
+	if pTmp.BuyerId != "" {
+		// 中间人可介绍业主
+		var r3 []map[string]interface{}
+		r3 = FindMiddleman([]string{pTmp.BuyerId}, req.PositionId, r3)
+		if r3 != nil && len(r3) > 0 {
+			for _, m := range r3 {
+				tmp := ResultData{
+					SourceType:   "middleman",
+					EntName:      common.ObjToString(m["b_name"]),
+					EntPerson:    common.ObjToString(m["personName"]),
+					Relationship: "业主的关系人",
+				}
+				result = append(result, &tmp)
+			}
+		}
+		// 关联单位
+		var r4 []map[string]interface{}
+		r4 = Findfirstparty([]string{pTmp.BuyerId}, r4)
+		if r4 != nil && len(r4) > 0 {
+			for _, m := range r3 {
+				tmp := ResultData{
+					SourceType:   "sup_sub",
+					EntName:      common.ObjToString(m["b_name"]),
+					EntPerson:    common.ObjToString(m["personName"]),
+					Relationship: common.ObjToString(m["relationship"]),
+				}
+				result = append(result, &tmp)
+			}
+		}
+	}
 	return
 }
 
@@ -193,32 +197,6 @@ func GetData(propertyForm, bid string) (result1, result2 []map[string]interface{
 	return
 }
 
-// @Author jianghan
-// @Description 中间人
-// @Date 2024/4/20
-func GetData1(positionId int64, buyid string) (result []map[string]interface{}) {
-	info := T.CrmMysql.SelectBySql(sql_2_2, positionId, buyid)
-	if info != nil && len(*info) > 0 {
-		for _, m := range *info {
-			result = append(result, map[string]interface{}{"name": m["company_name"], "pserson": m["contact_name"]})
-		}
-	}
-	return
-}
-
-// @Author jianghan
-// @Description 业主关联企业 上下级/股权控制
-// @Date 2024/4/20
-func GetData2(buyid string) (result []map[string]interface{}) {
-	info := T.CrmMysql.SelectBySql(sql_2_3, buyid, buyid, buyid, buyid, buyid, buyid)
-	if info != nil && len(*info) > 0 {
-		for _, m := range *info {
-			result = append(result, map[string]interface{}{"name": m["company_name"], "pserson": m["contact_name"]})
-		}
-	}
-	return
-}
-
 type P_History struct {
 	ProjectId   string `ch:"project_id"`
 	ProjectName string `ch:"project_name"`

+ 68 - 34
api/internal/service/owner.go

@@ -79,7 +79,15 @@ func (t *OwnerService) OwnerlList() map[string]interface{} {
 	dataMap := &map[string]map[string]interface{}{}
 	projectMap := &map[string]map[string]interface{}{}
 	if t.PartyA != "" || t.Supplier != "" || t.Heterotophy != "" || t.Intermediary != "" || t.Agency != "" {
-		dataMap = BuyerList(t.PartyA, t.Supplier, t.Heterotophy, t.Intermediary, t.Agency)
+		dataMap = BuyerList(t.PartyA, t.Supplier, t.Heterotophy, t.Intermediary, t.Agency, t.PositionId)
+		if len(*dataMap) == 0 {
+			return map[string]interface{}{
+				"connectionsNumber": 0,
+				"highSuccessNumber": 0,
+				"monitorNumber":     0,
+				"list":              []BuyerProject{},
+			}
+		}
 		//处理状态初始化
 		if t.ProcessingStatus != "" {
 			ProcessingStatusInit(t.PositionId, dataMap, t.ProcessingStatus)
@@ -202,6 +210,9 @@ func ConnectionsHandle(buyerArr []string, positionId int64, isAll bool) []map[st
 
 // 供应商处理
 func Findwinner(buyerArr []string, returnData []map[string]interface{}) []map[string]interface{} {
+	if len(buyerArr) == 0 {
+		return returnData
+	}
 	//供应商  采购单位 供应商     招标代理机构  采购单位  招标代理机构  需要计算合作次数
 	winnerSql := fmt.Sprintf(`select
 		DISTINCT 
@@ -358,6 +369,9 @@ func Findwinner(buyerArr []string, returnData []map[string]interface{}) []map[st
 
 // 中间人查询
 func FindMiddleman(buyerArr []string, positionId int64, returnData []map[string]interface{}) []map[string]interface{} {
+	if len(buyerArr) == 0 {
+		return returnData
+	}
 	//中间人  作为可介绍业主    企业名称
 	companyArr := CrmMysql.SelectBySql(
 		fmt.Sprintf("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=%d  and a.connection_id=b.id  and   a.relate_Id in (%s) and  a.itype =1  and  b.itype=4 and  b.status=1 ", positionId, strings.Join(buyerArr, ",")))
@@ -382,6 +396,9 @@ func FindMiddleman(buyerArr []string, positionId int64, returnData []map[string]
 
 // 企业之间关系查询
 func Findfirstparty(buyerArr []string, returnData []map[string]interface{}) []map[string]interface{} {
+	if len(buyerArr) == 0 {
+		return returnData
+	}
 	buyerSql := fmt.Sprintf(`select DISTINCT 
 			a.a_id as a_id,
 			a.b_id as b_id,
@@ -504,8 +521,11 @@ func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, s
 						EstimatedAmount: money,
 						Connections:     []map[string]interface{}{},
 					},
-					Area:   gconv.String(projectMap["area"]),
-					Zbtime: zbtime,
+					Area:             gconv.String(projectMap["area"]),
+					Zbtime:           zbtime,
+					IsIgnore:         gconv.Bool(buyerMap["isIgnore"]),
+					IsMonitor:        gconv.Bool(buyerMap["isMonitor"]),
+					IsCreateCustomer: gconv.Bool(buyerMap["isCreateCustomer"]),
 				})
 			} else {
 				if count > 2 {
@@ -519,8 +539,11 @@ func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, s
 						EstimatedAmount: money,
 						Connections:     []map[string]interface{}{},
 					},
-					Area:   gconv.String(projectMap["area"]),
-					Zbtime: zbtime,
+					Area:             gconv.String(projectMap["area"]),
+					Zbtime:           zbtime,
+					IsIgnore:         gconv.Bool(buyerMap["isIgnore"]),
+					IsMonitor:        gconv.Bool(buyerMap["isMonitor"]),
+					IsCreateCustomer: gconv.Bool(buyerMap["isCreateCustomer"]),
 				})
 			}
 		} else {
@@ -532,8 +555,11 @@ func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, s
 					EstimatedAmount: 0,
 					Connections:     []map[string]interface{}{},
 				},
-				Area:   "",
-				Zbtime: 0,
+				Area:             "",
+				Zbtime:           0,
+				IsIgnore:         false,
+				IsMonitor:        false,
+				IsCreateCustomer: false,
 			})
 		}
 		connectionsNumber++
@@ -628,18 +654,17 @@ func ProcessingStatusInit(positionId int64, dataMap *map[string]map[string]inter
 }
 
 // 采购单位查询
-func BuyerList(partyA, supplier, heterotophy, intermediary, agency string) *map[string]map[string]interface{} {
+func BuyerList(partyA, supplier, heterotophy, intermediary, agency string, positionId int64) *map[string]map[string]interface{} {
 	dataMap := &map[string]map[string]interface{}{}
 	//甲方
 	if partyA != "" {
+		intermediaryArr := []string{}
 		for _, v := range strings.Split(partyA, ",") {
-			intermediaryArr := strings.Split(v, "_")
-			if len(intermediaryArr) == 2 {
-				(*dataMap)[intermediaryArr[0]] = map[string]interface{}{
-					"buyerName": intermediaryArr[1],
-				}
-			}
+			intermediaryArr = append(intermediaryArr, fmt.Sprintf("'%s'", v))
+
 		}
+		partyASql := fmt.Sprintf(`select  id as buyer_id,company_name as buyer  from  ent_info   where  id in (%s)`, strings.Join(intermediaryArr, ","))
+		FindHandle(partyASql, dataMap)
 	}
 	//供应商 //同甲异业
 	if supplier != "" || heterotophy != "" {
@@ -655,11 +680,14 @@ func BuyerList(partyA, supplier, heterotophy, intermediary, agency string) *map[
 	}
 	//中间人
 	if intermediary != "" {
-		for _, v := range strings.Split(intermediary, ",") {
-			intermediaryArr := strings.Split(v, "_")
-			if len(intermediaryArr) == 2 {
-				(*dataMap)[intermediaryArr[0]] = map[string]interface{}{
-					"buyerName": intermediaryArr[1],
+		intermediarySql := fmt.Sprintf(`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.position_id=%s  and  find_in_set(company_id,"")and a.id=b.connection_id and b.itype=1)`, gconv.String(positionId), intermediary)
+		intermediaryArr := CrmMysql.SelectBySql(intermediarySql)
+		if intermediaryArr != nil && len(*intermediaryArr) > 0 {
+			for _, m := range *intermediaryArr {
+				buyerId := gconv.String(m["relate_id"])
+				buyerName := gconv.String(m["relate_name"])
+				(*dataMap)[buyerId] = map[string]interface{}{
+					"buyerName": buyerName,
 				}
 			}
 		}
@@ -766,8 +794,10 @@ func FindHandle(sqlStr string, dataMap *map[string]map[string]interface{}) {
 	for rows.Next() {
 		data := Recommend{}
 		rows.ScanStruct(&data)
-		(*dataMap)[data.buyerId] = map[string]interface{}{
-			"buyerName": data.buyer,
+		if data.buyerId != "" {
+			(*dataMap)[data.buyerId] = map[string]interface{}{
+				"buyerName": data.buyer,
+			}
 		}
 	}
 	return
@@ -975,7 +1005,7 @@ func (t *OwnerService) CandidateChannel() []*ResultData {
 	returnData := []*ResultData{}
 	dataMap := &map[string]map[string]interface{}{}
 	if t.PartyA != "" || t.Supplier != "" || t.Heterotophy != "" || t.Intermediary != "" || t.Agency != "" {
-		dataMap = BuyerList(t.PartyA, t.Supplier, t.Heterotophy, t.Intermediary, t.Agency)
+		dataMap = BuyerList(t.PartyA, t.Supplier, t.Heterotophy, t.Intermediary, t.Agency, t.PositionId)
 	}
 	if len(*dataMap) > 0 && dataMap != nil {
 		propertyForm := ""
@@ -1013,32 +1043,36 @@ func (t *OwnerService) CandidateChannel() []*ResultData {
 					returnData = append(returnData, &tmp)
 				}
 			}
-			r3 := GetData1(t.PositionId, buyerId)
+
+			// 中间人可介绍业主
+			var r3 []map[string]interface{}
+			r3 = FindMiddleman([]string{buyerId}, t.PositionId, r3)
 			if r3 != nil && len(r3) > 0 {
 				for _, m := range r3 {
 					tmp := ResultData{
-						SourceType:  "middleman",
-						EntName:     common.ObjToString(m["name"]),
-						ProjectNum:  common.IntAll(m["coop_size"]),
-						TotalAmount: common.Float64All(m["coop_amount"]),
+						SourceType:   "middleman",
+						EntName:      common.ObjToString(m["b_name"]),
+						EntPerson:    common.ObjToString(m["personName"]),
+						Relationship: "业主的关系人",
 					}
 					returnData = append(returnData, &tmp)
 				}
 			}
-			r4 := GetData2(buyerId)
+			// 关联单位
+			var r4 []map[string]interface{}
+			r4 = Findfirstparty([]string{buyerId}, r4)
 			if r4 != nil && len(r4) > 0 {
-				for _, m := range r4 {
+				for _, m := range r3 {
 					tmp := ResultData{
-						SourceType:  "sup_sub",
-						EntName:     common.ObjToString(m["name"]),
-						ProjectNum:  common.IntAll(m["coop_size"]),
-						TotalAmount: common.Float64All(m["coop_amount"]),
+						SourceType:   "sup_sub",
+						EntName:      common.ObjToString(m["b_name"]),
+						EntPerson:    common.ObjToString(m["personName"]),
+						Relationship: common.ObjToString(m["relationship"]),
 					}
 					returnData = append(returnData, &tmp)
 				}
 			}
 		}
-
 	}
 	return returnData
 }

+ 56 - 35
api/internal/service/plistService.go

@@ -2,6 +2,7 @@ package service
 
 import (
 	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/encrypt"
 	P "app.yhyue.com/moapp/jybase/mapping"
 	T "bp.jydev.jianyu360.cn/CRM/application/api/common"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
@@ -12,9 +13,9 @@ import (
 )
 
 const (
-	sql_1 = `SELECT buyer_id, count(1) as count FROM information.transaction_info WHERE buyer_id in (?) GROUP BY buyer_id`
+	sql_1 = `SELECT buyer_id, count(1) as count FROM information.transaction_info WHERE buyer_id in (%s) GROUP BY buyer_id`
 	sql_2 = `SELECT relate_id, is_handle, is_ignore, is_create FROM crm.connection_status WHERE position_id = ? AND itype = 2`
-	sql_3 = `SELECT * FROM crm.connection WHERE company_id in (?) AND status = 1`
+	sql_3 = `SELECT * FROM crm.connection WHERE company_id in (%s) AND status = 1`
 )
 
 type ProjectData struct {
@@ -51,7 +52,7 @@ type ProjectEntry struct {
 
 func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasNextPage bool, total int) {
 
-	buyerM := BuyerList(req.PartyA, req.Supplier, req.Heterotophy, req.Intermediary, req.Agency)
+	buyerM := BuyerList(req.PartyA, req.Supplier, req.Heterotophy, req.Intermediary, req.Agency, req.PositionId)
 	MonitorStatusInit(req.PositionId, buyerM, "0")
 	buyerArr := make([]string, len(*buyerM))
 	for b := range *buyerM {
@@ -72,6 +73,7 @@ func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasN
 	for rows.Next() {
 		project := ProjectEntry{}
 		_ = rows.ScanStruct(&project)
+		project.ProjectId = encrypt.CommonEncodeArticle("content", project.ProjectId)
 		resultList = append(resultList, &project)
 	}
 
@@ -209,10 +211,10 @@ func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr []string) (cou
 	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 "
 	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 ", findSql, "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 "))
 	} else {
 		countSql = fmt.Sprintf("select count(1) from %s a ", "information.transaction_info")
-		findSql = fmt.Sprintf("%s from %s  a ", findSql, "information.transaction_info")
+		findSql = fmt.Sprintf("%s from %s a order by zbtime", findSql, "information.transaction_info")
 	}
 	if isPage {
 		findSql += fmt.Sprintf(" limit %d,%d", (req.PageNum-1)*req.PageSize, req.PageSize)
@@ -275,16 +277,17 @@ func moreInfo(req *types.ProjectListReq, list []*ProjectEntry) (result []*Projec
 		}
 	}
 	countMap := make(map[string]int)
-	info1, err := T.ClickhouseConn.Query(context.TODO(), sql_1, strings.Join(buyerIds, ","))
+	str1, arr1 := common.WhArgs(buyerIds)
+	info1, err := T.ClickhouseConn.Query(context.TODO(), fmt.Sprintf(sql_1, str1), arr1...)
 	if err == nil {
 		for info1.Next() {
 			var buyerId string
-			var count int
+			var count uint64
 			_ = info1.Scan(&buyerId, &count)
-			countMap[buyerId] = count
+			countMap[buyerId] = int(count)
 		}
 	}
-	info2 := T.CrmMysql.SelectBySql(sql_3, strings.Join(buyerIds, ","))
+	info2 := T.CrmMysql.SelectBySql(fmt.Sprintf(sql_3, str1), arr1...)
 	connMap := make(map[string]int)
 	if info2 != nil && len(*info2) > 0 {
 		for _, m := range *info2 {
@@ -318,31 +321,49 @@ func moreInfo(req *types.ProjectListReq, list []*ProjectEntry) (result []*Projec
 		}
 	}
 	// 人脉路径
-	//var bArr []string
-	//for _, m := range list {
-	//	// 有我的人脉标签时不需要查询人脉路径信息
-	//	if m.MyConn == false && m.BuyerId != "" {
-	//		bArr = append(bArr, fmt.Sprintf("'%s'", m.BuyerId))
-	//	}
-	//}
-	//companyList := ConnectionsHandle(bArr, req.PositionId, false)
-	//if companyList != nil && len(companyList) > 0 {
-	//	for _, m := range list {
-	//		if m.MyConn == false {
-	//			for _, m1 := range companyList {
-	//				if m.BuyerId == common.ObjToString(m1["b_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"])
-	//					break
-	//				}
-	//			}
-	//		}
-	//	}
-	//
-	//}
+	var bArr []string
+	for _, m := range list {
+		// 有我的人脉标签时不需要查询人脉路径信息
+		if m.MyConn == false && m.BuyerId != "" {
+			bArr = append(bArr, fmt.Sprintf("'%s'", m.BuyerId))
+		}
+	}
+	companyList := Findfirstparty(bArr, nil)
+	if companyList != nil && len(companyList) > 0 {
+		for _, m := range list {
+			if m.MyConn == false {
+				for _, m1 := range companyList {
+					if m.BuyerId == common.ObjToString(m1["b_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"])
+						break
+					}
+				}
+			}
+		}
+	} else {
+		companyList = Findwinner(bArr, nil)
+		if companyList != nil && len(companyList) > 0 {
+			for _, m := range list {
+				if m.MyConn == false {
+					for _, m1 := range companyList {
+						if m.BuyerId == common.ObjToString(m1["b_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"])
+							break
+						}
+					}
+				}
+			}
+		}
+	}
 	return list
 }

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module bp.jydev.jianyu360.cn/CRM/application
 go 1.19
 
 require (
-	app.yhyue.com/moapp/jybase v0.0.0-20240422010359-27408422af30
+	app.yhyue.com/moapp/jybase v0.0.0-20240424025716-c77615e9004e
 	app.yhyue.com/moapp/jypkg v0.0.0-20230825092743-3bfc415bb5bb
 	bp.jydev.jianyu360.cn/BaseService/fileCenter v0.0.0-20231016051530-64b559fee531
 	bp.jydev.jianyu360.cn/BaseService/gateway v1.3.4

+ 2 - 0
go.sum

@@ -12,6 +12,8 @@ app.yhyue.com/moapp/jybase v0.0.0-20220706083640-79084ff2be42/go.mod h1:FjBF25AY
 app.yhyue.com/moapp/jybase v0.0.0-20230117032034-ad7c00ffe11a/go.mod h1:zB47XTeJvpcbtBRYgkQuxOICWNexiZfbUO+7aUf6mNs=
 app.yhyue.com/moapp/jybase v0.0.0-20240422010359-27408422af30 h1:d3EW7fnnsIUtXCeYvPRvRr7NfrKRZwQRWOV8DJpN+T4=
 app.yhyue.com/moapp/jybase v0.0.0-20240422010359-27408422af30/go.mod h1:XHNATN6tsJKHdCB0DbUtFdPPHXexTUFyB3RlO+lUUoM=
+app.yhyue.com/moapp/jybase v0.0.0-20240424025716-c77615e9004e h1:1LaaIJVFQrwtjMKagxxq1JHZ93I48xzmJk6DI5PiCL8=
+app.yhyue.com/moapp/jybase v0.0.0-20240424025716-c77615e9004e/go.mod h1:XHNATN6tsJKHdCB0DbUtFdPPHXexTUFyB3RlO+lUUoM=
 app.yhyue.com/moapp/jypkg v0.0.0-20230825092743-3bfc415bb5bb h1:J9CQ60meKlABYqeOB6zdZXJtBHAsJqnHeWhd/OOCUtU=
 app.yhyue.com/moapp/jypkg v0.0.0-20230825092743-3bfc415bb5bb/go.mod h1:VaHDi3twSg4G84k2+UFOe7ZCw5EqUZVAkW2N2dHeMbU=
 bp.jydev.jianyu360.cn/BP/jynsq v0.0.0-20220222052708-ebc43af90698/go.mod h1:ojo/AUH9Yr1wzarEjOaNMkj1Cet/9r8IgLyba64Z52E=