From 74f4798a0f8578aa4609cd05f57f19f43a115afc Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期二, 28 七月 2020 20:06:55 +0800
Subject: [PATCH] fix face to FaceDetect

---
 esutil/EsClient.go |   29 +++++++++++++++++++++++++----
 1 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/esutil/EsClient.go b/esutil/EsClient.go
index 55c0d5b..ea1a079 100644
--- a/esutil/EsClient.go
+++ b/esutil/EsClient.go
@@ -98,6 +98,17 @@
 			if !exist {
 				continue
 			}
+			alarmRules, exist := source["alarmRules"]
+			if exist {
+				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 {
+				d["alarmLevel"] = ""
+			}
 			pmArr := pmax.([]interface{})
 			if len(pmArr) > 0 {
 				d["picMaxUrl"] = pmArr[0]
@@ -121,7 +132,7 @@
 			if len(tiArr) > 0 {
 				ti := tiArr[0]
 				d["picSmUrl"] = ti.PicSmUrl
-				if ti.TargetType == "face" {
+				if ti.TargetType == "FaceDetect" {
 					sLabelStr, ok := source["showLabels"]
 					if ok {
 						labelArr := strings.Split(sLabelStr.(string), "/")
@@ -160,6 +171,11 @@
 	} else {
 		return nil, dat
 	}
+}
+
+type AlarmRule struct {
+	GroupId 			string 			`json:"groupId"`
+	AlarmLevel 			string 			`json:"alarmLevel"`
 }
 
 type TargetInfo struct {
@@ -263,19 +279,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\"]}" +
 		"}"
 	err, tokenRes := GetEsDataReq(url, param, true)
 

--
Gitblit v1.8.0