From 75c6f6fea50b977cb72a50f4609a5cbbbf235c35 Mon Sep 17 00:00:00 2001
From: sunty <suntianyu0923@163.com>
Date: 星期一, 29 七月 2019 10:07:56 +0800
Subject: [PATCH] delete analyServerId omitempty

---
 controllers/esSearch.go |   56 ++++++++++++++++++++++----------------------------------
 1 files changed, 22 insertions(+), 34 deletions(-)

diff --git a/controllers/esSearch.go b/controllers/esSearch.go
index 0a9f139..4e23425 100644
--- a/controllers/esSearch.go
+++ b/controllers/esSearch.go
@@ -5,6 +5,7 @@
 	"fmt"
 	"strconv"
 	"strings"
+	"webserver/extend/logger"
 
 	"github.com/gin-gonic/gin"
 	"webserver/extend/code"
@@ -33,30 +34,33 @@
 	util.ResponseFormat(c, code.Success, data)
 }
 //鑾峰彇鐩戞帶绛夌骇
-func getAlarmLevel(alarmlevel []int) ([]string) {
+func getAlarmLevel(alarmlevel []interface{}) ([]string) {
 	d := dbapi.DicApi{}
         res,data := d.FindByType("ALARMLEVEL")
         if data == nil {
-                fmt.Println("dsadasd")
+                logger.Debug("data is nil")
         }
-	fmt.Println(res)
-		// fmt.Println(data)
+	logger.Debug(res)
+		// logger.Debug(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"]) 
+			// logger.Debug(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("dsadas")
+				logger.Debug(err)
 			}
 			alarmLevel[vl] = name
 		}
 	alarmLevelRes := make([]string,len(alarmlevel))
 		for i,v := range  alarmlevel  {
-			alarmLevelRes[i] =  alarmLevel[v]
+			if v.(int) < 0 {
+				alarmLevelRes[i] = "鎾ら槻"
+			}else {
+				alarmLevelRes[i] =  alarmLevel[v.(int)]
+			}
 		}
 	return alarmLevelRes	
 }
@@ -111,27 +115,12 @@
 		isCollectStr = "{\"term\":{\"isCollect\":\"" + isCollect + "\"}},"
 	}
 	//鍒ゆ柇甯冮槻绛夌骇id
-	// alarmLevelId :=searchBody["alarmlevel"].([]int)
-	// alarmLevelStr := ""
-	// 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 + "\"]}},"		
-	// 	}
-	// }
+	alarmLevelId :=searchBody["alarmlevel"].([]interface{})
+	alarmLevelStr := ""
+	if len(alarmLevelId) > 0 {
+		alarmLevelTypes := strings.Replace(strings.Trim(fmt.Sprint(getAlarmLevel(alarmLevelId)), "[]"), " ", "\",\"", -1)
+		alarmLevelStr = "{\"terms\":{\"alarmRules.alarmLevel\":[\"" + alarmLevelTypes + "\"]}},"
+	}
 		
 	//浣跨敤es搴曞眰鏈哄埗澶勭悊鍒嗛〉
 	//璇锋眰澶�
@@ -147,8 +136,7 @@
 		"\"query\":{\"bool\":{" + queryStr +
 		"\"filter\":[" +
 		cameraIdStr +
-		// alarmLevelStr +
-		// defenceStateStr +
+		alarmLevelStr +
 		taskIdStr +
 		isCollectStr +
 		esTableIdStr +
@@ -157,7 +145,7 @@
 		"\"sort\":[{\"_score\":{\"order\":\"desc\"}},{\"picDate\":{\"order\":\"desc\"}}]," +
 		"\"_source\":[\"baseInfo\",\"alarmRules\",\"sex\",\"analyServerName\",\"sdkName\",\"ageDescription\",\"content\",\"id\",\"cameraAddr\",\"picMaxUrl\",\"picDate\",\"race\",\"videoUrl\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"isAlarm\",\"analyServerIp\",\"cameraId\"]" +
 		"}"
-	fmt.Println(prama)
+	logger.Debug(prama)
 	//鏁版嵁瑙f瀽
 	tokenRes := esutil.GetEsDataReq(url, prama, true)
 	return tokenRes
@@ -178,7 +166,7 @@
 
 	tokenRes := esutil.GetEsDataReq(url, prama, true)
 	personRes := make(map[string]string)
-	//fmt.Println(tokenRes["datalist"].([]interface{}))
+	//logger.Debug(tokenRes["datalist"].([]interface{}))
 	result := tokenRes["datalist"].([]interface{})
 	for _, value := range result {
 		userMap := value.(map[string]interface{})
@@ -200,7 +188,7 @@
 		// personRes["phoneNum"] = value.(map[string]interface{})["phoneNum"].(string)
 		// personRes["sex"] = value.(map[string]interface{})["sex"].(string)
 	}
-	//fmt.Println(personRes)
+	//logger.Debug(personRes)
 	if len(personRes) < 1 {
 		personRes["personName"] = ""
 		personRes["phoneNum"] = ""

--
Gitblit v1.8.0