Explorar o código

Merge branch 'dev/v1.1.26_fuwencai' of BaseService/jyMicroservices into feature/v1.1.26

wangshan %!s(int64=2) %!d(string=hai) anos
pai
achega
a10e48f74b

+ 6 - 9
jyBXBuyer/rpc/internal/logic/buyerlistlogic.go

@@ -39,8 +39,11 @@ func (l *BuyerListLogic) BuyerList(in *bxbuyer.BuyerListReq) (*bxbuyer.BuyerList
 	if in.PageNum < 1 {
 		in.PageNum = 1
 	}
-	if in.PageSize < 1 || in.PageSize > IC.C.BuyerSearchLimit {
-		in.PageSize = IC.C.BuyerSearchLimit / in.PageNum
+	if in.PageSize > 100 || in.PageSize < 1 {
+		in.PageSize = 10
+	}
+	if in.PageSize > IC.C.BuyerSearchLimit {
+		in.PageSize = IC.C.BuyerSearchLimit
 	}
 	query, CountQuery := "", ""
 	buyerNames := []string{}
@@ -73,13 +76,7 @@ func (l *BuyerListLogic) BuyerList(in *bxbuyer.BuyerListReq) (*bxbuyer.BuyerList
 			}
 		}
 		if isBool {
-			/*
-				空搜索
-				1. 聚合出来200条采购单位数据  项目数量 采购单位规模 可以直接一块出来
-				2. 查采购单位库确认100条数据有效
-				3. 存一周缓存
-			*/
-			query = model.BuyerListRedisCacheQuery(in.PageNum, in.PageSize)
+			query = model.BuyerListRedisCacheQuery()
 			buyerNames, resp = model.BuyerListRedisCache(query, in)
 
 		}

+ 111 - 74
jyBXBuyer/rpc/model/buyerListBYEs.go

@@ -158,6 +158,101 @@ func GetBuyerList(qstr string, CountQuery string, isCache bool) (buyerNames []st
 }
 
 // BuyerListRedisCache 空搜索 1.查询项目数量最多的前200个 2.然后 再查buyer里确认数据有效 100个 3.项目数量和采购规模单独存缓存 1天
+//
+//	func BuyerListRedisCache(query string, in *bxbuyer.BuyerListReq) (buyerNames []string, resp *bxbuyer.BuyerListResp) {
+//		//获取缓存数据
+//		resp = &bxbuyer.BuyerListResp{
+//			Data: &bxbuyer.BuyerData{
+//				List: []*bxbuyer.BuyerList{},
+//			},
+//		}
+//		t1 := time.Now()
+//		logx.Info("耗时1:", time.Since(t1))
+//		aggs := GetAggs(P_INDEX, P_TYPE, query)
+//		logx.Info("查询语句:", query)
+//		logx.Info("BuyerListRedisCache:", time.Since(t1))
+//		type BuyerAggStruct struct {
+//			Buckets []struct {
+//				Key            string `json:"key,omitempty"`
+//				Doc_count      int64  `json:"doc_count,omitempty"`
+//				BidAmountCount struct {
+//					Value float32 `json:"value,omitempty"`
+//				} `json:"bidAmountCount"`
+//			} `json:"buckets"`
+//		}
+//		var buyerBuckets = BuyerAggStruct{}
+//		saveBuyerList := []*bxbuyer.BuyerList{} //100条数据 最后存起来
+//		// 处理成map 用于后面格式化数据
+//		if aggs == nil || aggs["buyerBuckets"] == nil {
+//			return
+//		}
+//		bs, err := aggs["buyerBuckets"].MarshalJSON()
+//		if err != nil {
+//			resp.ErrCode = -1
+//			resp.ErrMsg = "获取数据异常"
+//			return
+//		}
+//		if len(bs) == 0 {
+//			resp.ErrMsg = "暂无数据"
+//			return
+//		}
+//		err = json.Unmarshal(bs, &buyerBuckets)
+//		if err != nil || len(buyerBuckets.Buckets) == 0 {
+//			resp.ErrMsg = "暂无数据"
+//			return
+//		}
+//		for i := 0; i < len(buyerBuckets.Buckets); i++ {
+//			if len(saveBuyerList) == int(IC.C.BuyerSearchLimit) {
+//				break
+//			}
+//			// 查buyer  确认数据存在 补充 buyerclass 省份 城市信息
+//			rs := GetBuyer(buyerBuckets.Buckets[i].Key)
+//			if rs != nil && len(*rs) > 0 { // 存在 则追加
+//				tmpBuyerInfo := (*rs)[0]
+//				buyerInfo := &bxbuyer.BuyerList{
+//					Buyer:      buyerBuckets.Buckets[i].Key,
+//					Province:   MC.ObjToString(tmpBuyerInfo["province"]),
+//					City:       MC.ObjToString(tmpBuyerInfo["city"]),
+//					BuyerClass: MC.ObjToString(tmpBuyerInfo["buyerclass"]),
+//				}
+//				saveBuyerList = append(saveBuyerList, buyerInfo)
+//				buyerNames = append(buyerNames, buyerInfo.Buyer)
+//				// 项目数量和采购规模存缓存 1天
+//				projectCacheData := supplyDataStruct{
+//					ProjectCount:   buyerBuckets.Buckets[i].Doc_count,
+//					BidAmountCount: buyerBuckets.Buckets[i].BidAmountCount.Value,
+//				}
+//				go func(buyer string, data supplyDataStruct) {
+//					b, err := json.Marshal(data)
+//					if err == nil {
+//						redis.PutBytes("other", fmt.Sprintf(BuyerProjectInfoRedisKey, buyer), &b, BuyerProjectInfoRedisTime+GetRand(60))
+//					}
+//				}(buyerBuckets.Buckets[i].Key, projectCacheData)
+//
+//			}
+//		}
+//		if len(saveBuyerList) > 0 {
+//			//  100 列表存redis 7天
+//			go func(data []*bxbuyer.BuyerList) {
+//				b, err := json.Marshal(data)
+//				if err == nil {
+//					redis.PutBytes("other", fmt.Sprintf(P_redis_key), &b, P_redis_time)
+//				}
+//			}(saveBuyerList)
+//		} else {
+//			return
+//		}
+//
+//		// 根据页码返回数据
+//		start := in.PageSize * (in.PageNum - 1)
+//		end := in.PageSize * in.PageNum
+//		resp.Data.Count = int64(len(saveBuyerList))
+//		if end > int64(len(saveBuyerList)-1) {
+//			end = int64(len(saveBuyerList) - 1)
+//		}
+//		resp.Data.List = saveBuyerList[start:end]
+//		return
+//	}
 func BuyerListRedisCache(query string, in *bxbuyer.BuyerListReq) (buyerNames []string, resp *bxbuyer.BuyerListResp) {
 	//获取缓存数据
 	resp = &bxbuyer.BuyerListResp{
@@ -166,69 +261,21 @@ func BuyerListRedisCache(query string, in *bxbuyer.BuyerListReq) (buyerNames []s
 		},
 	}
 	t1 := time.Now()
-	logx.Info("耗时1:", time.Since(t1))
-	aggs := GetAggs(P_INDEX, P_TYPE, query)
-	logx.Info("查询语句:", query)
-	logx.Info("BuyerListRedisCache:", time.Since(t1))
-	type BuyerAggStruct struct {
-		Buckets []struct {
-			Key            string `json:"key,omitempty"`
-			Doc_count      int64  `json:"doc_count,omitempty"`
-			BidAmountCount struct {
-				Value float32 `json:"value,omitempty"`
-			} `json:"bidAmountCount"`
-		} `json:"buckets"`
-	}
-	var buyerBuckets = BuyerAggStruct{}
-	saveBuyerList := []*bxbuyer.BuyerList{} //100条数据 最后存起来
-	// 处理成map 用于后面格式化数据
-	if aggs == nil || aggs["buyerBuckets"] == nil {
-		return
-	}
-	bs, err := aggs["buyerBuckets"].MarshalJSON()
-	if err != nil {
-		resp.ErrCode = -1
-		resp.ErrMsg = "获取数据异常"
-		return
-	}
-	if len(bs) == 0 {
-		resp.ErrMsg = "暂无数据"
-		return
-	}
-	err = json.Unmarshal(bs, &buyerBuckets)
-	if err != nil || len(buyerBuckets.Buckets) == 0 {
-		resp.ErrMsg = "暂无数据"
+	rs := elastic.Get(BuyerIndex, BuyerType, query) // 采购单位列表
+	logx.Info("空搜索采购单位列表 es get查询耗时", time.Since(t1))
+	if rs == nil || len(*rs) == 0 {
 		return
 	}
-	for i := 0; i < len(buyerBuckets.Buckets); i++ {
-		if len(saveBuyerList) == int(IC.C.BuyerSearchLimit) {
-			break
-		}
-		// 查buyer  确认数据存在 补充 buyerclass 省份 城市信息
-		rs := GetBuyer(buyerBuckets.Buckets[i].Key)
-		if rs != nil && len(*rs) > 0 { // 存在 则追加
-			tmpBuyerInfo := (*rs)[0]
-			buyerInfo := &bxbuyer.BuyerList{
-				Buyer:      buyerBuckets.Buckets[i].Key,
-				Province:   MC.ObjToString(tmpBuyerInfo["province"]),
-				City:       MC.ObjToString(tmpBuyerInfo["city"]),
-				BuyerClass: MC.ObjToString(tmpBuyerInfo["buyerclass"]),
-			}
-			saveBuyerList = append(saveBuyerList, buyerInfo)
-			buyerNames = append(buyerNames, buyerInfo.Buyer)
-			// 项目数量和采购规模存缓存 1天
-			projectCacheData := supplyDataStruct{
-				ProjectCount:   buyerBuckets.Buckets[i].Doc_count,
-				BidAmountCount: buyerBuckets.Buckets[i].BidAmountCount.Value,
-			}
-			go func(buyer string, data supplyDataStruct) {
-				b, err := json.Marshal(data)
-				if err == nil {
-					redis.PutBytes("other", fmt.Sprintf(BuyerProjectInfoRedisKey, buyer), &b, BuyerProjectInfoRedisTime+GetRand(60))
-				}
-			}(buyerBuckets.Buckets[i].Key, projectCacheData)
-
+	saveBuyerList := []*bxbuyer.BuyerList{} //最后缓存起来
+	for i := 0; i < len(*rs); i++ {
+		tmp := &bxbuyer.BuyerList{
+			Buyer:      MC.ObjToString((*rs)[i]["name"]),
+			Province:   MC.ObjToString((*rs)[i]["province"]),
+			City:       MC.ObjToString((*rs)[i]["city"]),
+			BuyerClass: MC.ObjToString((*rs)[i]["buyerclass"]),
 		}
+		buyerNames = append(buyerNames, tmp.Buyer)
+		saveBuyerList = append(saveBuyerList, tmp)
 	}
 	if len(saveBuyerList) > 0 {
 		//  100 列表存redis 7天
@@ -241,7 +288,6 @@ func BuyerListRedisCache(query string, in *bxbuyer.BuyerListReq) (buyerNames []s
 	} else {
 		return
 	}
-
 	// 根据页码返回数据
 	start := in.PageSize * (in.PageNum - 1)
 	end := in.PageSize * in.PageNum
@@ -250,6 +296,7 @@ func BuyerListRedisCache(query string, in *bxbuyer.BuyerListReq) (buyerNames []s
 		end = int64(len(saveBuyerList) - 1)
 	}
 	resp.Data.List = saveBuyerList[start:end]
+	logx.Info("空搜索整体耗时;", time.Since(t1).Seconds(), "秒--", time.Since(t1).Microseconds())
 	return
 }
 
@@ -736,17 +783,7 @@ func CheckEmpty(in *bxbuyer.BuyerListReq) bool {
 //缓存数据查询
 
 // 获取采购单位查询query
-func BuyerListRedisCacheQuery(pageNum, pageSize int64) (qstr string) {
-	qstr = `{"size":0,"query":{"bool":{        "must": [
-            {
-                "range": {
-                    "jgtime": {
-                        "gte": %d,
-                        "lt": %d
-                    }
-                }
-            }
-        ],"must_not":[{"term":{"buyer":""}}]}},"aggs":{"buyerBuckets":{"terms":{"field":"buyer","order":[{"_count":"desc"}],"size":200},"aggs":{"bidAmountCount":{"sum":{"field":"bidamount"}}}}}}`
-	start, end := getTimeRange()
-	return fmt.Sprintf(qstr, start.Unix(), end.Unix())
+func BuyerListRedisCacheQuery() (qstr string) {
+	qstr = `{"size":%d,"query":{"bool":{"must":[],"must_not":[{"term":{"buyer_name":""}}]}},"sort":[{"updatetime":"desc"}]}`
+	return fmt.Sprintf(qstr, IC.C.BuyerSearchLimit)
 }