|
@@ -184,13 +184,14 @@ func Save(index, itype string, obj interface{}) bool {
|
|
|
//{"query":{"match_all":{}},"from":10,"size":10,"_source":["account_number","balance"],"sort":{"balance":{"order":"desc"}}}
|
|
|
//{"query":{"match_phrase":{"address":"milllane"}}}和match不同会去匹配整个短语,相当于must[]
|
|
|
func DfsGet(index, itype, query string) (int64, *[]map[string]interface{}) {
|
|
|
- return get(index, itype, query, "dfs_query_then_fetch")
|
|
|
+ t, _, l := get(index, itype, query, "dfs_query_then_fetch", true, true)
|
|
|
+ return t, l
|
|
|
}
|
|
|
func Get(index, itype, query string) *[]map[string]interface{} {
|
|
|
- _, r := get(index, itype, query, "")
|
|
|
+ _, _, r := get(index, itype, query, "", true, true)
|
|
|
return r
|
|
|
}
|
|
|
-func get(index, itype, query, searchType string) (int64, *[]map[string]interface{}) {
|
|
|
+func get(index, itype, query, searchType string, isLimit, isHighlight bool) (int64, int, *[]map[string]interface{}) {
|
|
|
//log.Println("query -- ", query)
|
|
|
client := GetEsConn()
|
|
|
defer func() {
|
|
@@ -198,57 +199,6 @@ func get(index, itype, query, searchType string) (int64, *[]map[string]interface
|
|
|
}()
|
|
|
var res []map[string]interface{}
|
|
|
var total int64
|
|
|
- if client != nil {
|
|
|
- defer func() {
|
|
|
- if r := recover(); r != nil {
|
|
|
- log.Println("[E]", r)
|
|
|
- for skip := 1; ; skip++ {
|
|
|
- _, file, line, ok := runtime.Caller(skip)
|
|
|
- if !ok {
|
|
|
- break
|
|
|
- }
|
|
|
- go log.Printf("%v,%v\n", file, line)
|
|
|
- }
|
|
|
- }
|
|
|
- }()
|
|
|
- ss := client.Search().Index(index).Source(query)
|
|
|
- if searchType != "" {
|
|
|
- ss.SearchType(searchType)
|
|
|
- }
|
|
|
- searchResult, err := ss.Do(context.TODO())
|
|
|
- if err != nil {
|
|
|
- log.Println("从ES查询出错", err.Error())
|
|
|
- return total, nil
|
|
|
- }
|
|
|
- total = searchResult.TotalHits()
|
|
|
- if searchResult.Hits != nil {
|
|
|
- resNum := len(searchResult.Hits.Hits)
|
|
|
- if resNum < 5000 {
|
|
|
- res = make([]map[string]interface{}, resNum)
|
|
|
- for i, hit := range searchResult.Hits.Hits {
|
|
|
- //d := json.NewDecoder(bytes.NewBuffer(*hit.Source))
|
|
|
- //d.UseNumber()
|
|
|
- //d.Decode(&res[i])
|
|
|
- parseErr := json.Unmarshal(hit.Source, &res[i])
|
|
|
- if parseErr == nil && hit.Highlight != nil && res[i] != nil {
|
|
|
- res[i]["highlight"] = map[string][]string(hit.Highlight)
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.Println("查询结果太多,查询到:", resNum, "条")
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- return total, &res
|
|
|
-}
|
|
|
-func GetOA(index, itype, query string) (*[]map[string]interface{}, int) {
|
|
|
- //log.Println("query -- ", query)
|
|
|
- client := GetEsConn()
|
|
|
- defer func() {
|
|
|
- go DestoryEsConn(client)
|
|
|
- }()
|
|
|
- var res []map[string]interface{}
|
|
|
var resNum int
|
|
|
if client != nil {
|
|
|
defer func() {
|
|
@@ -266,19 +216,22 @@ func GetOA(index, itype, query string) (*[]map[string]interface{}, int) {
|
|
|
searchResult, err := client.Search().Index(index).Source(query).Do(context.TODO())
|
|
|
if err != nil {
|
|
|
log.Println("从ES查询出错", err.Error())
|
|
|
- return nil, 0
|
|
|
+ return total, resNum, nil
|
|
|
}
|
|
|
-
|
|
|
+ total = searchResult.TotalHits()
|
|
|
if searchResult.Hits != nil {
|
|
|
resNum = len(searchResult.Hits.Hits)
|
|
|
- if resNum < 5000 {
|
|
|
+ if isLimit && resNum < 5000 {
|
|
|
res = make([]map[string]interface{}, resNum)
|
|
|
for i, hit := range searchResult.Hits.Hits {
|
|
|
//d := json.NewDecoder(bytes.NewBuffer(*hit.Source))
|
|
|
//d.UseNumber()
|
|
|
//d.Decode(&res[i])
|
|
|
parseErr := json.Unmarshal(hit.Source, &res[i])
|
|
|
- if parseErr == nil && hit.Highlight != nil && res[i] != nil {
|
|
|
+ if res[i] != nil {
|
|
|
+ res[i]["_id"] = hit.Id
|
|
|
+ }
|
|
|
+ if isHighlight && parseErr == nil && hit.Highlight != nil && res[i] != nil {
|
|
|
res[i]["highlight"] = map[string][]string(hit.Highlight)
|
|
|
}
|
|
|
}
|
|
@@ -288,45 +241,16 @@ func GetOA(index, itype, query string) (*[]map[string]interface{}, int) {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- return &res, resNum
|
|
|
+ return total, resNum, &res
|
|
|
+}
|
|
|
+func GetOA(index, itype, query string) (*[]map[string]interface{}, int) {
|
|
|
+ _, n, l := get(index, itype, query, "", true, true)
|
|
|
+ return l, n
|
|
|
}
|
|
|
|
|
|
func GetNoLimit(index, itype, query string) *[]map[string]interface{} {
|
|
|
- //log.Println("query -- ", query)
|
|
|
- client := GetEsConn()
|
|
|
- defer DestoryEsConn(client)
|
|
|
- var res []map[string]interface{}
|
|
|
- if client != nil {
|
|
|
- defer func() {
|
|
|
- if r := recover(); r != nil {
|
|
|
- log.Println("[E]", r)
|
|
|
- for skip := 1; ; skip++ {
|
|
|
- _, file, line, ok := runtime.Caller(skip)
|
|
|
- if !ok {
|
|
|
- break
|
|
|
- }
|
|
|
- go log.Printf("%v,%v\n", file, line)
|
|
|
- }
|
|
|
- }
|
|
|
- }()
|
|
|
- searchResult, err := client.Search().Index(index).Source(query).Do(context.TODO())
|
|
|
- if err != nil {
|
|
|
- log.Println("从ES查询出错", err.Error())
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
- if searchResult.Hits != nil {
|
|
|
- resNum := len(searchResult.Hits.Hits)
|
|
|
- res = make([]map[string]interface{}, resNum)
|
|
|
- for i, hit := range searchResult.Hits.Hits {
|
|
|
- json.Unmarshal(hit.Source, &res[i])
|
|
|
- if res[i] != nil {
|
|
|
- res[i]["_id"] = hit.Id
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return &res
|
|
|
+ _, _, l := get(index, itype, query, "", false, false)
|
|
|
+ return l
|
|
|
}
|
|
|
|
|
|
//分页查询
|
|
@@ -600,134 +524,6 @@ func UpdateNewDoc(index, itype string, obj ...interface{}) bool {
|
|
|
return b
|
|
|
}
|
|
|
|
|
|
-//把地市代码转为地市
|
|
|
-func getLoc(code string, res *map[string]string) (loc string) {
|
|
|
- switch len(code) {
|
|
|
- case 6:
|
|
|
- loc = (*res)[code[:2]] + " " + (*res)[code[:4]] + " " + (*res)[code]
|
|
|
- break
|
|
|
- case 4:
|
|
|
- loc = (*res)[code[:2]] + " " + (*res)[code]
|
|
|
- break
|
|
|
- case 2:
|
|
|
- loc = (*res)[code]
|
|
|
- break
|
|
|
- }
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func ConverData(ent *map[string]interface{}) map[string]interface{} {
|
|
|
- tmp := *ent
|
|
|
- id64, _ := tmp["ID"].(int64)
|
|
|
- ids := fmt.Sprintf("%d", id64)
|
|
|
- tmp2 := make(map[string]interface{})
|
|
|
- tmp2["ID"] = ids
|
|
|
- tmp2["_id"] = tmp["_id"]
|
|
|
- tmp2["id"] = tmp["_id"]
|
|
|
- tmp2["Area"] = tmp["Area"]
|
|
|
- tmp2["LeRep"] = tmp["LeRep"]
|
|
|
- tmp2["RegNo"] = tmp["RegNo"]
|
|
|
- tmp2["EntType"] = tmp["EntType"]
|
|
|
- tmp2["EntName"] = tmp["EntName"]
|
|
|
- tmp2["EntTypeName"] = tmp["EntTypeName"]
|
|
|
- tmp2["Dom"] = tmp["Dom"]
|
|
|
- tmp2["EstDate"] = tmp["EstDate"]
|
|
|
- tmp2["OpStateName"] = tmp["OpStateName"]
|
|
|
- tmp2["OpScope"] = tmp["OpScope"]
|
|
|
- tmp2["OpState"] = tmp["OpState"]
|
|
|
- tmp2["s_submitid"] = tmp["s_submitid"]
|
|
|
- tmp2["l_submittime"] = tmp["l_submittime"]
|
|
|
- tmp2["s_submitname"] = tmp["s_submitname"]
|
|
|
- tmp2["RegCapCurName"] = tmp["RegCapCurName"]
|
|
|
- //增加营业状态排序
|
|
|
- if tmp2["OpState"] == "06" {
|
|
|
- tmp2["OpSint"] = true
|
|
|
- } else {
|
|
|
- tmp2["OpSint"] = false
|
|
|
- }
|
|
|
- tmp2["OpLocDistrict"] = tmp["OpLocDistrict"]
|
|
|
- //增加代码转名称
|
|
|
- tmpLoc, _ := tmp["OpLocDistrict"].(string)
|
|
|
- tmp2["OpLocDistrictName"] = getLoc(tmpLoc, &LocCity)
|
|
|
-
|
|
|
- tmp2["RecCap"] = tmp["RecCap"]
|
|
|
- tmp2["RegCap"] = tmp["RegCap"]
|
|
|
- tmp2["IndustryPhy"] = tmp["IndustryPhy"]
|
|
|
- tmp2["IndustryPhyName"] = tmp["IndustryPhyName"]
|
|
|
- tmp2["RegOrg"] = tmp["RegOrg"]
|
|
|
- tmp2["RegOrgName"] = tmp["RegOrgName"]
|
|
|
- tmp2["Tel"] = tmp["Tel"]
|
|
|
- tmp2["CompForm"] = tmp["CompForm"]
|
|
|
- tmp2["CompFormName"] = tmp["CompFormName"]
|
|
|
- //增加异常名录标记 Ycml可能是bool也可能是string
|
|
|
- Ycmlb, _ := tmp["Ycml"].(bool)
|
|
|
- Ycmls, _ := tmp["Ycml"].(string)
|
|
|
- if Ycmlb || Ycmls == "1" {
|
|
|
- tmp2["Ycml"] = true
|
|
|
- } else {
|
|
|
- tmp2["Ycml"] = false
|
|
|
- }
|
|
|
- //增加年报联系信息
|
|
|
- if tmp["Nb_email"] != nil {
|
|
|
- tmp2["Nb_email"] = tmp["Nb_email"]
|
|
|
- }
|
|
|
- if tmp["Nb_tel"] != nil {
|
|
|
- tmp2["Nb_tel"] = tmp["Nb_tel"]
|
|
|
- }
|
|
|
- if tmp["Nb_addr"] != nil {
|
|
|
- tmp2["Nb_addr"] = tmp["Nb_addr"]
|
|
|
- }
|
|
|
-
|
|
|
- s_synopsis := tmp["s_synopsis"]
|
|
|
- if s_synopsis == nil {
|
|
|
- s_synopsis = ""
|
|
|
- }
|
|
|
- tmp2["s_synopsis"] = s_synopsis //企业简介
|
|
|
-
|
|
|
- //股东
|
|
|
- stock := getStock(tmp["investor"])
|
|
|
- tmp2["stock"] = stock
|
|
|
-
|
|
|
- tmp2["LegCerNO"] = tmp["LegCerNO"]
|
|
|
- if tmp["s_microwebsite"] != nil {
|
|
|
- tmp2["s_microwebsite"] = tmp["s_microwebsite"]
|
|
|
- }
|
|
|
-
|
|
|
- tmp2["SourceType"] = tmp["SourceType"] //数据来源
|
|
|
- s_servicenames := tmp["s_servicenames"]
|
|
|
- if s_servicenames == nil {
|
|
|
- s_servicenames = ""
|
|
|
- }
|
|
|
- tmp2["s_servicenames"] = s_servicenames //服务名称
|
|
|
- s_action := tmp["s_action"]
|
|
|
- if s_action == nil {
|
|
|
- s_action = "N"
|
|
|
- }
|
|
|
- tmp2["s_action"] = s_action
|
|
|
- tmp2["s_persion"] = tmp["s_persion"]
|
|
|
- tmp2["s_mobile"] = tmp["s_mobile"]
|
|
|
- tmp2["s_enturl"] = tmp["s_enturl"]
|
|
|
- tmp2["s_weixin"] = tmp["s_weixin"]
|
|
|
- tmp2["s_avatar"] = tmp["s_avatar"]
|
|
|
- return tmp2
|
|
|
-}
|
|
|
-
|
|
|
-func getStock(obj interface{}) string {
|
|
|
- stock := ""
|
|
|
- if ns, ok := obj.([]interface{}); ok {
|
|
|
- stock = " "
|
|
|
- for _, ns1 := range ns {
|
|
|
- if nn, ok1 := ns1.(map[string]interface{}); ok1 {
|
|
|
- tmp := fmt.Sprintf("%s", nn["Inv"])
|
|
|
- if strings.Index(stock, tmp) < 0 {
|
|
|
- stock += tmp + " "
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return stock
|
|
|
-}
|
|
|
-
|
|
|
func BulkSave(index, itype string, obj *[]map[string]interface{}, isDelBefore bool) {
|
|
|
client := GetEsConn()
|
|
|
defer DestoryEsConn(client)
|