Browse Source

wip:搜索数据导出新增buyer、winner、agency字段

wangkaiyue 1 year ago
parent
commit
04995b1769
2 changed files with 49 additions and 6 deletions
  1. 34 4
      common/src/qfw/util/dataexport/dataexport.go
  2. 15 2
      public/dataexport.go

+ 34 - 4
common/src/qfw/util/dataexport/dataexport.go

@@ -52,6 +52,7 @@ type SieveCondition struct {
 	Industry         []string  `json:"industry"`         //行业
 	Keyword          []KeyWord `json:"keywords"`         //关键词
 	Buyer            []string  `json:"buyer"`            //招标单位(采购单位)
+	Agency           []string  `json:"agency"`           //招标代理机构(采购单位)
 	Buyerclass       []string  `json:"buyerclass"`       //采购单位类型
 	HasBuyerTel      string    `json:"hasBuyertel"`      //是否有采购单位电话
 	Winner           []string  `json:"winner"`           //中标单位
@@ -110,6 +111,23 @@ func DetailANDTitle(findfields string) bool {
 	return strings.Contains(findfields, "detail") && strings.Contains(findfields, "title")
 }
 
+var getMatchPhraseSql = func(field string, val ...string) (sql string) {
+	if len(val) == 0 {
+		return
+	}
+	var arr []string
+	for _, s := range val {
+		if s == "" {
+			continue
+		}
+		arr = append(arr, fmt.Sprintf(`{"match_phrase": {"%s": "%s"}}`, field, s))
+	}
+	if len(arr) == 0 {
+		return ""
+	}
+	return fmt.Sprintf(`{"bool": {"should": [%s],"minimum_should_match": 1}}`, strings.Join(arr, ","))
+}
+
 // 获取数据导出查询语句
 func getDataExportSql(scd *SieveCondition) string {
 	if len(scd.SelectIds) > 0 {
@@ -241,14 +259,25 @@ func getDataExportSql(scd *SieveCondition) string {
 	if len(scd.Industry) > 0 {
 		musts = append(musts, fmt.Sprintf(query_bool_must, "s_subscopeclass", `"`+strings.Join(scd.Industry, `","`)+`"`))
 	}
-	if len(scd.Buyer) > 0 {
-		musts = append(musts, fmt.Sprintf(query_bool_must, "buyer", `"`+strings.Join(scd.Buyer, `","`)+`"`))
-	}
 	if len(scd.Buyerclass) > 0 {
 		musts = append(musts, fmt.Sprintf(query_bool_must, "buyerclass", `"`+strings.Join(scd.Buyerclass, `","`)+`"`))
 	}
+	//P492招标采购搜索匹配采购单位等优化 新增buyer、agency、winner模糊搜索,数据导出同步改为模糊
+	//query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
+	if len(scd.Buyer) > 0 {
+		if sql := getMatchPhraseSql("buyer.mbuyer", scd.Buyer...); sql != "" {
+			musts = append(musts, sql)
+		}
+	}
+	if len(scd.Agency) > 0 {
+		if sql := getMatchPhraseSql("agency.magency", scd.Buyer...); sql != "" {
+			musts = append(musts, sql)
+		}
+	}
 	if len(scd.Winner) > 0 {
-		musts = append(musts, fmt.Sprintf(query_bool_must, "s_winner", `"`+strings.Join(scd.Winner, `","`)+`"`))
+		if sql := getMatchPhraseSql("s_winner.mwinner", scd.Buyer...); sql != "" {
+			musts = append(musts, sql)
+		}
 	}
 	_minPrice := ""
 	_maxPrice := ""
@@ -495,6 +524,7 @@ func GetSqlObjFromId(mongo mg.MongodbSim, _id string) *SieveCondition {
 		SelectType:       qutil.ObjToString((*query)["selectType"]),
 		PublishTime:      qutil.ObjToString((*query)["publishtime"]),
 		Buyer:            getStringArrFromDbResult((*query)["buyer"]),
+		Agency:           getStringArrFromDbResult((*query)["agency"]),
 		Buyerclass:       getStringArrFromDbResult((*query)["buyerclass"]),
 		HasBuyerTel:      qutil.ObjToString((*query)["hasBuyertel"]),
 		Winner:           getStringArrFromDbResult((*query)["winner"]),

+ 15 - 2
public/dataexport.go

@@ -106,6 +106,8 @@ type BidSearchExport struct {
 	Industry        string //选中的行业
 	SelectType      string //标题 or 全文
 	Winner          string //中标单位
+	Buyer           string `json:"buyer"`  //招标单位(采购单位)
+	Agency          string `json:"agency"` //招标代理机构(采购单位)
 	Buyerclass      string //采购单位行业
 	Hasbuyertel     string //是否有采购电话
 	Haswinnertel    string //是否有中标电话
@@ -124,8 +126,11 @@ type BidSearchExport struct {
 
 func (this *BidSearchExport) PassBidSearchExport(Sysconfig map[string]interface{}) (returnData map[string]interface{}) {
 	defer util.Catch()
-	areaSave, industrySave, citySave, districtSave := []string{}, []string{}, []string{}, []string{}
-	winnerSave, buyerclassSave := []string{}, []string{}
+
+	var (
+		areaSave, industrySave, citySave, districtSave    = []string{}, []string{}, []string{}, []string{}
+		winnerSave, buyerSave, agencySave, buyerclassSave = []string{}, []string{}, []string{}, []string{}
+	)
 	publishtimeSave := this.Publishtime
 	if len(this.Area) > 0 {
 		areaSave = strings.Split(this.Area, ",")
@@ -146,6 +151,12 @@ func (this *BidSearchExport) PassBidSearchExport(Sysconfig map[string]interface{
 	if len(this.Winner) > 0 {
 		winnerSave = strings.Split(this.Winner, ",")
 	}
+	if len(this.Buyer) > 0 {
+		buyerSave = strings.Split(this.Buyer, ",")
+	}
+	if len(this.Agency) > 0 {
+		agencySave = strings.Split(this.Agency, ",")
+	}
 
 	KeyWordSave := []dataexport.KeyWord{}
 	if len(this.Keywords) > 0 || len(this.AdditionalWords) > 0 {
@@ -210,6 +221,8 @@ func (this *BidSearchExport) PassBidSearchExport(Sysconfig map[string]interface{
 		"selectType":   this.SelectType,
 		"buyerclass":   buyerclassSave,
 		"winner":       winnerSave,
+		"buyer":        buyerSave,
+		"agency":       agencySave,
 		"hasBuyertel":  this.Hasbuyertel,
 		"hasWinnertel": this.Haswinnertel,
 		"fileExists":   this.FileExists,