|
@@ -94,7 +94,6 @@ func (t *OwnerService) OwnerlList() *OwnerlListRes {
|
|
|
if t.PageIndex == 0 {
|
|
|
t.PageIndex = 1
|
|
|
}
|
|
|
- startIndex := (t.PageIndex - 1) * t.PageSize
|
|
|
olr := &OwnerlListRes{
|
|
|
ReturnData: []BuyerProject{},
|
|
|
}
|
|
@@ -106,30 +105,30 @@ func (t *OwnerService) OwnerlList() *OwnerlListRes {
|
|
|
monitorMap := NetworkCom.EntMonitor(gconv.String(t.PositionId))
|
|
|
comKey := common.GetMd5String(fmt.Sprintf("%+v business:%s", t, businessStr))
|
|
|
listKey := fmt.Sprintf(NetworkManageOwnerlList, t.PositionId, comKey)
|
|
|
- // 检查 Redis 中是否存在列表缓存
|
|
|
- if ok, err := redis.Exists("newother", listKey); ok && err == nil && t.SourceType != "2" {
|
|
|
- olr = handleRedisCache(listKey)
|
|
|
+ getFromCache := false
|
|
|
+ monitorBuyers := []string{}
|
|
|
+ if t.SourceType != "2" {
|
|
|
+ // 检查 Redis 中是否存在列表缓存
|
|
|
+ if rb, err := redis.GetNewBytes("newother", listKey); err == nil && rb != nil {
|
|
|
+ if json.Unmarshal(*rb, &olr) == nil {
|
|
|
+ getFromCache = true
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
- // 没有缓存时的处理逻辑
|
|
|
- if t.PartyA == "" && t.Supplier == "" && t.Heterotophy == "" && t.Intermediary == "" && t.Agency == "" {
|
|
|
- return olr
|
|
|
+ for k, _ := range monitorMap {
|
|
|
+ monitorBuyers = append(monitorBuyers, k)
|
|
|
}
|
|
|
+ }
|
|
|
+ // 没有缓存时的处理逻辑
|
|
|
+ if !getFromCache {
|
|
|
dataMap := BuyerList(t.PartyA, t.Intermediary, t.PositionId)
|
|
|
- // 监控状态处理
|
|
|
- if t.SourceType == "2" {
|
|
|
- for k, v := range *dataMap {
|
|
|
- if _, ok1 := monitorMap[gconv.String(v["buyerName"])]; !ok1 {
|
|
|
- delete(*dataMap, k)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if len(*dataMap) == 0 {
|
|
|
+ if len(*dataMap) == 0 && t.Supplier == "" && t.Heterotophy == "" && t.Agency == "" {
|
|
|
return olr
|
|
|
}
|
|
|
// 项目数量查询
|
|
|
buyerArr := getBuyerArr(dataMap)
|
|
|
// 项目数量处理
|
|
|
- projectMap, connectionsNumber := ProjectHandle(t.Supplier, t.Heterotophy, t.Agency, buyerArr, t.Area, businessStr, dataMap, startIndex, t.PageSize, t.SourceType)
|
|
|
+ projectMap, connectionsNumber := t.ProjectHandle(buyerArr, businessStr, monitorBuyers)
|
|
|
endTime := time.Now().Unix()
|
|
|
fmt.Println("用时时间:", endTime-startTime)
|
|
|
if len(*projectMap) == 0 {
|
|
@@ -176,19 +175,6 @@ func (t *OwnerService) OwnerlList() *OwnerlListRes {
|
|
|
return olr
|
|
|
}
|
|
|
|
|
|
-// handleRedisCache 处理从 Redis 中获取缓存数据的逻辑
|
|
|
-func handleRedisCache(key string) *OwnerlListRes {
|
|
|
- ols := &OwnerlListRes{}
|
|
|
- if bytes, err := redis.GetNewBytes("newother", key); err == nil && bytes != nil {
|
|
|
- err = json.Unmarshal(*bytes, &ols)
|
|
|
- if err != nil {
|
|
|
- // 处理解组错误
|
|
|
- fmt.Println("Error unmarshaling from Redis:", err)
|
|
|
- }
|
|
|
- }
|
|
|
- return ols
|
|
|
-}
|
|
|
-
|
|
|
// getBuyerArr 从数据映射中获取买家数组
|
|
|
func getBuyerArr(dataMap *map[string]map[string]interface{}) []string {
|
|
|
buyerArr := []string{}
|
|
@@ -695,58 +681,66 @@ func BuyerList(partyA, intermediary string, positionId int64) *map[string]map[st
|
|
|
}
|
|
|
|
|
|
// 项目数量查
|
|
|
-func ProjectHandle(supplier, heterotophy, agency string, buyerArr []string, area, businessStr string, dataMap *map[string]map[string]interface{}, startIndex, PageSize int64, sourceType string) (*map[string]map[string]interface{}, int64) {
|
|
|
+func (t *OwnerService) ProjectHandle(buyerArr []string, businessStr string, monitorBuyers []string) (*map[string]map[string]interface{}, int64) {
|
|
|
projectMap := &map[string]map[string]interface{}{}
|
|
|
- count := int64(0)
|
|
|
- tscSql := `'` + strings.ReplaceAll(businessStr, ",", `','`) + `'`
|
|
|
- sqlStr := `select buyer,buyer_id,groupUniqArray(area) as areaStr,count(if(hasAny(topscopeclass,[`
|
|
|
- sqlStr += tscSql + `])=1 and project_bidstatus>1,1,null)) as ocount,SUM(if(hasAny(topscopeclass,[`
|
|
|
- sqlStr += tscSql + `])=1 and project_bidstatus>1,project_money,0)) as project_money,MAX(zbtime) as zbtime from transaction_info_all where (`
|
|
|
- allArgs := []interface{}{}
|
|
|
+ startIndex := (t.PageIndex - 1) * t.PageSize
|
|
|
+ whBs, allArgs := common.WhArgs(strings.Split(businessStr, ","))
|
|
|
+ allArgs = append(allArgs, allArgs...)
|
|
|
+ sqlStr := `select b.buyer as buyer,b.buyer_id as buyer_id,groupUniqArray(b.area) as areaStr,count(if(hasAny(b.topscopeclass,[`
|
|
|
+ sqlStr += whBs + `])=1 and b.project_bidstatus>1,1,null)) as ocount,SUM(if(hasAny(b.topscopeclass,[`
|
|
|
+ sqlStr += whBs + `])=1 and b.project_bidstatus>1,b.project_money,0)) as project_money,MAX(b.zbtime) as zbtime from transaction_info_all a inner join transaction_info_all b on ((`
|
|
|
ors := []string{}
|
|
|
if len(buyerArr) > 0 {
|
|
|
wh, args := common.WhArgs(buyerArr)
|
|
|
- ors = append(ors, `buyer_id in (`+wh+`)`)
|
|
|
+ ors = append(ors, `a.buyer_id in (`+wh+`)`)
|
|
|
allArgs = append(allArgs, args...)
|
|
|
}
|
|
|
winner_ids := []string{}
|
|
|
- if supplier != "" {
|
|
|
- winner_ids = append(winner_ids, strings.Split(supplier, ",")...)
|
|
|
+ if t.Supplier != "" {
|
|
|
+ winner_ids = append(winner_ids, strings.Split(t.Supplier, ",")...)
|
|
|
}
|
|
|
- if heterotophy != "" {
|
|
|
- winner_ids = append(winner_ids, strings.Split(heterotophy, ",")...)
|
|
|
+ if t.Heterotophy != "" {
|
|
|
+ winner_ids = append(winner_ids, strings.Split(t.Heterotophy, ",")...)
|
|
|
}
|
|
|
if len(winner_ids) > 0 {
|
|
|
wh, args := common.WhArgs(winner_ids)
|
|
|
- ors = append(ors, `hasAny(winner_id,[`+wh+`]`)
|
|
|
+ ors = append(ors, `hasAny(a.winner_id,[`+wh+`]`)
|
|
|
+ allArgs = append(allArgs, args...)
|
|
|
+ }
|
|
|
+ if t.Agency != "" {
|
|
|
+ wh, args := common.WhArgs(strings.Split(t.Agency, ","))
|
|
|
+ ors = append(ors, `a.agency_id in (`+wh+`)`)
|
|
|
allArgs = append(allArgs, args...)
|
|
|
}
|
|
|
- if agency != "" {
|
|
|
- wh, args := common.WhArgs(strings.Split(agency, ","))
|
|
|
- ors = append(ors, `agency_id in (`+wh+`)`)
|
|
|
+ sqlStr += strings.Join(ors, " or ") + ") and a.buyer_id<>'' and a.buyer_id=b.buyer_id)"
|
|
|
+ wheres := []string{}
|
|
|
+ if len(monitorBuyers) > 0 {
|
|
|
+ wh, args := common.WhArgs(monitorBuyers)
|
|
|
+ wheres = append(wheres, `b.buyer in (`+wh+`)`)
|
|
|
allArgs = append(allArgs, args...)
|
|
|
}
|
|
|
- sqlStr += strings.Join(ors, " or ")
|
|
|
- if area != "" {
|
|
|
- wh, args := common.WhArgs(strings.Split(area, ","))
|
|
|
- sqlStr += `) and area in (` + wh + `)`
|
|
|
+ if t.Area != "" {
|
|
|
+ wh, args := common.WhArgs(strings.Split(t.Area, ","))
|
|
|
+ wheres = append(wheres, `b.area in (`+wh+`)`)
|
|
|
allArgs = append(allArgs, args...)
|
|
|
}
|
|
|
- sqlStr += " GROUP by buyer,buyer_id "
|
|
|
- if sourceType == "1" {
|
|
|
+ if len(wheres) > 0 {
|
|
|
+ sqlStr += " where " + strings.Join(wheres, " and ")
|
|
|
+ }
|
|
|
+ sqlStr += " GROUP by b.buyer,b.buyer_id"
|
|
|
+ if t.SourceType == "1" {
|
|
|
sqlStr += " HAVING ocount>2 "
|
|
|
}
|
|
|
- sqlStr += " order by zbtime desc"
|
|
|
countSql := fmt.Sprintf("select count(1) as count from (%s) b ", sqlStr)
|
|
|
- sqlStr += " limit ?,?"
|
|
|
+ sqlStr += fmt.Sprintf(" order by zbtime desc limit %d,%d", startIndex, t.PageSize)
|
|
|
//总数查询
|
|
|
- rows, err1 := ClickhouseConn.Query(context.TODO(), sqlStr, startIndex, PageSize)
|
|
|
- count = T.NetworkCom.Count(countSql)
|
|
|
+ ass := []BuyerAggStruct{}
|
|
|
+ rows, err1 := ClickhouseConn.Query(context.TODO(), sqlStr, allArgs...)
|
|
|
if err1 != nil {
|
|
|
logx.Error(err1)
|
|
|
- return projectMap, count
|
|
|
+ return projectMap, 0
|
|
|
}
|
|
|
- ass := []BuyerAggStruct{}
|
|
|
+ defer rows.Close()
|
|
|
for rows.Next() {
|
|
|
as := BuyerAggStruct{}
|
|
|
if err := rows.ScanStruct(&as); err != nil {
|
|
@@ -755,7 +749,6 @@ func ProjectHandle(supplier, heterotophy, agency string, buyerArr []string, area
|
|
|
}
|
|
|
ass = append(ass, as)
|
|
|
}
|
|
|
- defer rows.Close()
|
|
|
for _, object := range ass {
|
|
|
buyerName := object.Buyer
|
|
|
buyerId := object.BuyerId
|
|
@@ -769,7 +762,7 @@ func ProjectHandle(supplier, heterotophy, agency string, buyerArr []string, area
|
|
|
"buyerName": buyerName,
|
|
|
}
|
|
|
}
|
|
|
- return projectMap, count
|
|
|
+ return projectMap, T.NetworkCom.Count(countSql, allArgs...)
|
|
|
}
|
|
|
|
|
|
type BuyerAggStruct struct {
|