소스 검색

feat:xiugai

wangchuanjin 9 달 전
부모
커밋
5c4a07bb11
4개의 변경된 파일47개의 추가작업 그리고 41개의 파일을 삭제
  1. 9 9
      api/internal/logic/coophistorylistlogic.go
  2. 30 26
      api/internal/service/CoopHistoryService.go
  3. 2 1
      api/internal/service/network.go
  4. 6 5
      api/internal/service/network_test.go

+ 9 - 9
api/internal/logic/coophistorylistlogic.go

@@ -1,11 +1,12 @@
 package logic
 
 import (
+	"context"
+	"fmt"
+
 	"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/service"
 	"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/svc"
 	"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/types"
-	"context"
-	"fmt"
 
 	"github.com/zeromicro/go-zero/core/logx"
 )
@@ -27,14 +28,13 @@ func NewCoopHistoryListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C
 func (l *CoopHistoryListLogic) CoopHistoryList(req *types.CoopHistoryReq) (resp *types.Reply, err error) {
 	logx.Info(fmt.Sprintf("%+v", req))
 	resp = &types.Reply{}
-	result, size1, size2, size3, size4 := service.GetPrList(req)
+	result := service.GetPrList(req)
 	resp.Data = map[string]interface{}{
-		"list":  result,
-		"size1": size1,
-		"size2": size2,
-		"size3": size3,
-		"size4": size4,
+		"list":  result.Result,
+		"size1": result.Size_1,
+		"size2": result.Size_2,
+		"size3": result.Size_3,
+		"size4": result.Size_4,
 	}
-
 	return
 }

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

