From f88a44f58396fb36a979cfe5640a36d6ac2d7289 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期四, 25 七月 2019 14:50:56 +0800 Subject: [PATCH] add discovery --- controllers/esSearch.go | 49 +++++++++++++++++++++++++++++-------------------- 1 files changed, 29 insertions(+), 20 deletions(-) diff --git a/controllers/esSearch.go b/controllers/esSearch.go index 27e21eb..971857d 100644 --- a/controllers/esSearch.go +++ b/controllers/esSearch.go @@ -32,35 +32,33 @@ data := findEsData(searchBody) util.ResponseFormat(c, code.Success, data) } - -func getAlarmLevel(alarmlevel int) (string) { +//鑾峰彇鐩戞帶绛夌骇 +func getAlarmLevel(alarmlevel []int) ([]string) { d := dbapi.DicApi{} res,data := d.FindByType("ALARMLEVEL") if data == nil { - fmt.Println("data is nil") + fmt.Println("dsadasd") } fmt.Println(res) // fmt.Println(data) alarmLevel := make(map[int]string) tmp := data.(map[string]interface{}) - for _,value := range tmp["ALARMLEVEL"].([]interface{}) { // fmt.Println(value.(map[string]interface{})["value"]," ",value.(map[string]interface{})["name"]) val := value.(map[string]interface{})["value"].(string) name := value.(map[string]interface{})["name"].(string) vl,err := strconv.Atoi(val) if err != nil { - fmt.Println(err) + fmt.Println("dsadas") } alarmLevel[vl] = name - } - - // fmt.Println(alarmLevel) - - alarmLevelRes = alarmLevel[alarmlevel] - return alarmLevelRes + alarmLevelRes := make([]string,len(alarmlevel)) + for i,v := range alarmlevel { + alarmLevelRes[i] = alarmLevel[v] + } + return alarmLevelRes } func findEsData(searchBody map[string]interface{}) map[string]interface{} { @@ -113,18 +111,28 @@ isCollectStr = "{\"term\":{\"isCollect\":\"" + isCollect + "\"}}," } //鍒ゆ柇甯冮槻绛夌骇id - alarmLevelId :=searchBody["alarmlevel"].(int) + alarmLevelId :=searchBody["alarmlevel"].([]int) alarmLevelStr := "" - if alarmLevelId != nil && alarmLevelId != 0{ - if alarmLevelId != -1 { - id := getAlarmLevel(alarmLevelId) - alarmLevelStr = "{\"terms\":{\"alarmRules.alarmLevel\":[\"" + id + "\"]}},{\"terms\":{\"alarmRules.defenceState\":[\"true\"]}}," - - }else{ - alarmLevelStr = "{\"terms\":{\"alarmRules.defenceState\":[\"false\"]}}," + defenceStateStr := "" + if len(alarmLevelId) > 0 { + flag := false + for i,v := range alarmLevelId { + if v == -1 { + alarmLevelId = append(alarmLevelId[:i], alarmLevelId[i+1:]...) + defenceStateStr = "{\"term\":{\"alarmRules.defenceState\":false}}," + flag = true + break + } + } + if len(alarmLevelId) > 0{ + if flag == false { + defenceStateStr = "{\"term\":{\"alarmRules.defenceState\":true}}," + } + id := strings.Replace(strings.Trim(fmt.Sprint(getAlarmLevel(alarmLevelId)), "[]"), " ", "\",\"", -1) + alarmLevelStr = "{\"terms\":{\"alarmRules.alarmLevel\":[\"" + id + "\"]}}," } } - + //浣跨敤es搴曞眰鏈哄埗澶勭悊鍒嗛〉 //璇锋眰澶� url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + @@ -140,6 +148,7 @@ "\"filter\":[" + cameraIdStr + alarmLevelStr + + defenceStateStr + taskIdStr + isCollectStr + esTableIdStr + -- Gitblit v1.8.0