Browse Source

Merge branch 'dev4.5' of http://192.168.3.207:8080/qmx/jy into dev4.5

zhangyuhan 4 years ago
parent
commit
87a2c0efb2

+ 45 - 4
src/jfw/modules/publicapply/src/enterpriseSearch/entity/entQuery.go

@@ -1,10 +1,13 @@
 package entity
 package entity
 
 
 import (
 import (
+	"config"
+	"encoding/json"
 	"fmt"
 	"fmt"
 	"log"
 	"log"
 	qutil "qfw/util"
 	qutil "qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/elastic"
+	"qfw/util/redis"
 	"strings"
 	"strings"
 )
 )
 
 
@@ -26,8 +29,10 @@ type EnterpriseSearch struct {
 }
 }
 
 
 const (
 const (
-	searchMaxLimit = 100 //最大查询数量限制
-	freeSearchNum  = 5   //免费查询数量限制
+	searchMaxLimit    = 100 //最大查询数量限制
+	freeSearchNum     = 5   //免费查询数量限制
+	entSearchCacheDB  = "other"
+	entSearchCacheKey = "entSearchIndexCache"
 
 
 	index, itype = "qyxy", "qyxy"
 	index, itype = "qyxy", "qyxy"
 	entQuery     = `{"query":{"bool":{"must":[%s]}},"_source":["_id","company_name","company_status","legal_person","capital","company_address","company_shortname"]}`
 	entQuery     = `{"query":{"bool":{"must":[%s]}},"_source":["_id","company_name","company_status","legal_person","capital","company_address","company_shortname"]}`
@@ -103,11 +108,28 @@ func (es *EnterpriseSearch) Check() (*EnterpriseSearch, error) {
 	return es, nil
 	return es, nil
 }
 }
 
 
+//判断是否是空查询
+func (es *EnterpriseSearch) isEmptySearch() bool {
+	if es.Match == "" &&
+		(es.MatchType == "" ||
+			es.MatchType == "A") &&
+		es.EntArea == "" &&
+		es.EntCity == "" &&
+		es.EntCapital == "" &&
+		es.EntType == "" &&
+		es.EntStatus == "" &&
+		es.BiddingArea == "" &&
+		es.EntClass == "" &&
+		es.EntContact == "" {
+		return true
+	}
+	return false
+}
+
 //GetQuerySql 获取检索语句
 //GetQuerySql 获取检索语句
 //return  company_name、company_status、legal_person、capital、company_address、id、company_shortname
 //return  company_name、company_status、legal_person、capital、company_address、id、company_shortname
 //返回字段 企业名称、企业状态、法人、注册资本、地址、企业id、企业简称
 //返回字段 企业名称、企业状态、法人、注册资本、地址、企业id、企业简称
 func (es *EnterpriseSearch) GetQuerySql() string {
 func (es *EnterpriseSearch) GetQuerySql() string {
-
 	musts := make([]string, 0, 0)
 	musts := make([]string, 0, 0)
 	//输入查询
 	//输入查询
 	if es.Match != "" { //或关系 仅需满足一个
 	if es.Match != "" { //或关系 仅需满足一个
@@ -188,6 +210,10 @@ func (es *EnterpriseSearch) GetQuerySql() string {
 
 
 //DoQuery 根据EnterpriseSearch参数进行企业相关查询
 //DoQuery 根据EnterpriseSearch参数进行企业相关查询
 func (es *EnterpriseSearch) DoQuery() (list *[]map[string]interface{}, total int64, err error) {
 func (es *EnterpriseSearch) DoQuery() (list *[]map[string]interface{}, total int64, err error) {
+	if es.isEmptySearch() { //是否是空查询,返回默认企业
+		list = GetEntIndexShow()
+		return
+	}
 	sql := es.GetQuerySql()
 	sql := es.GetQuerySql()
 	log.Println("EnterpriseSearch DoQuery sql", sql)
 	log.Println("EnterpriseSearch DoQuery sql", sql)
 
 
@@ -228,7 +254,22 @@ func getCompanyShortName(entName string) string {
 		return ""
 		return ""
 	}
 	}
 	//去掉省、市、县、区、路
 	//去掉省、市、县、区、路
-
 	//截取四个字符
 	//截取四个字符
 	return ""
 	return ""
 }
 }
+
+func GetEntIndexShow() (list *[]map[string]interface{}) {
+	bytes, err := redis.GetBytes(entSearchCacheDB, entSearchCacheKey)
+	if err == nil {
+		if err = json.Unmarshal(*bytes, &list); err == nil && list != nil && len(*list) > 0 {
+			return
+		}
+	}
+	sql := fmt.Sprintf(entQuery, fmt.Sprintf(`{"terms":{"_id":["%s"]}}`, strings.Join(config.Config.DefaultEntList, "\",\"")))
+	listTmp := elastic.Get(index, itype, sql)
+	if listTmp != nil && len(*listTmp) > 0 {
+		list = formatData(listTmp)
+		redis.Put(entSearchCacheDB, entSearchCacheKey, list, 60*60*10)
+	}
+	return
+}

+ 0 - 31
src/jfw/modules/publicapply/src/enterpriseSearch/entity/indexShow.go

@@ -1,31 +0,0 @@
-package entity
-
-import (
-	"encoding/json"
-	"fmt"
-	"jfw/modules/publicapply/src/config"
-	"qfw/util/elastic"
-	"qfw/util/redis"
-	"strings"
-)
-
-const (
-	entSearchCacheDB  = "other"
-	entSearchCacheKey = "entSearchIndexCache"
-)
-
-func GetEntIndexShow() (list *[]map[string]interface{}) {
-	bytes, err := redis.GetBytes(entSearchCacheDB, entSearchCacheKey)
-	if err == nil {
-		if err = json.Unmarshal(*bytes, &list); err == nil && list != nil && len(*list) > 0 {
-			return
-		}
-	}
-	sql := fmt.Sprintf(entQuery, fmt.Sprintf(`{"terms":{"_id":["%s"]}}`, strings.Join(config.Config.DefaultEntList, "\",\"")))
-	listTmp := elastic.Get(index, itype, sql)
-	if listTmp != nil && len(*listTmp) > 0 {
-		list = formatData(listTmp)
-		redis.Put(entSearchCacheDB, entSearchCacheKey, list, 60*60*10)
-	}
-	return
-}

+ 1 - 2
src/jfw/modules/publicapply/src/enterpriseSearch/service/search.go

@@ -12,8 +12,7 @@ import (
 
 
 type EnterpriseSearchAction struct {
 type EnterpriseSearchAction struct {
 	*xweb.Action
 	*xweb.Action
-	doEntSearch     xweb.Mapper `xweb:"/enterpriseSearch/doQuery"` //企业搜索
-	defaultEntIndex xweb.Mapper `xweb:"/enterpriseSearch/index"`   //企业搜索-默认展示
+	doEntSearch xweb.Mapper `xweb:"/enterpriseSearch/doQuery"` //企业搜索
 }
 }
 
 
 //企业搜索
 //企业搜索