Bläddra i källkod

feat:耗时超时

wangshan 3 år sedan
förälder
incheckning
13834fa042

+ 1 - 1
jyBXBuyer/api/etc/bxbuyer-api.yaml

@@ -1,7 +1,7 @@
 Name: bxbuyer-api
 Host: 0.0.0.0
 Port: 8007
-Timeout: 5000
+Timeout: 10000
 Webrpcport: 8017
 Gateway:
   ServerCode: jybxbuyer

+ 4 - 4
jyBXBuyer/rpc/internal/logic/buyerlistlogic.go

@@ -8,7 +8,6 @@ import (
 	"jyBXBuyer/rpc/internal/svc"
 	"jyBXBuyer/rpc/model"
 	"jyBXBuyer/rpc/type/bxbuyer"
-	"log"
 )
 
 type BuyerListLogic struct {
@@ -27,7 +26,7 @@ func NewBuyerListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BuyerLi
 
 // 采购单位搜索
 func (l *BuyerListLogic) BuyerList(in *bxbuyer.BuyerListReq) (*bxbuyer.BuyerListResp, error) {
-	log.Println("----:", model.CheckEmpty(in))
+	logx.Info("----:", model.CheckEmpty(in))
 	query := ""
 	resp := &bxbuyer.BuyerListResp{}
 	if model.CheckEmpty(in) {
@@ -43,7 +42,7 @@ func (l *BuyerListLogic) BuyerList(in *bxbuyer.BuyerListReq) (*bxbuyer.BuyerList
 		}
 		if isBool {
 			query = model.BuyerListRedisCacheQuery()
-			resp = model.GetBuyerList(query, in)
+			resp = model.GetBuyerList(query, in, true)
 			b, err := json.Marshal(resp.Data)
 			if err == nil {
 				redis.PutBytes("other", model.P_redis_key, &b, model.P_redis_time)
@@ -53,7 +52,8 @@ func (l *BuyerListLogic) BuyerList(in *bxbuyer.BuyerListReq) (*bxbuyer.BuyerList
 		}
 	} else {
 		query = model.BuyerListQuery(in)
-		resp = model.GetBuyerList(query, in)
+		//logx.Info("query:", query)
+		resp = model.GetBuyerList(query, in, false)
 	}
 	return &bxbuyer.BuyerListResp{
 		Data:    resp.Data,

+ 36 - 22
jyBXBuyer/rpc/model/buyerListBYEs.go

@@ -12,6 +12,7 @@ import (
 	"runtime"
 	"strings"
 	"sync"
+	"time"
 )
 
 type BScope struct {
@@ -33,11 +34,11 @@ func BuyerListQuery(in *bxbuyer.BuyerListReq) (qstr string) {
 	musts := []string{}
 	//省份
 	if len(in.Province) > 0 {
-		musts = append(musts, fmt.Sprintf(`{"terms":{"area":[%s]}}`, strings.Join(in.Province, ",")))
+		musts = append(musts, fmt.Sprintf(`{"terms":{"area":["%s"]}}`, strings.Join(in.Province, "\",\"")))
 	}
 	//城市
 	if len(in.City) > 0 {
-		musts = append(musts, fmt.Sprintf(`{"terms":{"city":[%s]}}`, strings.Join(in.City, ",")))
+		musts = append(musts, fmt.Sprintf(`{"terms":{"city":["%s"]}}`, strings.Join(in.City, "\",\"")))
 	}
 	//采购单位名称
 	if len(in.BuyerName) > 0 {
@@ -129,11 +130,17 @@ const (
 )
 
 //查询采购单位列表
-func GetBuyerList(qstr string, in *bxbuyer.BuyerListReq) (resp *bxbuyer.BuyerListResp) {
+func GetBuyerList(qstr string, in *bxbuyer.BuyerListReq, isCache bool) (resp *bxbuyer.BuyerListResp) {
+	t1 := time.Now()
 	aggs, count := GetAggs(P_INDEX, P_TYPE, qstr)
-	log.Println(aggs, "=------===", count)
-	if count > int64(len(IC.C.DefaultBuyerNames)) {
-		count = int64(len(IC.C.DefaultBuyerNames))
+	log.Println("=------===", count)
+	if count > IC.C.BuyerCount {
+		count = IC.C.BuyerCount
+	}
+	if isCache {
+		if count > int64(len(IC.C.DefaultBuyerNames)) {
+			count = int64(len(IC.C.DefaultBuyerNames))
+		}
 	}
 	resp = &bxbuyer.BuyerListResp{
 		Data: &bxbuyer.BuyerData{},
@@ -213,6 +220,7 @@ func GetBuyerList(qstr string, in *bxbuyer.BuyerListReq) (resp *bxbuyer.BuyerLis
 		}
 		wg.Wait()
 	}
+	log.Println("耗时;", time.Since(t1).Seconds(), time.Since(t1).Microseconds())
 	return
 }
 
@@ -260,12 +268,14 @@ func GetBuyerInfo(buyerNames []string) (infoMap map[string]buyerInfo) {
 	var buyerInfoQuery = `{"query": {"bool": {"must": [{"terms": {"%s": [%s]}}],"must_not": [],"should": []}},"from": 0,"size": 50,"sort": []}`
 	query := fmt.Sprintf(buyerInfoQuery, "buyer_name", `"`+strings.Join(buyerNames, `","`)+`"`)
 	list := *elastic.Get("buyer", "buyer", query)
-	if len(list) > 0 {
-		infoMap = map[string]buyerInfo{}
-		for _, v := range list {
-			infoMap[v["name"].(string)] = buyerInfo{
-				Province: MC.If(v["province"] != nil, MC.ObjToString(v["province"]), "").(string),
-				City:     MC.If(v["city"] != nil, MC.ObjToString(v["city"]), "").(string),
+	if list != nil {
+		if len(list) > 0 {
+			infoMap = map[string]buyerInfo{}
+			for _, v := range list {
+				infoMap[v["name"].(string)] = buyerInfo{
+					Province: MC.If(v["province"] != nil, MC.ObjToString(v["province"]), "").(string),
+					City:     MC.If(v["city"] != nil, MC.ObjToString(v["city"]), "").(string),
+				}
 			}
 		}
 	} else {
@@ -284,11 +294,13 @@ func IsFollowd(buyerNames []string, userId string) (isFws map[string]bool) {
 		},
 	}
 	list, ok := IC.Mgo.Find(fc, queryMap, `{"_id":1}`, nil, false, -1, -1)
-	if ok && list != nil && len(*list) > 0 {
-		isFws = map[string]bool{}
-		for _, lv := range *list {
-			if MC.ObjToString(lv["name"]) != "" {
-				isFws[MC.ObjToString(lv["name"])] = true
+	if ok && list != nil {
+		if len(*list) > 0 {
+			isFws = map[string]bool{}
+			for _, lv := range *list {
+				if MC.ObjToString(lv["name"]) != "" {
+					isFws[MC.ObjToString(lv["name"])] = true
+				}
 			}
 		}
 	} else {
@@ -305,11 +317,13 @@ var (
 //领取状态
 func IsReceived(buyerNames []string, entUserId string) (isRws map[string]bool) {
 	receInfos := IC.MainMysql.SelectBySql(fmt.Sprintf("SELECT  ecn.name  FROM %s ecn,%s  euu WHERE ecn.id = euu.customer_id AND euu.user_id =? AND ecn.`name` IN  ('%s') AND (euu.source_type =1 or euu.source_type=4)", Entniche_customer, Entniche_user_customer, strings.Join(buyerNames, "','")), entUserId)
-	if len(*receInfos) > 0 {
-		isRws = map[string]bool{}
-		for _, rv := range *receInfos {
-			if MC.ObjToString(rv["name"]) != "" {
-				isRws[MC.ObjToString(rv["name"])] = true
+	if receInfos != nil {
+		if len(*receInfos) > 0 {
+			isRws = map[string]bool{}
+			for _, rv := range *receInfos {
+				if MC.ObjToString(rv["name"]) != "" {
+					isRws[MC.ObjToString(rv["name"])] = true
+				}
 			}
 		}
 	} else {