|
@@ -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
|
|
|
}
|
|
|
|