소스 검색

wip:采购单位默认搜索展示 二级缓存+聚合查询

wangkaiyue 1 년 전
부모
커밋
472dbc6fb0
2개의 변경된 파일13개의 추가작업 그리고 3개의 파일을 삭제
  1. 12 2
      jyBXBuyer/rpc/internal/logic/buyerlistlogic.go
  2. 1 1
      jyBXBuyer/rpc/model/redisL2Cache.go

+ 12 - 2
jyBXBuyer/rpc/internal/logic/buyerlistlogic.go

@@ -62,7 +62,7 @@ func (l *BuyerListLogic) BuyerList(in *bxbuyer.BuyerListReq) (*bxbuyer.BuyerList
 	if model.CheckEmpty(in) {
 		res := model.GetL2CacheData("other", model.BuyerListQueryLock, model.P_redis_key, func() interface{} {
 			//聚合查询获取最近一个月中标单位数量最多的采购单位
-			agg := model.GetAggs("projectset", "projectset", fmt.Sprintf(`{"query":{"bool":{"must":[{"range":{"jgtime":{"gt":%d}}}]}},"aggs":{"buyerTop":{"terms":{"field":"buyer","size":%d}}}}`, time.Now().AddDate(-3, 0, -1).Unix(), IC.C.BuyerSearchLimit))
+			agg := model.GetAggs("projectset", "projectset", fmt.Sprintf(`{"query":{"bool":{"must":[{"range":{"jgtime":{"gt":%d}}}]}},"aggs":{"buyerTop":{"terms":{"field":"buyer","size":%d}}}}`, time.Now().AddDate(0, 0, -1).Unix(), IC.C.BuyerSearchLimit*2))
 			var ta TopAgg
 			err := gconv.Struct(gconv.String(agg["buyerTop"]), &ta)
 			if err != nil {
@@ -73,9 +73,16 @@ func (l *BuyerListLogic) BuyerList(in *bxbuyer.BuyerListReq) (*bxbuyer.BuyerList
 				names = append(names, bucket.Key)
 			}
 			//根据采购单位名称查询列表展示字段
-			rs := elastic.Get(model.BuyerIndex, model.BuyerIndex, fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"buyer_name":["%s"]}}]}},"source":["seo_id","name","province","city","buyerclass"]}`, strings.Join(names, `","`)))
+			rs := elastic.Get(model.BuyerIndex, model.BuyerIndex, fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"buyer_name":["%s"]}}]}},"_source":["seo_id","name","province","city","buyerclass"],"size":%d}`, strings.Join(names, `","`), len(names)))
+			if rs == nil || len(*rs) == 0 {
+				return nil
+			}
 			var saveBuyerList []*bxbuyer.BuyerList
 			for i := 0; i < len(*rs); i++ {
+				name := MC.ObjToString((*rs)[i]["name"])
+				if !(len(name) > 5 && (strings.HasSuffix(name, "公司") || strings.HasSuffix(name, "学校") || strings.HasSuffix(name, "医院"))) {
+					continue
+				}
 				saveBuyerList = append(saveBuyerList, &bxbuyer.BuyerList{
 					SeoId:      MC.ObjToString((*rs)[i]["seo_id"]),
 					Buyer:      MC.ObjToString((*rs)[i]["name"]),
@@ -83,6 +90,9 @@ func (l *BuyerListLogic) BuyerList(in *bxbuyer.BuyerListReq) (*bxbuyer.BuyerList
 					City:       MC.ObjToString((*rs)[i]["city"]),
 					BuyerClass: MC.ObjToString((*rs)[i]["buyerclass"]),
 				})
+				if gconv.Int64(len(saveBuyerList)) > IC.C.BuyerSearchLimit {
+					break
+				}
 			}
 			return saveBuyerList
 		}, model.P_redis_time)

+ 1 - 1
jyBXBuyer/rpc/model/redisL2Cache.go

@@ -17,7 +17,7 @@ func GetL2CacheData(dbName string, lock *sync.RWMutex, key string, f func() inte
 		data    = gvar.New(redis.Get(dbName, key))
 		newData *gvar.Var
 	)
-	if data == nil {
+	if data.IsEmpty() {
 		data = gvar.New(redis.Get(dbName, fmt.Sprintf("%s_L2Cache", key)))
 		go func() {
 			if lock.TryLock() {