Browse Source

feat:采购单位搜索

wangshan 2 years ago
parent
commit
50cdbd4c1d

+ 1 - 1
jyBXBuyer/rpc/etc/db.yaml

@@ -1,7 +1,7 @@
 mysql:
     main:
         dbName: jianyu
-        address: 192.168.3.11:3366
+        address: 192.168.3.149:3306
         userName: root
         password: Topnet123
         maxOpenConns: 5

+ 3 - 1
jyBXBuyer/rpc/internal/logic/buyerlistlogic.go

@@ -69,7 +69,9 @@ func (l *BuyerListLogic) BuyerList(in *bxbuyer.BuyerListReq) (*bxbuyer.BuyerList
 		query, CountQuery = model.BuyerListQuery(in)
 		logx.Info("query:", query)
 		resp = model.GetBuyerList(query, CountQuery, in, false) // 查询数据
-		resp = model.SupplyBuyerListData(resp)
+		if len(resp.Data.List) > 0 {
+			model.SupplyBuyerListData(resp)
+		}
 	}
 	if resp.Data.Count > IC.C.BuyerSearchLimit {
 		resp.Data.Count = IC.C.BuyerSearchLimit

+ 50 - 66
jyBXBuyer/rpc/model/buyerListBYEs.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	IC "jyBXBuyer/rpc/init"
 	"jyBXBuyer/rpc/type/bxbuyer"
+	"log"
 	"strconv"
 	"strings"
 	"sync"
@@ -48,8 +49,8 @@ func BuyerListQuery(in *bxbuyer.BuyerListReq) (qstr string, CountQstr string) {
 		musts = append(musts, fmt.Sprintf(query_bool_should, strings.Join(musts_should, ",")))
 	}
 	//采购单位名称
-	if len(in.BuyerName) > 0 {
-		entNameQuery := `{"match_phrase":{"name":"` + in.BuyerName + `"}}`
+	if in.BuyerName != "" {
+		entNameQuery := fmt.Sprintf(`{"multi_match": {"query": "%s","type": "phrase", "fields": ["name"]}}`, in.BuyerName)
 		musts = append(musts, entNameQuery)
 	}
 	//采购单位类型
@@ -88,7 +89,7 @@ func SupplyDataQuery(buyerList []string) (query string) {
 func getTimeRage() (st, et time.Time) {
 	now := time.Now()
 	eYear := now.Year()
-	sYear := now.Year() - 2
+	sYear := now.Year() - 5
 	//返回默认时间
 	sTimeStamp := time.Date(sYear, 1, 1, 0, 0, 0, 0, time.Local)
 	eTimeStamp := time.Date(eYear, now.Month(), now.Day(), now.Hour(), now.Minute(), 0, 0, time.Local)
@@ -112,6 +113,7 @@ const (
 func GetBuyerList(qstr string, CountQuery string, in *bxbuyer.BuyerListReq, isCache bool) (resp *bxbuyer.BuyerListResp) {
 	t1 := time.Now()
 	total := elastic.Count(BuyerIndex, BuyerType, CountQuery) // 总数
+	fmt.Println("耗时1:", time.Since(t1))
 	resp = &bxbuyer.BuyerListResp{
 		Data: &bxbuyer.BuyerData{
 			Count: total,
@@ -123,72 +125,55 @@ func GetBuyerList(qstr string, CountQuery string, in *bxbuyer.BuyerListReq, isCa
 	}
 	start := time.Now()
 	rs := elastic.Get(BuyerIndex, BuyerType, qstr) // 采购单位列表
-	logx.Info("采购单位列表 es get查询耗时", time.Since(start))
+	fmt.Println("采购单位列表 es get查询耗时", time.Since(start))
 	if rs == nil || len(*rs) == 0 {
 		return
 	}
+	var buyerNames []string
 	for i := 0; i < len(*rs); i++ {
 		tmp := &bxbuyer.BuyerList{
-			Buyer:      MC.ObjToString((*rs)[i]["buyer_name"]),
-			Province:   MC.ObjToString((*rs)[i]["province"]),
+			Buyer:      MC.ObjToString((*rs)[i]["name"]),
+			Province:   MC.ObjToString((*rs)[i]["area"]),
 			City:       MC.ObjToString((*rs)[i]["city"]),
-			BuyerClass: MC.ObjToString((*rs)[i]["buyerclasss"]),
+			BuyerClass: MC.ObjToString((*rs)[i]["buyerclass"]),
 		}
+		buyerNames = append(buyerNames, tmp.Buyer)
 		resp.Data.List = append(resp.Data.List, tmp)
-
 	}
-	var wg sync.WaitGroup
 	//省份和城市 是否查询已关注信息 是否查询已领取信息
 	//企业信用库qyxy_std 和es buyer库 查询省份和城市
-	var fiftyArr = []*bxbuyer.BuyerList{}
-	var buyerNames = []string{}
-	for bk, bv := range resp.Data.List {
-		fiftyArr = append(fiftyArr, bv)
-		buyerNames = append(buyerNames, bv.Buyer)
-		if (bk+1)%50 == 0 || len(resp.Data.List) == bk+1 {
-			wg.Add(1)
-			go func(wg *sync.WaitGroup, fiftyArr []*bxbuyer.BuyerList, buyerNames []string, icf, icr bool, userId, entUserId string) {
-				// 关注状态 领取状态
-				//关注状态
-				isFws := map[string]bool{}
-				if icf {
-					isFws = IsFollowd(buyerNames, userId)
-				}
-				//领取状态
-				isRws := map[string]string{}
-				if icr {
-					isRws = IsReceived(buyerNames, entUserId)
-				}
-				//log.Println("---:", isRws)
-				for _, fv := range fiftyArr {
-					if icf {
-						fv.IsFollowed = isFws[fv.Buyer]
-					}
-					if icr {
-						if isRws[fv.Buyer] != "" {
-							fv.RecId = isRws[fv.Buyer]
-							fv.IsReceived = true
-						}
-					}
-				}
-				wg.Done()
-			}(&wg, fiftyArr, buyerNames, in.IsCheckFollow, in.IsCheckReceive, in.UserId, in.EntUserId)
-			fiftyArr = []*bxbuyer.BuyerList{}
-			buyerNames = []string{}
+	//客户领取
+	t2 := time.Now()
+	isRws := map[string]string{}
+	if in.IsCheckReceive {
+		isRws = IsReceived(buyerNames, in.EntUserId)
+	}
+	fmt.Println("客户领取耗时:", time.Since(t2))
+	//客户关注
+	t3 := time.Now()
+	isFws := map[string]bool{}
+	if in.IsCheckFollow {
+		isFws = IsFollowd(buyerNames, in.UserId)
+	}
+	fmt.Println("采购单位关注耗时:", time.Since(t3))
+	for _, bv := range resp.Data.List {
+		if in.IsCheckReceive {
+			if isRws[bv.Buyer] != "" {
+				bv.IsReceived = true
+				bv.RecId = isRws[bv.Buyer]
+			}
+			if isFws[bv.Buyer] {
+				bv.IsFollowed = true
+			}
 		}
 	}
-	wg.Wait()
-
-	logx.Info("耗时;", time.Since(t1).Seconds(), time.Since(t1).Microseconds())
+	fmt.Println("耗时;", time.Since(t1).Seconds(), "秒--", time.Since(t1).Microseconds())
 	return
 }
 
 // 补充字段   项目数量 历史联系人数量 采购单位规模
-func SupplyBuyerListData(resp *bxbuyer.BuyerListResp) *bxbuyer.BuyerListResp {
+func SupplyBuyerListData(resp *bxbuyer.BuyerListResp) {
 	start := time.Now()
-	if resp == nil || resp.Data == nil || resp.Data.List == nil || len(resp.Data.List) == 0 {
-		return resp
-	}
 	// buyerList
 	buyerList := []string{}
 	for i := 0; i < len(resp.Data.List); i++ {
@@ -198,8 +183,8 @@ func SupplyBuyerListData(resp *bxbuyer.BuyerListResp) *bxbuyer.BuyerListResp {
 	query := SupplyDataQuery(buyerList) // 项目数量、采购规模
 	// 聚合查
 	aggs := GetAggs(P_INDEX, P_TYPE, query)
-	logx.Info("项目数量采购规模查询耗时", time.Since(t1))
 	logx.Info("查询语句:", query)
+	fmt.Println("项目数量采购规模查询耗时:", time.Since(t1))
 	type BuyerAggStruct struct {
 		Buckets []struct {
 			Key            string `json:"key,omitempty"`
@@ -270,8 +255,7 @@ func SupplyBuyerListData(resp *bxbuyer.BuyerListResp) *bxbuyer.BuyerListResp {
 
 	}
 	wg.Wait()
-	logx.Info("SupplyBuyerListData 整体耗时:", time.Since(start))
-	return resp
+	fmt.Println("SupplyBuyerListData 整体耗时:", time.Since(start))
 }
 
 func GetProjectContactCount(buyerName string) int64 {
@@ -333,7 +317,7 @@ func GetProjectContactCount(buyerName string) int64 {
 			}
 		}
 	}
-	logx.Info("GetProjectContactCount 单次耗时:", time.Since(start))
+	fmt.Println("GetProjectContactCount 单次耗时:", time.Since(start))
 	return int64(len(list))
 }
 func GetNewBiddingCount(buyer string) int64 {
@@ -345,9 +329,9 @@ func GetNewBiddingCount(buyer string) int64 {
 	st, et := getTimeRage()
 	mustQuery = append(mustQuery, fmt.Sprintf(`{"range":{"publishtime":{"gte":%d,"lte":%d}}}`, st.Unix(), et.Unix()))
 	mustQuery = append(mustQuery, fmt.Sprintf(`{"term": {"buyer": "%s"}}`, buyer))
-
-	count := elastic.Count(biddingIndex, biddingType, fmt.Sprintf(`{"query":{"bool":{"must":[%s]}}}`, strings.Join(mustQuery, ",")))
-	logx.Info("GetNewBiddingCount 单次耗时:", time.Since(start))
+	aa := fmt.Sprintf(`{"query":{"bool":{"must":[%s]}}}`, strings.Join(mustQuery, ","))
+	count := elastic.Count(biddingIndex, biddingType, aa)
+	fmt.Println("GetNewBiddingCount 单次耗时:", time.Since(start))
 	return count
 }
 
@@ -393,17 +377,15 @@ 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 {
-		if len(*list) > 0 {
-			isFws = map[string]bool{}
-			for _, lv := range *list {
-				if MC.ObjToString(lv["name"]) != "" {
-					isFws[MC.ObjToString(lv["name"])] = true
-				}
+	if ok && len(*list) > 0 {
+		isFws = map[string]bool{}
+		for _, lv := range *list {
+			if MC.ObjToString(lv["name"]) != "" {
+				isFws[MC.ObjToString(lv["name"])] = true
 			}
 		}
 	} else {
-		logx.Info("采购单位是否已关注信息异常")
+		logx.Info("采购单位是否已关注信息异常  or  未查到数据")
 	}
 	return
 }
@@ -416,6 +398,8 @@ var (
 // 领取状态
 func IsReceived(buyerNames []string, entUserId string) (isRws map[string]string) {
 	//新加领取的客户id----保证领取的唯一性
+	aa := fmt.Sprintf("SELECT ecn.id,  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, "','"))
+	log.Println(aa)
 	receInfos := IC.MainMysql.SelectBySql(fmt.Sprintf("SELECT ecn.id,  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 receInfos != nil {
 		if len(*receInfos) > 0 {