From 89a3b406aabf07ba6faf0b6eb2a0c147d62b75d5 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期二, 28 七月 2020 19:08:22 +0800
Subject: [PATCH] add log

---
 esutil/EsClient.go |   40 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/esutil/EsClient.go b/esutil/EsClient.go
index 7215b26..ddadef7 100644
--- a/esutil/EsClient.go
+++ b/esutil/EsClient.go
@@ -98,6 +98,22 @@
 			if !exist {
 				continue
 			}
+			alarmRules, exist := source["alarmRules"]
+			if exist {
+				fmt.Println("exist alarmRules")
+				if alarmB,ae := json.Marshal(alarmRules);ae ==nil {
+					var alarmRArr []AlarmRule
+					if ae = json.Unmarshal(alarmB, &alarmRArr);ae ==nil && len(alarmRArr) >0 {
+						d["alarmLevel"] = alarmRArr[0].AlarmLevel
+					} else {
+						fmt.Println("unmarshal ae:", ae)
+					}
+				} else {
+					fmt.Println("ae:", ae)
+				}
+			} else {
+				d["alarmLevel"] = ""
+			}
 			pmArr := pmax.([]interface{})
 			if len(pmArr) > 0 {
 				d["picMaxUrl"] = pmArr[0]
@@ -146,8 +162,12 @@
 				d["picSmUrl"] = d["picMaxUrl"]
 			}
 
-
-			d["videoNum"] = source["videoUrl"]
+			vUri := source["videoUrl"]
+			if vUri != nil && vUri.(string) != "" {
+				d["videoNum"] = "http://"+vUri.(string)
+			} else {
+				d["videoNum"] = ""
+			}
 
 			sources = append(sources, d)
 		}
@@ -156,6 +176,11 @@
 	} else {
 		return nil, dat
 	}
+}
+
+type AlarmRule struct {
+	GroupId 			string 			`json:"groupId"`
+	AlarmLevel 			string 			`json:"alarmLevel"`
 }
 
 type TargetInfo struct {
@@ -259,19 +284,24 @@
 		preSec = strconv.Itoa(sec)
 	}
 	var filterArr []string
+	var mustNotArr []string
 	//鏄惁鏌ユ姤璀︽暟鎹�
 	if ishub == "hub" {
-		filterArr = append(filterArr,"{\"term\":{\"alarmRules.alarmLevel.raw\":\"浜岀骇\"}}")
+		mustNotArr = append(mustNotArr,"{\"term\":{\"alarmRules.alarmLevel.raw\":\"浜旂骇\"}}")
 	}
 
 	filterArr = append(filterArr, "{\"range\":{\"picDate\":{\"gte\":\"now+8h-"+preSec+"s\",\"lt\":\"now+8h\"}}}")
 
 	filterStr := ""
+	mustNotStr := ""
 	if len(filterArr) >0 {
 		filterStr = strings.Join(filterArr, ",")
 	}
-	param := "{\"query\":{\"bool\":{\"filter\":["+filterStr+"]}},\"size\":\""+sizeStr+"\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," +
-		"\"_source\":{\"includes\":[\"cameraAddr\",\"baseInfo\",\"targetInfo\",\"content\",\"id\",\"picMaxUrl\",\"picDate\",\"showLabels\",\"taskName\",\"sdkName\",\"videoUrl\"],\"excludes\":[\"*.feature\",\"*.attachTarget\",\"*.targetLocation\",\"alarmRules\"]}" +
+	if len(mustNotArr) > 0 {
+		mustNotStr = strings.Join(mustNotArr, ",")
+	}
+	param := "{\"query\":{\"bool\":{\"filter\":["+filterStr+"],\"must_not\":["+mustNotStr+"]}},\"size\":\""+sizeStr+"\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," +
+		"\"_source\":{\"includes\":[\"cameraAddr\",\"baseInfo\",\"targetInfo\",\"content\",\"id\",\"picMaxUrl\",\"picDate\",\"showLabels\",\"taskName\",\"sdkName\",\"videoUrl\",\"alarmRules\"],\"excludes\":[\"*.feature\",\"*.attachTarget\",\"*.targetLocation\",\"alarmRules\"]}" +
 		"}"
 	err, tokenRes := GetEsDataReq(url, param, true)
 

--
Gitblit v1.8.0