Просмотр исходного кода

Merge branch 'master' of https://jygit.jydev.jianyu360.cn/CRM/networkManage

wangchuanjin 9 месяцев назад
Родитель
Сommit
8eb8b9773e

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

@@ -19,12 +19,14 @@ 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_2   = `SELECT buyer, buyer_id, agency, agency_id, property_form FROM information.transaction_info WHERE has(info_ids, ?)`
 	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_1_1 = `SELECT project_id, project_name, zbtime FROM information.transaction_info WHERE buyer_id = ? AND agency = ? ORDER BY zbtime DESC`
-	sql_2_2   = `select DISTINCT  b.company_id,b.company_name,a.relate_id,a.relate_name,b.contact_person   from  connection_introduce a  INNER JOIN connection b on  a.position_id= ? and a.connection_id=b.id  and   a.relate_Id = ? and  a.itype =1  and  b.itype=4 and  b.status=1 `
-	sql_2_3   = `select a.a_id as a_id, a.b_id as b_id, a.a_name as a_name, a.b_name as b_name, a.code as code, c.legal_person as c_person, d.legal_person d_person from crm.ent_map_code a left join ent_info c on (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201') and a.a_id = c.id left join ent_info d on (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201') and a.b_id = d.id where (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201')`
-	es_query  = `{"query": {"bool": {"must": [{"terms": {"buyer_id": ["%s"]}},{"exists": {"field": "winner_id"}}],"must_not": {"terms": {"property_form": ["%s"]}}}},"aggs": {"winner_count": {"terms": {"field": "winner","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "winner_id"}},"buyer_id": {"terms": {"field": "buyer_id"}}}}},"size": 1}`
-	es_query1 = `{"query": {"bool": {"must": [{"terms": {"buyer_id": ["%s"]}}],"must_not": [{"term": {"agency_id": {"value": ""}}}]}},"aggs": {"agency_count": {"terms": {"field": "agency","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "agency_id"}},"buyer_id": {"terms": {"field": "buyer_id"}}}}},"size": 1}`
+	//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": [{"terms": {"buyer_id": ["%s"]}},{"exists": {"field": "winner_id"}}],"should": [%s],"minimum_should_match": 1}},"aggs": {"winner_count": {"terms": {"field": "winner","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "winner_id"}},"buyer_id": {"terms": {"field": "buyer_id"}}}}},"size": 1}`
+	es_query1  = `{"query": {"bool": {"must": [{"terms": {"buyer_id": ["%s"]}}],"must_not": [{"term": {"agency_id": {"value": ""}}}]}},"aggs": {"agency_count": {"terms": {"field": "agency","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "agency_id"}},"buyer_id": {"terms": {"field": "buyer_id"}}}}},"size": 1}`
+	shouldMul1 = `{"term": {"topscopeclass": "%s"}}`
 )
 
 type ResultData struct {
@@ -76,20 +78,20 @@ type Cooperate struct {
 
 func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2, size_3, size_4 int64) {
 	pTmp := ProjectTmp{}
-	id := ""
+	var err error
 	if req.Pid != "" {
-		id = req.Pid
+		err = T.ClickhouseConn.QueryRow(context.TODO(), sql_2_0, req.Pid).ScanStruct(&pTmp)
 	} else if req.Bid != "" {
-		id = encrypt.CommonDecodeArticle("content", req.Bid)[0]
-	}
-	if id == "" {
+		id := encrypt.CommonDecodeArticle("content", req.Bid)[0]
+		err = T.ClickhouseConn.QueryRow(context.TODO(), sql_2_2, id).ScanStruct(&pTmp)
+	} else {
 		return
 	}
-	err := T.ClickhouseConn.QueryRow(context.TODO(), sql_2_0, id).ScanStruct(&pTmp)
 	if err != nil {
 		return nil, 0, 0, 0, 0
 	}
-	propertyForm := T.NetworkCom.GetMyProbusfor(req.EntAccountId)
+	//propertyForm := T.NetworkCom.GetMyProbusfor(req.EntAccountId)
+	scopeClass := FindBusiness(req.EntId, req.EntUserId)
 	// firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构 sup_sub: 上下级
 	// 1、同甲异业数据/ 3、招标代理机构渠道
 	if pTmp.BuyerId != "" {
@@ -131,7 +133,7 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 				}
 			}
 		}