@@ -17,6 +17,10 @@ import (
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
+const (
+	NetworkManageCoopHistory = "networkManage_coopHistory_%d_%s"
+)
+
 var (
 	INDEX_1   = "transaction_info_all"
 	sql_2_0   = `SELECT buyer_id FROM information.transaction_info_all WHERE project_id = ?`
@@ -75,8 +79,21 @@ type AggStruct struct {
 	ProjectMoney decimal.Decimal `ch:"project_money"`
 	Zbtime       int64           `ch:"zbtime"`
 }
+type PrListRes struct {
+	Result []*ResultData
+	Size_1 int64
+	Size_2 int64
+	Size_3 int64
+	Size_4 int64
+}
 
-func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2, size_3, size_4 int64) {
+func GetPrList(req *types.CoopHistoryReq) *PrListRes {
+	redisKey := fmt.Sprintf(NetworkManageCoopHistory, req.PositionId, common.GetMd5String(fmt.Sprintf("%+v", req)))
+	prListRes := &PrListRes{}
+	if rb, re := redis.GetNewBytes("newother", redisKey); re == nil && rb != nil {
+		json.Unmarshal(*rb, &re)
+		return prListRes
+	}
 	pTmp := ProjectTmp{}
 	var err error
 	if req.Pid != "" {
@@ -84,10 +101,10 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 	} else if req.Buyer != "" {
 		err = T.ClickhouseConn.QueryRow(context.TODO(), sql_2_2, req.Buyer).ScanStruct(&pTmp)
 	} else {
-		return
+		return prListRes
 	}
 	if err != nil || pTmp.BuyerId == "" {
-		return
+		return prListRes
 	}
 	// firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构 sup_sub: 上下级
 	// 1、同甲异业数据/ 3、招标代理机构渠道
@@ -95,7 +112,7 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 	if req.ChannelType == "0" || req.ChannelType == "4" {
 		var r3 []map[string]interface{}
 		r3 = FindMiddleman([]string{fmt.Sprintf("'%s'", pTmp.BuyerId)}, req.PositionId, r3)
-		size_4 = int64(len(r3))
+		prListRes.Size_4 = int64(len(r3))
 		for _, m := range r3 {
 			tmp := ResultData{
 				SourceType:   "middleman",
@@ -105,14 +122,14 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 				Relationship: "业主的关系人",
 				BuyerId:      pTmp.BuyerId,
 			}
-			result = append(result, &tmp)
+			prListRes.Result = append(prListRes.Result, &tmp)
 		}
 	}
 	// 关联单位
 	if req.ChannelType == "0" || req.ChannelType == "2" {
 		var r4 []map[string]interface{}
 		r4 = Findfirstparty([]string{fmt.Sprintf("'%s'", pTmp.BuyerId)}, r4)
-		size_2 = int64(len(r4))
+		prListRes.Size_2 = int64(len(r4))
 		for _, m := range r4 {
 			tmp := ResultData{
 				SourceType:   "sup_sub",
@@ -122,13 +139,13 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 				Relationship: common.ObjToString(m["relationship"]),
 				BuyerId:      pTmp.BuyerId,
 			}
-			result = append(result, &tmp)
+			prListRes.Result = append(prListRes.Result, &tmp)
 		}
 	}
 	if req.ChannelType == "0" || req.ChannelType == "1" {
 		scopeClass := FindBusiness(req.EntId, req.EntUserId)
 		r1 := GetWinnerData(scopeClass, pTmp.BuyerId)
-		size_1 = int64(len(r1))
+		prListRes.Size_1 = int64(len(r1))
 		for _, m := range r1 {
 			tmp := ResultData{
 				SourceType: "adiffb",
@@ -141,12 +158,12 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 			if time.Now().AddDate(-3, 0, 0).Unix() <= tmp.RecentTime {
 				tmp.NearlyYears = true
 			}
-			result = append(result, &tmp)
+			prListRes.Result = append(prListRes.Result, &tmp)
 		}
 	}
 	if req.ChannelType == "0" || req.ChannelType == "3" {
 		r2 := GetAgencyData(pTmp.BuyerId)
-		size_3 = int64(len(r2))
+		prListRes.Size_3 = int64(len(r2))
 		for _, m := range r2 {
 			tmp := ResultData{
 				SourceType: "agency",
@@ -159,22 +176,17 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 			if time.Now().AddDate(-3, 0, 0).Unix() <= tmp.RecentTime {
 				tmp.NearlyYears = true
 			}
-			result = append(result, &tmp)
+			prListRes.Result = append(prListRes.Result, &tmp)
 		}
 	}
-	return
+	redis.Put("newother", redisKey, prListRes, T.C.CacheTimeOut)
+	return prListRes
 }
 func GetWinnerData(scopeClass string, bid string) []AggStruct {
 	ass := []AggStruct{}
 	if scopeClass == "" {
 		return ass
 	}
-	winnerKey := fmt.Sprintf("networkManage_coopHistory_winner_%s", common.GetMd5String(scopeClass+"_"+bid))
-	wb, err := redis.GetBytes("newother", winnerKey)
-	if err == nil && wb != nil {
-		json.Unmarshal(*wb, &ass)
-		return ass
-	}
 	args := []interface{}{bid, bid}
 	wh, newArgs := common.WhArgs(strings.Split(scopeClass, ","))
 	args = append(args, newArgs...)
@@ -196,19 +208,12 @@ func GetWinnerData(scopeClass string, bid string) []AggStruct {
 	if err := rows.Err(); err != nil {
 		logx.Error(err)
 	}
-	redis.Put("newother", winnerKey, ass, T.C.CacheTimeOut)
 	return ass
 }
 
 //代理机构
 func GetAgencyData(bid string) []AggStruct {
 	ass := []AggStruct{}
-	agencyKey := fmt.Sprintf("networkManage_coopHistory_agency_%s", bid)
-	wb, err := redis.GetNewBytes("newother", agencyKey)
-	if err == nil && wb != nil {
-		json.Unmarshal(*wb, &ass)
-		return ass
-	}
 	rows, err1 := T.ClickhouseConn.Query(context.TODO(), `select agency as name,agency_id as id,sum(1) as sum,sum(project_money) as project_money,max(zbtime) as zbtime from information.transaction_info_all where buyer_id=? and agency<>'' and agency_id<>'' GROUP by agency,agency_id`, bid)
 	if err1 != nil {
 		logx.Error(err1)
@@ -226,7 +231,6 @@ func GetAgencyData(bid string) []AggStruct {
 	if err := rows.Err(); err != nil {
 		logx.Error(err)
 	}
-	redis.Put("newother", agencyKey, ass, T.C.CacheTimeOut)
 	return ass
 }
 

+ 2 - 1
api/internal/service/network.go

@@ -1321,5 +1321,6 @@ func (n *network) AllIntroduceOwner(sqlAppend1, sqlAppend2 string, args []interf
 //
 func (n *network) DeleteCache(positionId int64) {
 	redis.Del("newother", fmt.Sprintf(NetworkManageAllProjectKey, positionId))
-	redis.DelByCodePattern("newother", fmt.Sprintf("networkManage_list_%d_%s", positionId, "*"))
+	redis.DelByCodePattern("newother", fmt.Sprintf(NetworkManageList, positionId, "*"))
+	redis.DelByCodePattern("newother", fmt.Sprintf(NetworkManageCoopHistory, positionId, "*"))
 }

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

@@ -143,14 +143,14 @@ func TestProjectHistory(t *testing.T) {
 
 func TestCoopHistoryService(t *testing.T) {
 	InitConf()
-	result, size_1, size_2, size_3, size_4 := GetPrList(&types.CoopHistoryReq{
+	result := GetPrList(&types.CoopHistoryReq{
 		PositionId:  935,
 		EntId:       221,
-		Buyer:       "广州粤华物业有限公司",
+		Buyer:       "武汉市中心医院",
 		ChannelType: "0",
 	})
-	log.Println(size_1, size_2, size_3, size_4)
-	for _, v := range result {
+	log.Println(result.Size_1, result.Size_2, result.Size_3, result.Size_4)
+	for _, v := range result.Result {
 		log.Println(fmt.Sprintf("%+v", v))
 	}
 }
@@ -158,13 +158,14 @@ func TestCoopHistoryService(t *testing.T) {
 func TestInitNetwork(t *testing.T) {
 	//安徽公共资源交易集团项目管理有限公司
 	//广州粤华物业有限公司
+	//
 	InitConf()
 	inw := InitNetwork{
 		PositionId:   935,
 		EntId:        221,
 		DeptId:       498,
 		UserId:       195,
-		EntName:      "安徽公共资源交易集团项目管理有限公司",
+		EntName:      "武汉市中心医院",
 		BusinessType: "建筑工程,机械设备,信息技术",
 	}
 	inw.Init()