liuxiaolong
2019-06-15 1efc7ae174f57e6a0a96ccfe4efadc9390589b5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package service
 
import (
    "encoding/json"
    "fmt"
    "webserver/extend/config"
    "webserver/extend/esutil"
    "webserver/models"
)
 
// 地库人员数据 为 比对做准备
func QueryDbPersonsForCompare(reqBody models.EsSearch) map[string]interface{} {
    url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
        "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_search"
    tableIds := make([]string, 20)
    if reqBody.DataBases != nil {
        tableIds = reqBody.DataBases
    }
    startDate := "";endDate := ""
    if reqBody.SearchTime != nil && len(reqBody.SearchTime) >= 2 {
        dates := reqBody.SearchTime
        startDate = dates[0];endDate = dates[1] // 起始结束时间
    }
    contentValue := reqBody.InputValue //输入框内容
    /*page := 1 ;if reqBody["page"] != nil { page = int(reqBody["page"].(float64))       } // 页码
    size := 8 ;if reqBody["size"] != nil { size = int(reqBody["size"].(float64))       }// 条数
    from := (page - 1) * size
    */
    syncTerm := ""
    contentParam := ""
    if len(tableIds) < 1 {
        // / 所有人员
    } else {
        bytes, _ := json.Marshal(tableIds)
        syncTerm += ",{\"terms\":{\"tableId\":" + string(bytes) + "}}" // 底库人员
    }
    if startDate != "" && endDate != "" {
        syncTerm += ",{\"range\":{\"create_time\":{\"from\":\"" + startDate + "\"," +
            "\"to\":\"" + endDate + "\",\"include_lower\":true,\"include_upper\":true,\"boost\":1}}}" // 底库人员
    }
    if contentValue != "" {
        contentParam = ",\"must\":[{\"multi_match\":{\"query\":\"" + contentValue + "\",\"type\":\"best_fields\"," +
            "\"fields\":[\"personName\",\"sex\",\"idcard\",\"phoneNum\",\"reserved\"],\"boost\":1}}]"
    }
    params := "{\"query\":{\"bool\":{\"filter\":[" +
        "{\"term\":{\"del_flag\":\"0\"}}" + syncTerm + "]" + contentParam + "}},\"from\":0,\"size\":10000,\"sort\":{\"uuid\":{\"order\":\"desc\"}}}"
    fmt.Print("查询全部底库人员 请求url:%s;\n 请求参数params:%s", url, params)
    data := esutil.GetEsDataReq(url, params, true)
    return data
}