|
@@ -100,10 +100,10 @@ func getTimeRage() (st, et time.Time) {
|
|
const (
|
|
const (
|
|
P_INDEX = "projectset"
|
|
P_INDEX = "projectset"
|
|
P_TYPE = "projectset"
|
|
P_TYPE = "projectset"
|
|
- P_redis_time = 15 * 24 * 60 * 60 //redis存15天
|
|
|
|
- P_redis_key = "buyerListCache"
|
|
|
|
- BuyerIndex = "buyer_v2" // 采购单位index
|
|
|
|
- BuyerType = "_doc"
|
|
|
|
|
|
+ P_redis_time = 15 * 24 * 60 * 60 //redis存15天
|
|
|
|
+ P_redis_key = "buyerListCache_%d_%d" // 按页存缓存
|
|
|
|
+ BuyerIndex = "buyer" // 采购单位index
|
|
|
|
+ BuyerType = "buyer"
|
|
biddingIndex = "bidding"
|
|
biddingIndex = "bidding"
|
|
biddingType = "bidding"
|
|
biddingType = "bidding"
|
|
)
|
|
)
|
|
@@ -121,7 +121,9 @@ func GetBuyerList(qstr string, CountQuery string, in *bxbuyer.BuyerListReq, isCa
|
|
if total == 0 {
|
|
if total == 0 {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ start := time.Now()
|
|
rs := elastic.Get(BuyerIndex, BuyerType, qstr) // 采购单位列表
|
|
rs := elastic.Get(BuyerIndex, BuyerType, qstr) // 采购单位列表
|
|
|
|
+ logx.Info("采购单位列表 es get查询耗时", time.Since(start))
|
|
if rs == nil || len(*rs) == 0 {
|
|
if rs == nil || len(*rs) == 0 {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -183,6 +185,7 @@ func GetBuyerList(qstr string, CountQuery string, in *bxbuyer.BuyerListReq, isCa
|
|
|
|
|
|
// 补充字段 项目数量 历史联系人数量 采购单位规模
|
|
// 补充字段 项目数量 历史联系人数量 采购单位规模
|
|
func SupplyBuyerListData(resp *bxbuyer.BuyerListResp) *bxbuyer.BuyerListResp {
|
|
func SupplyBuyerListData(resp *bxbuyer.BuyerListResp) *bxbuyer.BuyerListResp {
|
|
|
|
+ start := time.Now()
|
|
if resp == nil || resp.Data == nil || resp.Data.List == nil || len(resp.Data.List) == 0 {
|
|
if resp == nil || resp.Data == nil || resp.Data.List == nil || len(resp.Data.List) == 0 {
|
|
return resp
|
|
return resp
|
|
}
|
|
}
|
|
@@ -191,10 +194,12 @@ func SupplyBuyerListData(resp *bxbuyer.BuyerListResp) *bxbuyer.BuyerListResp {
|
|
for i := 0; i < len(resp.Data.List); i++ {
|
|
for i := 0; i < len(resp.Data.List); i++ {
|
|
buyerList = append(buyerList, resp.Data.List[i].Buyer)
|
|
buyerList = append(buyerList, resp.Data.List[i].Buyer)
|
|
}
|
|
}
|
|
- query := SupplyDataQuery(buyerList) // 招标动态数量、项目数量、采购规模
|
|
|
|
|
|
+ t1 := time.Now()
|
|
|
|
+ query := SupplyDataQuery(buyerList) // 项目数量、采购规模
|
|
// 聚合查
|
|
// 聚合查
|
|
aggs := GetAggs(P_INDEX, P_TYPE, query)
|
|
aggs := GetAggs(P_INDEX, P_TYPE, query)
|
|
-
|
|
|
|
|
|
+ logx.Info("项目数量采购规模查询耗时", time.Since(t1))
|
|
|
|
+ logx.Info("查询语句:", query)
|
|
type BuyerAggStruct struct {
|
|
type BuyerAggStruct struct {
|
|
Buckets []struct {
|
|
Buckets []struct {
|
|
Key string `json:"key,omitempty"`
|
|
Key string `json:"key,omitempty"`
|
|
@@ -221,7 +226,8 @@ func SupplyBuyerListData(resp *bxbuyer.BuyerListResp) *bxbuyer.BuyerListResp {
|
|
if len(bs) == 0 {
|
|
if len(bs) == 0 {
|
|
resp.ErrMsg = "暂无数据"
|
|
resp.ErrMsg = "暂无数据"
|
|
} else {
|
|
} else {
|
|
- json.Unmarshal(bs, &buyerBuckets)
|
|
|
|
|
|
+ err := json.Unmarshal(bs, &buyerBuckets)
|
|
|
|
+ logx.Info(err)
|
|
if len(buyerBuckets.Buckets) > 0 {
|
|
if len(buyerBuckets.Buckets) > 0 {
|
|
for _, v := range buyerBuckets.Buckets {
|
|
for _, v := range buyerBuckets.Buckets {
|
|
buyerMap[v.Key] = supplyDataStruct{
|
|
buyerMap[v.Key] = supplyDataStruct{
|
|
@@ -243,31 +249,33 @@ func SupplyBuyerListData(resp *bxbuyer.BuyerListResp) *bxbuyer.BuyerListResp {
|
|
resp.Data.List[i].BidAmountCount = supplyData.BidAmountCount
|
|
resp.Data.List[i].BidAmountCount = supplyData.BidAmountCount
|
|
resp.Data.List[i].ProjectCount = supplyData.ProjectCount
|
|
resp.Data.List[i].ProjectCount = supplyData.ProjectCount
|
|
}
|
|
}
|
|
- ch <- 1
|
|
|
|
|
|
+ ch2 <- 1
|
|
wg.Add(1)
|
|
wg.Add(1)
|
|
go func(list *bxbuyer.BuyerList, buyer string) {
|
|
go func(list *bxbuyer.BuyerList, buyer string) {
|
|
defer func() {
|
|
defer func() {
|
|
- <-ch
|
|
|
|
|
|
+ <-ch2
|
|
wg.Done()
|
|
wg.Done()
|
|
}()
|
|
}()
|
|
- list.BiddingCount = GetNewBiddingCount(buyer)
|
|
|
|
|
|
+ list.ContactCount = GetProjectContactCount(buyer) // 补充联系人字段
|
|
}(resp.Data.List[i], buyer)
|
|
}(resp.Data.List[i], buyer)
|
|
- ch2 <- 1
|
|
|
|
|
|
+ ch <- 1
|
|
wg.Add(1)
|
|
wg.Add(1)
|
|
go func(list *bxbuyer.BuyerList, buyer string) {
|
|
go func(list *bxbuyer.BuyerList, buyer string) {
|
|
defer func() {
|
|
defer func() {
|
|
- <-ch2
|
|
|
|
|
|
+ <-ch
|
|
wg.Done()
|
|
wg.Done()
|
|
}()
|
|
}()
|
|
- list.ContactCount = GetProjectContactCount(buyer) // 补充联系人字段
|
|
|
|
|
|
+ list.BiddingCount = GetNewBiddingCount(buyer)
|
|
}(resp.Data.List[i], buyer)
|
|
}(resp.Data.List[i], buyer)
|
|
|
|
|
|
}
|
|
}
|
|
wg.Wait()
|
|
wg.Wait()
|
|
|
|
+ logx.Info("SupplyBuyerListData 整体耗时:", time.Since(start))
|
|
return resp
|
|
return resp
|
|
}
|
|
}
|
|
|
|
|
|
func GetProjectContactCount(buyerName string) int64 {
|
|
func GetProjectContactCount(buyerName string) int64 {
|
|
|
|
+ start := time.Now()
|
|
list := []string{}
|
|
list := []string{}
|
|
var musts []string
|
|
var musts []string
|
|
if buyerName != "" {
|
|
if buyerName != "" {
|
|
@@ -277,7 +285,7 @@ func GetProjectContactCount(buyerName string) int64 {
|
|
return 0
|
|
return 0
|
|
}
|
|
}
|
|
searchSql := fmt.Sprintf(`{"query":{"bool":{"must":[%s]}},"_source":["_id","zbtime","projectname","list"],"sort":[{"zbtime":"desc"}],"size":500}`, strings.Join(musts, ","))
|
|
searchSql := fmt.Sprintf(`{"query":{"bool":{"must":[%s]}},"_source":["_id","zbtime","projectname","list"],"sort":[{"zbtime":"desc"}],"size":500}`, strings.Join(musts, ","))
|
|
- projectList := elastic.Get("projectset", "projectset", searchSql)
|
|
|
|
|
|
+ projectList := elastic.Get(P_INDEX, P_TYPE, searchSql)
|
|
if projectList == nil || len(*projectList) == 0 {
|
|
if projectList == nil || len(*projectList) == 0 {
|
|
return 0
|
|
return 0
|
|
}
|
|
}
|
|
@@ -325,9 +333,11 @@ func GetProjectContactCount(buyerName string) int64 {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ logx.Info("GetProjectContactCount 单次耗时:", time.Since(start))
|
|
return int64(len(list))
|
|
return int64(len(list))
|
|
}
|
|
}
|
|
func GetNewBiddingCount(buyer string) int64 {
|
|
func GetNewBiddingCount(buyer string) int64 {
|
|
|
|
+ start := time.Now()
|
|
if buyer == "" {
|
|
if buyer == "" {
|
|
return 0
|
|
return 0
|
|
}
|
|
}
|
|
@@ -335,7 +345,10 @@ func GetNewBiddingCount(buyer string) int64 {
|
|
st, et := getTimeRage()
|
|
st, et := getTimeRage()
|
|
mustQuery = append(mustQuery, fmt.Sprintf(`{"range":{"publishtime":{"gte":%d,"lte":%d}}}`, st.Unix(), et.Unix()))
|
|
mustQuery = append(mustQuery, fmt.Sprintf(`{"range":{"publishtime":{"gte":%d,"lte":%d}}}`, st.Unix(), et.Unix()))
|
|
mustQuery = append(mustQuery, fmt.Sprintf(`{"term": {"buyer": "%s"}}`, buyer))
|
|
mustQuery = append(mustQuery, fmt.Sprintf(`{"term": {"buyer": "%s"}}`, buyer))
|
|
- return elastic.Count(biddingIndex, biddingType, fmt.Sprintf(`{"query":{"bool":{"must":[%s]}}}`, strings.Join(mustQuery, ",")))
|
|
|
|
|
|
+
|
|
|
|
+ count := elastic.Count(biddingIndex, biddingType, fmt.Sprintf(`{"query":{"bool":{"must":[%s]}}}`, strings.Join(mustQuery, ",")))
|
|
|
|
+ logx.Info("GetNewBiddingCount 单次耗时:", time.Since(start))
|
|
|
|
+ return count
|
|
}
|
|
}
|
|
|
|
|
|
// 聚合查询
|
|
// 聚合查询
|
|
@@ -421,7 +434,7 @@ func IsReceived(buyerNames []string, entUserId string) (isRws map[string]string)
|
|
|
|
|
|
// 是否为空请求
|
|
// 是否为空请求
|
|
func CheckEmpty(in *bxbuyer.BuyerListReq) bool {
|
|
func CheckEmpty(in *bxbuyer.BuyerListReq) bool {
|
|
- if in.BuyerName == "" && len(in.BuyerClass) == 0 && len(in.Province) == 0 && len(in.City) == 0 {
|
|
|
|
|
|
+ if in.BuyerName == "" && len(in.BuyerClass) == 0 && len(in.Province) == 0 && len(in.City) == 0 && in.IsContact == 0 {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
return false
|
|
@@ -430,12 +443,13 @@ func CheckEmpty(in *bxbuyer.BuyerListReq) bool {
|
|
//缓存数据查询
|
|
//缓存数据查询
|
|
|
|
|
|
// 获取采购单位查询query
|
|
// 获取采购单位查询query
|
|
-func BuyerListRedisCacheQuery() (qstr string, a string) {
|
|
|
|
- query := `{"size": 0,"query":{"bool":{"must":[%s],"must_not": [{"term": {"buyer": ""}}],"should":[],"minimum_should_match": %d}}}`
|
|
|
|
|
|
+func BuyerListRedisCacheQuery(pageNum, pageSize int64) (qstr string, cstr string) {
|
|
|
|
+ query := `{"from":%d,"size":%d,"query":{"bool":{"must":[%s],"must_not": [{"term": {"buyer_name": ""}}],"should":[],"minimum_should_match": %d}}}`
|
|
|
|
+ queryCount := `{"query":{"bool":{"must":[%s],"must_not": [{"term": {"buyer": ""}}],"should":[],"minimum_should_match": %d}}}`
|
|
//21.1.20 为和画像保持一致 数据组要求 budget 改成 bidamount
|
|
//21.1.20 为和画像保持一致 数据组要求 budget 改成 bidamount
|
|
musts := []string{}
|
|
musts := []string{}
|
|
boolsNum := 0
|
|
boolsNum := 0
|
|
- entcustomerClass := `{"terms":{"buyer":[`
|
|
|
|
|
|
+ entcustomerClass := `{"terms":{"buyer_name":[`
|
|
for k, v := range IC.C.DefaultBuyerNames {
|
|
for k, v := range IC.C.DefaultBuyerNames {
|
|
if k > 0 {
|
|
if k > 0 {
|
|
entcustomerClass += `,`
|
|
entcustomerClass += `,`
|
|
@@ -444,7 +458,8 @@ func BuyerListRedisCacheQuery() (qstr string, a string) {
|
|
}
|
|
}
|
|
entcustomerClass += `]}}`
|
|
entcustomerClass += `]}}`
|
|
musts = append(musts, entcustomerClass)
|
|
musts = append(musts, entcustomerClass)
|
|
- qstr = fmt.Sprintf(query, strings.Join(musts, ","), boolsNum)
|
|
|
|
|
|
+ qstr = fmt.Sprintf(query, (pageNum-1)*pageSize, pageSize, strings.Join(musts, ","), boolsNum)
|
|
|
|
+ cstr = fmt.Sprintf(queryCount, strings.Join(musts, ","), boolsNum)
|
|
logx.Info("qstr:", qstr)
|
|
logx.Info("qstr:", qstr)
|
|
return
|
|
return
|
|
}
|
|
}
|