|
@@ -292,6 +292,156 @@ func AnalyzeNumber(area map[string]interface{}, business_scope []ViewKeyWord, bu
|
|
|
return all_count, area_count, buyer_count
|
|
|
}
|
|
|
|
|
|
+// //投标决策分析查询语句-中标企业和采购单位 类似项目明细
|
|
|
+func DecQueryNewSimilarMsgByBW(Winner string, this *DecParam, SearchType int) (qstr string) {
|
|
|
+ //基础查询
|
|
|
+ bools := []string{}
|
|
|
+ musts := []string{}
|
|
|
+ var BWExists = 0
|
|
|
+ var (
|
|
|
+ query_bool = `{"bool":{"should":[%s],"minimum_should_match":%d}}`
|
|
|
+ query = `{"track_total_hits": true,"query":{"bool":{"must":[%s]}},"size":0}`
|
|
|
+ )
|
|
|
+ //中标单位 类似项目合作历史||采购单位类似项目
|
|
|
+ if Winner != "" {
|
|
|
+ BWExists += 1
|
|
|
+ winnerterms := `{"terms":{"s_winner":[`
|
|
|
+ for k, v := range strings.Split(Winner, ",") {
|
|
|
+ if k > 0 {
|
|
|
+ winnerterms += `,`
|
|
|
+ }
|
|
|
+ winnerterms += `"` + v + `"`
|
|
|
+ }
|
|
|
+ winnerterms += `]}}`
|
|
|
+ musts = append(musts, winnerterms)
|
|
|
+ }
|
|
|
+ //中标单位 类似项目合作历史||采购单位类似项目
|
|
|
+ if this.Buyer != "" && this.SearchItem == 1 {
|
|
|
+ buyerterms := fmt.Sprintf(`{"query_string": {"default_field": "buyer","query": "*%s*"}}`, this.Buyer)
|
|
|
+ BWExists += 1
|
|
|
+ musts = append(musts, buyerterms)
|
|
|
+ }
|
|
|
+ //searchType ==1; buyer & winner 不能为空
|
|
|
+ if BWExists < 2 && SearchType == 1 {
|
|
|
+ SearchType = 0
|
|
|
+ }
|
|
|
+ if this.SearchItem == 2 {
|
|
|
+ //省份
|
|
|
+ areaCity := []string{}
|
|
|
+ citys := []string{}
|
|
|
+ if len(this.Area) > 0 {
|
|
|
+ areaquery := `{"terms":{"area":[`
|
|
|
+ var i = 0
|
|
|
+ for k, v := range this.Area {
|
|
|
+ if len(qutil.ObjArrToStringArr(v.([]interface{}))) == 0 {
|
|
|
+ if i > 0 {
|
|
|
+ areaquery += `,`
|
|
|
+ }
|
|
|
+ areaquery += `"` + strings.ReplaceAll(strings.ReplaceAll(k, "省", ""), "市", "") + `"`
|
|
|
+ i += 1
|
|
|
+ } else {
|
|
|
+ citys = append(citys, qutil.ObjArrToStringArr(v.([]interface{}))...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ areaquery += `]}}`
|
|
|
+ if i > 0 {
|
|
|
+ areaCity = append(areaCity, areaquery)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //城市
|
|
|
+ if len(citys) > 0 {
|
|
|
+ //城市对应前三十个
|
|
|
+ if len(citys) > 30 {
|
|
|
+ citys = citys[:30]
|
|
|
+ }
|
|
|
+ areaquery := `{"terms":{"city":[`
|
|
|
+ for k, v := range citys {
|
|
|
+ if k > 0 {
|
|
|
+ areaquery += `,`
|
|
|
+ }
|
|
|
+ areaquery += `"` + v + `"`
|
|
|
+ }
|
|
|
+ areaquery += `]}}`
|
|
|
+ areaCity = append(areaCity, areaquery)
|
|
|
+ }
|
|
|
+ if len(areaCity) > 0 {
|
|
|
+ musts = append(musts, strings.Join(areaCity, ","))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //检索日期
|
|
|
+ var (
|
|
|
+ gteTime time.Time
|
|
|
+ gte int64
|
|
|
+ )
|
|
|
+ sTime := time.Now()
|
|
|
+ switch this.LimitTime {
|
|
|
+ case "oneYear":
|
|
|
+ gteTime = sTime.AddDate(-1, 0, 0)
|
|
|
+ case "threeYear":
|
|
|
+ gteTime = sTime.AddDate(-3, 0, 0)
|
|
|
+ case "fiveYear": // 默认近五年
|
|
|
+ gteTime = sTime.AddDate(-5, 0, 0)
|
|
|
+ default:
|
|
|
+ gte = qutil.Int64All(entity.P_Starttime)
|
|
|
+ }
|
|
|
+ if this.LimitTime != "" {
|
|
|
+ gte = time.Date(gteTime.Year(), 1, 1, 0, 0, 0, 0, time.Local).Unix()
|
|
|
+ }
|
|
|
+ //检索日期
|
|
|
+ if gte > 0 {
|
|
|
+ musts = append(musts, fmt.Sprintf(`{"range":{"jgtime":{"gte":%d,"lt":%d}}}`, gte, sTime.Unix()))
|
|
|
+ }
|
|
|
+ //中标项目
|
|
|
+ if entity.PSearch_DecMust != "" {
|
|
|
+ musts = append(musts, fmt.Sprintf(query_bool_must, entity.PSearch_DecMust))
|
|
|
+ }
|
|
|
+
|
|
|
+ boolsNum := 0
|
|
|
+ //should
|
|
|
+ if len(this.BuyerContent) > 0 {
|
|
|
+ boolsNum = 1
|
|
|
+ findfields := `"projectname.pname","purchasing"`
|
|
|
+ multi_match := fmt.Sprintf(multi_match_public, "%s", findfields)
|
|
|
+ for _, kv := range this.BuyerContent {
|
|
|
+ shoulds := []string{}
|
|
|
+ must_not := []string{}
|
|
|
+ //关键词
|
|
|
+ for _, v := range kv.Keyword {
|
|
|
+ shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+v+"\""))
|
|
|
+ }
|
|
|
+ //附加词
|
|
|
+ if len(kv.Appended) > 0 {
|
|
|
+ for _, vv := range kv.Appended {
|
|
|
+ shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+vv+"\""))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(kv.Exclude) > 0 {
|
|
|
+ //排除词
|
|
|
+ for _, vv := range kv.Exclude {
|
|
|
+ must_not = append(must_not, fmt.Sprintf(multi_match, "\""+vv+"\""))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //添加
|
|
|
+ if len(shoulds) > 0 {
|
|
|
+ notStr := ""
|
|
|
+ if len(must_not) > 0 {
|
|
|
+ notStr = fmt.Sprintf(`,"must_not":[%s]`, strings.Join(must_not, ","))
|
|
|
+ }
|
|
|
+ bools = append(bools, fmt.Sprintf(query_bool_must_and, strings.Join(shoulds, ","), notStr))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(bools) > 0 {
|
|
|
+ musts = append(musts, fmt.Sprintf(query_bool, strings.Join(bools, ","), boolsNum))
|
|
|
+ }
|
|
|
+
|
|
|
+ qstr = fmt.Sprintf(query, strings.Join(musts, ","))
|
|
|
+ log.Println("投标决策分析查询语句-中标企业和采购单位 类似项目明细", qstr)
|
|
|
+ return qstr
|
|
|
+}
|
|
|
+
|
|
|
// 投标决策分析查询语句 - 中标单位top10
|
|
|
func DecWinnerQuery(area map[string]interface{}, business_scope []ViewKeyWord, buyer, limitTime string, searchItem, hotWinnerType int) string {
|
|
|
//类似项目热点中标企业
|