-		rs1, rs2 := GetData(propertyForm, pTmp.BuyerId)
+		rs1, rs2 := GetData(strings.Split(scopeClass, ","), pTmp.BuyerId)
 		r1 := rs1[pTmp.BuyerId]
 		r2 := rs2[pTmp.BuyerId]
 		winners, agency := []string{}, []string{}
@@ -186,7 +188,7 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 	return
 }
 
-func GetData(propertyForm []string, bid string) (result1, result2 map[string][]map[string]interface{}) {
+func GetData(scopeClass []string, bid string) (result1, result2 map[string][]map[string]interface{}) {
 	result1, result2 = map[string][]map[string]interface{}{}, map[string][]map[string]interface{}{}
 	type AggStruct struct {
 		Buckets []struct {
@@ -212,10 +214,14 @@ func GetData(propertyForm []string, bid string) (result1, result2 map[string][]m
 	m1 := make(map[string]interface{}) //采购单位-中标单位
 	m2 := make(map[string]interface{}) //采购单位-代理机构
 	noIds := []string{}
-	if len(propertyForm) > 0 {
+	if len(scopeClass) > 0 {
 		//同甲异态 中标企业
-		aggs, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(propertyForm, "\",\"")))
-		logx.Info("es聚合查询结果:", fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(propertyForm, "\",\"")))
+		var should []string
+		for _, v := range scopeClass {
+			should = append(should, fmt.Sprintf(shouldMul1, v))
+		}
+		aggs, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(should, ",")))
+		logx.Info("es聚合查询结果:", fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(should, ",")))
 		var m1Buckets = AggStruct{}
 		if aggs != nil && aggs["winner_count"] != nil {
 			bs, err := aggs["winner_count"].MarshalJSON()

+ 148 - 83
api/internal/service/owner.go

@@ -1,9 +1,11 @@
 package service
 
 import (
+	"app.yhyue.com/moapp/jybase/redis"
 	"context"
 	"encoding/json"
 	"fmt"
+	"log"
 	"sort"
 	"strings"
 	"time"
@@ -75,104 +77,175 @@ type Project struct {
 	Money      decimal.Decimal `ch:"money"`
 }
 
+// OwnerlList 执行主要的业务逻辑
 func (t *OwnerService) OwnerlList() map[string]interface{} {
-	//先查询采购单位列表
+	// 先查询采购单位列表
 	startTime := time.Now().Unix()
 	dataMap := &map[string]map[string]interface{}{}
 	projectMap := &map[string]map[string]interface{}{}
 	businessStr := FindBusiness(t.EntId, t.UserId)
-	returnData, connectionsNumber, highSuccessNumber, monitorNumber := []BuyerProject{}, int64(0), int64(0), int64(0)
+	// 初始化分页参数
+	if t.PageSize == 0 {
+		t.PageSize = 10
+	}
+	if t.PageIndex == 0 {
+		t.PageIndex = 1
+	}
+	startIndex := (t.PageIndex - 1) * t.PageSize
+	endIndex := t.PageIndex * t.PageSize
+	returnData, connectionsNumber := []BuyerProject{}, int64(0)
+	// 如果没有业务字符串,直接返回空数据
 	if businessStr == "" {
 		return map[string]interface{}{
-			"connectionsNumber": connectionsNumber,
-			"highSuccessNumber": highSuccessNumber,
-			"monitorNumber":     monitorNumber,
 			"list":              returnData,
+			"connectionsNumber": connectionsNumber,
 		}
 	}
-	if 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{},
+	key := fmt.Sprintf("%+v", t)
+	key = fmt.Sprintf("%s%s", key, fmt.Sprintf(" business:%s", businessStr))
+	listKey := "ownerlList-" + common.GetMd5String(fmt.Sprintf("%+v", key))
+	countKey := "ownerlCount-" + common.GetMd5String(fmt.Sprintf("%+v", key))
+	// 检查 Redis 中是否存在列表缓存
+	if ok, err := redis.Exists("newother", listKey); ok && err == nil && t.SourceType != "2" {
+		returnData = handleRedisCache(listKey)
+		connectionsNumber = gconv.Int64(redis.GetInt("newother", countKey))
+		// 处理监控状态
+	} else {
+		log.Println("111", fmt.Sprintf("%+v", key))
+		key = "companyList-" + common.GetMd5String(fmt.Sprintf("%+v", key))
+		// 检查 Redis 中是否存在公司缓存
+		if ok, err := redis.Exists("newother", key); ok && err == nil && t.SourceType != "2" {
+			// 处理可介绍业主人脉
+			returnData = handleRedisCache(key)
+			sortAndPaginateReturnData(&returnData, startIndex, endIndex)
+		} else {
+			// 没有缓存时的处理逻辑
+			if 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{},
+					}
+				}
+				// 监控状态处理
+				MonitorStatusInit(t.PositionId, dataMap, t.SourceType)
+				// 项目数量查询
+				buyerArr := getBuyerArr(dataMap)
+				// 项目数量处理
+				projectMap, dataMap = ProjectHandle(buyerArr, t.EntAccountId, t.SearchEntName, t.Area, businessStr, dataMap)
+			} else {
+				return map[string]interface{}{}
+			}
+			endTime := time.Now().Unix()
+			fmt.Println("用时时间:", endTime-startTime)
+			if len(*dataMap) == 0 {
+				return map[string]interface{}{}
+			}
+			// 采购单位和项目合并
+			a1 := time.Now().Unix()
+			returnData, connectionsNumber = BuyerProjectMerge(dataMap, projectMap, t.SourceType)
+			a2 := time.Now().Unix()
+			fmt.Println("组合数据", a2-a1)
+			if len(returnData) > 0 {
+				redis.Put("newother", key, returnData, C.CacheTimeOut)
+				sort.Slice(returnData, func(i, j int) bool {
+					aa := fmt.Sprintf("%d%s", (returnData)[i].Zbtime, (returnData)[i].BuyerId)
+					bb := fmt.Sprintf("%d%s", (returnData)[j].Zbtime, (returnData)[j].BuyerId)
+					return aa > bb
+				})
+				// 数组分页处理
+				sortAndPaginateReturnData(&returnData, startIndex, endIndex)
 			}
+
 		}
+	}
+	if ok, err := redis.Exists("newother", listKey); !ok || err != nil || t.SourceType == "2" {
+		buyerIdArr := getBuyerIdArr(returnData)
+		// 可介绍业主人脉处理
+		a3 := time.Now().Unix()
+		routeList := ConnectionsHandle(buyerIdArr, t.PositionId, false)
+		a4 := time.Now().Unix()
+		fmt.Println("组合数1111据", a4-a3)
+		updateReturnDataWithRoutes(returnData, routeList)
+	}
+	if len(returnData) > 0 {
 		//监控状态处理
-		//MonitorStatusInit(t.PositionId, dataMap, t.SourceType)
-		//项目数量查询
-		buyerArr := []string{}
-		for _, value := range *dataMap {
-			buyerArr = append(buyerArr, fmt.Sprintf(`"%s"`, gconv.String(value["buyerName"])))
+		monitorMap := NetworkCom.EntMonitor(gconv.String(t.PositionId))
+		for k, value := range returnData {
+			if _, ok := monitorMap[value.BuyerName]; ok {
+				returnData[k].IsMonitor = true
+			}
 		}
-		//项目数量处理
-		projectMap, _, dataMap = ProjectHandle(buyerArr, t.EntAccountId, t.SearchEntName, t.Area, businessStr, dataMap)
-	} else {
-		return map[string]interface{}{}
+		redis.Put("newother", listKey, returnData, C.CacheTimeOut)
+		redis.Put("newother", countKey, connectionsNumber, C.CacheTimeOut)
+
 	}
-	endTime := time.Now().Unix()
-	fmt.Println("用时时间:", endTime-startTime)
-	if len(*dataMap) == 0 {
-		return map[string]interface{}{}
+	// 返回数据组装
+	return map[string]interface{}{
+		"list":              returnData,
+		"connectionsNumber": connectionsNumber,
 	}
-	//采购单位和项目合并
-	a1 := time.Now().Unix()
-	returnData, connectionsNumber, highSuccessNumber, monitorNumber = BuyerProjectMerge(dataMap, projectMap, t.SourceType)
-	a2 := time.Now().Unix()
-	fmt.Println("组合数据", a2-a1)
-	//数组排序
-	//分页数据处理
-	if t.PageSize == 0 {
-		t.PageSize = 10
+}
+
+// handleRedisCache 处理从 Redis 中获取缓存数据的逻辑
+func handleRedisCache(key string) []BuyerProject {
+	returnData := []BuyerProject{}
+	if bytes, err := redis.GetBytes("newother", key); err == nil && bytes != nil {
+		err = json.Unmarshal(*bytes, &returnData)
+		if err != nil {
+			// 处理解组错误
+			fmt.Println("Error unmarshaling from Redis:", err)
+		}
 	}
-	if t.PageIndex == 0 {
-		t.PageIndex = 1
+	return returnData
+}
+
+// getBuyerArr 从数据映射中获取买家数组
+func getBuyerArr(dataMap *map[string]map[string]interface{}) []string {
+	buyerArr := []string{}
+	for _, value := range *dataMap {
+		buyerArr = append(buyerArr, fmt.Sprintf(`"%s"`, gconv.String(value["buyerName"])))
 	}
-	startIndex := (t.PageIndex - 1) * t.PageSize
-	endIndex := t.PageIndex * t.PageSize
-	sort.Slice(returnData, func(i, j int) bool {
-		aa := fmt.Sprintf("%d%s", returnData[i].Zbtime, returnData[i].BuyerId)
-		bb := fmt.Sprintf("%d%s", returnData[j].Zbtime, returnData[j].BuyerId)
-		return aa > bb
-	})
-	if startIndex < gconv.Int64(len(returnData)) {
-		if endIndex > gconv.Int64(len(returnData)) {
-			endIndex = gconv.Int64(len(returnData))
+	return buyerArr
+}
+
+// sortAndPaginateReturnData 对返回数据进行分页处理
+func sortAndPaginateReturnData(returnData *[]BuyerProject, startIndex, endIndex int64) {
+
+	if startIndex < int64(len(*returnData)) {
+		if endIndex > int64(len(*returnData)) {
+			endIndex = int64(len(*returnData))
 		}
-		returnData = returnData[startIndex:endIndex]
-	} else {
-		return map[string]interface{}{}
+		*returnData = (*returnData)[startIndex:endIndex]
 	}
+}
+
+// getBuyerIdArr 从返回数据中获取企业ID 数组
+func getBuyerIdArr(returnData []BuyerProject) []string {
 	buyerIdArr := []string{}
 	for _, value := range returnData {
 		if value.BuyerId != "" {
 			buyerIdArr = append(buyerIdArr, fmt.Sprintf("'%s'", value.BuyerId))
 		}
 	}
-	//可介绍业主人脉处理
-	a3 := time.Now().Unix()
-	routeList := ConnectionsHandle(buyerIdArr, t.PositionId, false)
-	a4 := time.Now().Unix()
-	fmt.Println("组合数1111据", a4-a3)
+	return buyerIdArr
+}
+
+// updateReturnDataWithRoutes 将路线信息更新到返回数据中
+func updateReturnDataWithRoutes(returnData []BuyerProject, routeList []map[string]interface{}) {
 	for _, v := range routeList {
 		buyerId := gconv.String(v["a_id"])
 		for i, v1 := range returnData {
 			aBuyerId := v1.BuyerId
 			if buyerId == aBuyerId {
-				//组装数据
+				// 组装数据
 				returnData[i].Project.Connections = append(returnData[i].Project.Connections, v)
 			}
 		}
 	}
-	//返回数据组装
-	return map[string]interface{}{
-		"connectionsNumber": connectionsNumber,
-		"highSuccessNumber": highSuccessNumber,
-		"monitorNumber":     monitorNumber,
-		"list":              returnData,
-	}
 }
 
 // 可介绍业主人脉列表
@@ -521,25 +594,17 @@ func Findfirstparty(buyerArr []string, returnData []map[string]interface{}) []ma
 }
 
 // 采购单位和项目合并
-func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, sourceType string) ([]BuyerProject, int64, int64, int64) {
+func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, sourceType string) ([]BuyerProject, int64) {
 	returnData := []BuyerProject{}
 	connectionsNumber := int64(0)
-	highSuccessNumber := int64(0)
-	monitorNumber := int64(0)
 	for buyerId, buyerMap := range *dataMap {
 		buyerName := gconv.String(buyerMap["buyerName"])
 		count := int64(0)
 		if _, ok := (*projectMap)[buyerName]; ok {
 			projectMap := (*projectMap)[buyerName]
-			if isMonitor := gconv.Bool(buyerMap["isMonitor"]); isMonitor {
-				monitorNumber++
-			}
-			count = gconv.Int64(projectMap["count"])
 			money := gconv.Int64(projectMap["money"])
+			count = gconv.Int64(projectMap["count"])
 			zbtime := gconv.Int64(projectMap["zbtime"])
-			if count >= 2 {
-				highSuccessNumber++
-			}
 			returnData = append(returnData, BuyerProject{
 				BuyerId:   buyerId,
 				BuyerName: buyerName,
@@ -555,11 +620,11 @@ func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, s
 				CId:       gconv.String(buyerMap["cId"]),
 			})
 		} else {
-			/*if sourceType == "1" {
+			if sourceType == "1" {
 				if count < 2 {
 					continue
 				}
-			}*/
+			}
 			returnData = append(returnData, BuyerProject{
 				BuyerId:   buyerId,
 				BuyerName: buyerName,
@@ -578,7 +643,7 @@ func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, s
 		}
 		connectionsNumber++
 	}
-	return returnData, connectionsNumber, highSuccessNumber, monitorNumber
+	return returnData, connectionsNumber
 }
 
 // 已监控数据处理
@@ -601,16 +666,16 @@ func MonitorStatusInit(positionId int64, dataMap *map[string]map[string]interfac
 			v["isMonitor"] = true
 			(*newMap)[k] = v
 		} else {
-			/*if sourceType != "2" {
+			if sourceType != "2" {
 				v["isMonitor"] = false
 				(*newMap)[k] = v
-			}*/
+			}
 		}
 	}
-	/*if sourceType == "2" {
+	if sourceType == "2" {
 		*dataMap = *newMap
 		return
-	}*/
+	}
 	if newMap != nil {
 		*dataMap = *newMap
 	}
@@ -718,7 +783,7 @@ func BuyerList(partyA, supplier, heterotophy, intermediary, agency string, posit
 }
 
 // 项目数量查
-func ProjectHandle(buyerArr []string, entAccountId int64, entName, area, businessStr string, dataMap *map[string]map[string]interface{}) (*map[string]map[string]interface{}, *map[string]map[string]interface{}, *map[string]map[string]interface{}) {
+func ProjectHandle(buyerArr []string, entAccountId int64, entName, area, businessStr string, dataMap *map[string]map[string]interface{}) (*map[string]map[string]interface{}, *map[string]map[string]interface{}) {
 	projectMap := &map[string]map[string]interface{}{}
 	returnMap := &map[string]map[string]interface{}{}
 	sql := ""
@@ -738,7 +803,7 @@ func ProjectHandle(buyerArr []string, entAccountId int64, entName, area, busines
 	endTime := time.Now().Unix()
 	fmt.Println("es用时时间:", endTime-startTime)
 	if len(data) == 0 {
-		return projectMap, returnMap, dataMap
+		return projectMap, dataMap
 	}
 	for _, object := range data {
 		buyerArr := BuyerAggStruct{}
@@ -796,7 +861,7 @@ func ProjectHandle(buyerArr []string, entAccountId int64, entName, area, busines
 		}
 
 	}
-	return projectMap, returnMap, dataMap
+	return projectMap, dataMap
 }
 
 type BuyerAggStruct struct {

+ 55 - 46
api/internal/service/plistService.go

@@ -3,10 +3,12 @@ package service
 import (
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/encrypt"
+	"app.yhyue.com/moapp/jybase/redis"
 	"app.yhyue.com/moapp/jypkg/ent/util"
 	T "bp.jydev.jianyu360.cn/CRM/networkManage/api/common"
 	"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/types"
 	"context"
+	"encoding/json"
 	"fmt"
 	"github.com/gogf/gf/v2/util/gconv"
 	"github.com/shopspring/decimal"
@@ -74,47 +76,55 @@ func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasN
 	for b := range *buyerM {
 		buyerArr = append(buyerArr, b)
 	}
-	preSales := preSalesStatus(req.PositionId)
-	isSqlPage := false
-	if req.SaleStatus == "0" {
-		isSqlPage = true // 是否sql分页
-	}
-	countSql, findSql := getQuerySql(req, isSqlPage, buyerArr, plist)
-	logx.Info("findSql: ", findSql)
-	rows, err := T.ClickhouseConn.Query(context.TODO(), findSql)
-	defer rows.Close()
-	if err != nil {
-		return nil, false, 0
-	}
-	for rows.Next() {
-		project := ProjectEntry{}
-		_ = rows.ScanStruct(&project)
-		resultList = append(resultList, &project)
+	//preSales := preSalesStatus(req.PositionId)
+	//isSqlPage := true
+	//if req.SaleStatus == "0" {
+	//	isSqlPage = true // 是否sql分页
+	//}
+	countSql, findSql := getQuerySql(req, true, buyerArr, plist)
+	// 缓存
+	rkey := "projectList-" + common.GetMd5String(fmt.Sprintf("%+v", req))
+	if ret, err := redis.GetBytes("newother", rkey); err == nil {
+		err = json.Unmarshal(*ret, &resultList)
+	} else {
+		logx.Info("findSql: ", findSql)
+		logx.Info("countSql: ", countSql)
+		rows, err := T.ClickhouseConn.Query(context.TODO(), findSql)
+		defer rows.Close()
+		if err != nil {
+			return nil, false, 0
+		}
+		for rows.Next() {
+			project := ProjectEntry{}
+			_ = rows.ScanStruct(&project)
+			resultList = append(resultList, &project)
+		}
+		redis.Put("newother", rkey, resultList, T.C.CacheTimeOut)
 	}
 
-	resultList = filterData(req, resultList, preSales, mmp, isSqlPage)
-	if !isSqlPage {
-		total = len(resultList)
-		if total > req.PageSize {
-			hasNextPage = true
-			start := (req.PageNum - 1) * req.PageSize
-			end := req.PageNum * req.PageSize
-			if end > total {
-				end = total
-				hasNextPage = false
-			}
-			resultList = resultList[start:end]
-		} else {
-			hasNextPage = false
-		}
+	resultList = filterData(req, resultList, nil, mmp, true)
+	//if !isSqlPage {
+	//total = len(resultList)
+	//if total > req.PageSize {
+	//	hasNextPage = true
+	//	start := (req.PageNum - 1) * req.PageSize
+	//	end := req.PageNum * req.PageSize
+	//	if end > total {
+	//		end = total
+	//		hasNextPage = false
+	//	}
+	//	resultList = resultList[start:end]
+	//} else {
+	//	hasNextPage = false
+	//}
+	//} else {
+	total = int(T.NetworkCom.Count(countSql))
+	if total > req.PageSize {
+		hasNextPage = true
 	} else {
-		total = int(T.NetworkCom.Count(countSql))
-		if total > req.PageSize {
-			hasNextPage = true
-		} else {
-			hasNextPage = false
-		}
+		hasNextPage = false
 	}
+	//}
 	moreInfo(req, plist, resultList) //  补充信息
 
 	return
@@ -286,11 +296,11 @@ func filterData(req *types.ProjectListReq, resultList []*ProjectEntry, preSales,
 	}
 	for _, m := range resultList {
 		// 处理/忽略/销售机会
-		if m1, ok := preSales[m.ProjectId].(map[string]interface{}); ok {
-			m.IsIgnore = common.IntAll(m1["is_handle"])
-			m.IsIgnore = common.IntAll(m1["is_ignore"])
-			m.IsCreate = common.IntAll(m1["is_create"])
-		}
+		//if m1, ok := preSales[m.ProjectId].(map[string]interface{}); ok {
+		//	m.IsIgnore = common.IntAll(m1["is_handle"])
+		//	m.IsIgnore = common.IntAll(m1["is_ignore"])
+		//	m.IsCreate = common.IntAll(m1["is_create"])
+		//}
 		// 监控
 		for _, s := range strings.Split(m.InfoId, ",") {
 			if mmp[s] != nil {
@@ -355,7 +365,6 @@ func moreInfo(req *types.ProjectListReq, plist []string, list []*ProjectEntry) (
 			}
 		}
 	}
-	logx.Info(connMap)
 	for _, m := range list {
 		// 中间人的项目 默认 我的人脉
 		if len(plist) > 0 {
@@ -368,9 +377,9 @@ func moreInfo(req *types.ProjectListReq, plist []string, list []*ProjectEntry) (
 			}
 		}
 		// 补充跳转链接
-		if m.BusinessType == "采购意向" || m.BusinessType == "招标项目" {
-			m.Href = fmt.Sprintf("/article/content/%s.html", encrypt.CommonEncodeArticle("content", m.ProjectId))
-		}
+		//if m.BusinessType == "采购意向" || m.BusinessType == "招标项目" {
+		m.Href = fmt.Sprintf("/article/content/%s.html", encrypt.CommonEncodeArticle("content", m.InfoId))
+		//}
 		m.ProjectId = util.EncodeId(m.ProjectId)
 		// 人脉、人脉所在单位项目 conn_type: 1 人脉可转介绍项目; conn_type: 2 人脉所在单位项目
 		if !m.MyConn {

+ 4 - 4
api/internal/service/prListService.go

@@ -13,15 +13,15 @@ import (
 )
 
 var (
-	esQ1      = `{"query": {"bool": {"must": [{"terms": {"buyer": ["%s"]}},{"terms": {"toptype": ["采购意向","预告","招标"]}}], "should": [%s], "minimum_should_match": 1}}, "_source": ["%s"], "sort": {"comeintime": {"order": "desc"}}, "from": %d, "size": %d}`
-	esQ2      = `{"query": {"bool": {"must": [{"terms": {"buyer": ["%s"]}},{"terms": {"toptype": ["采购意向","预告","招标"]}}]}}, "_source": ["%s"], "sort": {"comeintime": {"order": "desc"}}, "from": %d, "size": %d}`
+	esQ1      = `{"query": {"bool": {"must": [{"terms": {"buyer": ["%s"]}},{"terms": {"toptype": ["采购意向","预告","招标"]}}], "should": [%s], "minimum_should_match": 1}}, "_source": ["%s"], "sort": {"publishtime": {"order": "desc"}}, "from": %d, "size": %d}`
+	esQ2      = `{"query": {"bool": {"must": [{"terms": {"buyer": ["%s"]}},{"terms": {"toptype": ["采购意向","预告","招标"]}}]}}, "_source": ["%s"], "sort": {"publishtime": {"order": "desc"}}, "from": %d, "size": %d}`
 	shouldMul = `{"multi_match": {"query": "%s","type": "phrase", "fields": ["s_topscopeclass"]}}`
 	fields    = []string{"_id", "title", "publishtime", "dataweight", "detail", "site", "spidercode", "toptype", "subtype", "type", "area", "city", "district", "s_topscopeclass", "s_subscopeclass", "bidamount", "budget", "buyerclass", "buyer", "winner", "bidopentime", "buyertel", "buyerperson", "agency", "agencytel", "agencyperson", "s_winner", "winnertel", "winnerperson", "signendtime", "bidendtime", "projectinfo", "entidlist"}
 )
 
 func GetMonitorList(req *types.PrMonitorListReq) (resultList []map[string]interface{}, total int64, hasMonitor bool) {
 
-	bList, b := T.Mgo.Find("follow_customer", map[string]interface{}{"userId": req.MgoUserId}, `{_id: 1}`, nil, false, -1, -1)
+	bList, b := T.Mgo.Find("follow_customer", map[string]interface{}{"userId": req.UserId}, `{_id: 1}`, nil, false, -1, -1)
 	if b && len(*bList) > 0 {
 		hasMonitor = true
 		var bName []string
@@ -32,7 +32,7 @@ func GetMonitorList(req *types.PrMonitorListReq) (resultList []map[string]interf
 		}
 		pageStart := (req.PageNum - 1) * req.PageSize
 		esQuery1 := ""
-		scopeClass := FindBusiness(req.EntId, req.MgoUserId)
+		scopeClass := FindBusiness(req.EntId, req.UserId)
 		if scopeClass != "" {
 			var should []string
 			for _, v := range strings.Split(scopeClass, ",") {

+ 4 - 4
api/internal/types/types.go

@@ -42,11 +42,11 @@ type AssociateReq struct {
 type CoopHistoryReq struct {
 	EntAccountId int64  `header:"entAccountId,optional"` //企业账户id
 	PositionId   int64  `header:"positionId,optional"`
-	EntId        string `header:"entId,optional"`
+	EntId        int64  `header:"entId,optional"`
 	EntUserId    string `header:"entUserId,optional"`
 	DeptId       string `header:"deptId,optional"` //部门id
-	Pid          string `json:"projectId"`
-	Bid          string `json:"infoId"`
+	Pid          string `json:"projectId,optional"`
+	Bid          string `json:"infoId,optional"`
 	ChannelType  string `json:"channelType"`
 }
 
@@ -128,7 +128,7 @@ type PrCollectListReq struct {
 }
 
 type PrMonitorListReq struct {
-	MgoUserId  string `header:"mgoUserId,optional"`
+	UserId     string `header:"userId,optional"`
 	PositionId int64  `header:"positionId,optional"`
 	EntId      int64  `header:"entId,optional"`
 	PageSize   int    `json:"pageSize"`

+ 4 - 4
api/networkmanage.api

@@ -55,11 +55,11 @@ type (
 	CoopHistoryReq {
 		EntAccountId int64  `header:"entAccountId,optional"` //企业账户id
 		PositionId   int64  `header:"positionId,optional"`
-		EntId        string `header:"entId,optional"`
+		EntId        int64  `header:"entId,optional"`
 		EntUserId    string `header:"entUserId,optional"`
 		DeptId       string `header:"deptId,optional"` //部门id
-		Pid          string `json:"projectId"`
-		Bid          string `json:"infoId"`
+		Pid          string `json:"projectId,optional"`
+		Bid          string `json:"infoId,optional"`
 		ChannelType  string `json:"channelType"`
 	}
 	AddOrUpdateReq {
@@ -163,7 +163,7 @@ type (
 		EntRole      int64  `header:"entRole,optional"`
 	}
 	PrMonitorListReq {
-		MgoUserId  string `header:"mgoUserId,optional"`
+		UserId     string `header:"userId,optional"`
 		PositionId int64  `header:"positionId,optional"`
 		EntId      int64  `header:"entId,optional"`
 		PageSize   int    `json:"pageSize"`