Переглянути джерело

Merge branch 'dev/2.9.38_fu' of jianyu/ent_new into feature/v2.9.38

fuwencai 1 рік тому
батько
коміт
a637019818
1 змінених файлів з 20 додано та 18 видалено
  1. 20 18
      entniche_new/src/service/customer/customer.go

+ 20 - 18
entniche_new/src/service/customer/customer.go

@@ -193,9 +193,9 @@ func (this *CustomerAction) CustomerQuery() {
 			}
 			//企业项目查询
 			start := time.Now().Unix()
-			potComQ := MyPCQuery(customerName, numb)
+			potComQ, countQ := MyPCQuery(customerName, numb)
 			log.Println("potComQ", potComQ)
-			list, _, _, _ := getPCostomers(potComQ)
+			list, _, _, _ := getPCostomers(potComQ, countQ)
 			dataMap := map[string]*PTComs{}
 			for _, value := range list {
 				dataMap[value.Buyer] = value
@@ -684,8 +684,8 @@ func (this *CustomerAction) CustomerCorList() {
 		//接收参数
 		json.Unmarshal(this.Body(), &getRes)
 	}
-	potComQ := PCQuery(getRes.Area, getRes.Industry, getRes.BuyerClass, getRes.Business_scope, getRes.Sort_no, getRes.PCOR, getRes.EntName, getRes.Entcustomer)
-	list, count, msg, _ := getPCostomers(potComQ)
+	potComQ, countQ := PCQuery(getRes.Area, getRes.Industry, getRes.BuyerClass, getRes.Business_scope, getRes.Sort_no, getRes.PCOR, getRes.EntName, getRes.Entcustomer)
+	list, count, msg, _ := getPCostomers(potComQ, countQ)
 	errMsg := msg
 	this.ServeJson(Result{
 		Data: map[string]interface{}{
@@ -761,10 +761,10 @@ func (this *CustomerAction) CustomerHistory() {
 }
 
 // 我的客户信息拼接
-func MyPCQuery(entName []string, numb int) string {
+func MyPCQuery(entName []string, numb int) (string, string) {
 	log.Println("1111", numb)
 	multi_match := `{"multi_match": {"query": %s,"type": "phrase", "fields": [%s]}}`
-	query := `{"query":{"bool":{"must":[%s],"must_not": [{"term": {"buyer": ""}}],"minimum_should_match":%d}},"size": 0,%s}`
+	query := `{"query":{"bool":{"must":[%s],"must_not": [{"term": {"buyer": ""}}]}} %s}`
 	//21.1.20  为和画像保持一致  数据组要求 budget 改成 bidamount
 	query_aggs := `"aggs": {"group_field": {"terms": {"field": %s,"size": %d%s},"aggs": {"count": {"sum": {"field": "bidamount"}}, 
           "top": {
@@ -813,18 +813,19 @@ func MyPCQuery(entName []string, numb int) string {
 		query_sort = ""
 	}
 	query_aggs = fmt.Sprintf(query_aggs, query_sort)
-	qstr := fmt.Sprintf(query, strings.Join(musts, ","), 1, query_aggs)
-	return qstr
+	qstr := fmt.Sprintf(query, strings.Join(musts, ","), fmt.Sprintf(",%s", query_aggs))
+	cstr := fmt.Sprintf(query, strings.Join(musts, ","), "")
+	return qstr, cstr
 }
 
 // 采购单位拼接
-func PCQuery(area map[string]interface{}, industry []string, buyerclass []string, business_scope []map[string]interface{}, sort_no int, pcor, entName string, entcustomer []string) string {
+func PCQuery(area map[string]interface{}, industry []string, buyerclass []string, business_scope []map[string]interface{}, sort_no int, pcor, entName string, entcustomer []string) (string, string) {
 	multi_match := `{"multi_match": {"query": %s,"type": "phrase", "fields": [%s]}}`
 	query := ""
-	query = `{"query":{"bool":{"must":[%s],"must_not": [{"term": {"buyer": ""}}],"should":[%s],"minimum_should_match": %d}},%s}`
+	query = `{"query":{"bool":{"must":[%s],"must_not": [{"term": {"buyer": ""}}],"should":[%s],"minimum_should_match": %d}}%s}`
 	//query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
 	//21.1.20  为和画像保持一致  数据组要求 budget 改成 bidamount
-	query_aggs := `"aggs": {"group_field": {"terms": {"field": %s,"size": %d%s},"aggs": {"count": {"sum": {"field": "bidamount"}},
+	query_aggs := `,"aggs": {"group_field": {"terms": {"field": %s,"size": %d%s},"aggs": {"count": {"sum": {"field": "bidamount"}},
         "top": {
           "top_hits": {
             "sort": [
@@ -986,13 +987,14 @@ func PCQuery(area map[string]interface{}, industry []string, buyerclass []string
 	qstr := ""
 	qstr = fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(bools, ","), boolsNum, query_aggs)
 	fmt.Println(qstr)
-	return qstr
+	countQ := fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(bools, ","), boolsNum, "")
+	return qstr, countQ
 }
 
 // 客户解析
-func getPCostomers(potComQ string) ([]*PTComs, int64, string, int) {
+func getPCostomers(potComQ, countQuery string) ([]*PTComs, int64, string, int) {
 	var regMap = []*PTComs{}
-	aggs, res, count, msg := GetAggs(P_INDEX, P_TYPE, potComQ)
+	aggs, res, count, msg := GetAggs(P_INDEX, P_TYPE, potComQ, countQuery)
 	if count > config.Config.ItemsNumber {
 		return regMap, count, msg, 0
 	}
@@ -1039,8 +1041,8 @@ type Bucket struct {
 }
 
 // 聚合查询
-func GetAggs(index, itype, query string) (aggs esV7.Aggregations, res []map[string]interface{}, count int64, msg string) {
-	count = elastic.Count(index, itype, query)
+func GetAggs(index, itype, query string, countQuery string) (aggs esV7.Aggregations, res []map[string]interface{}, count int64, msg string) {
+	count = elastic.Count(index, itype, countQuery)
 	if count > config.Config.ItemsNumber {
 		msg = "搜索目标过于宽泛,请缩小搜索范围。"
 		return
@@ -1255,8 +1257,8 @@ func (this *CustomerAction) CstList() {
 			customerName = append(customerName, value.Name)
 		}
 		//企业项目查询
-		potComQ := MyPCQuery(customerName, len(customerName))
-		list, _, _, _ := getPCostomers(potComQ)
+		potComQ, countQ := MyPCQuery(customerName, len(customerName))
+		list, _, _, _ := getPCostomers(potComQ, countQ)
 		dataMap := map[string]*PTComs{}
 		for _, value := range list {
 			dataMap[value.Buyer] = value