From c6ae506a28e9ce6463822bfea5369856acf980e0 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期四, 14 一月 2021 18:19:37 +0800
Subject: [PATCH] add cameraIds to AggregateTaskList

---
 EsClient.go |   11 +++++++++--
 EsApi.go    |   14 ++++++++++++--
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/EsApi.go b/EsApi.go
index 96348c7..f60a1b6 100644
--- a/EsApi.go
+++ b/EsApi.go
@@ -1276,10 +1276,19 @@
 }
 
 //鑱氬悎浠诲姟鍒楄〃锛宼askId+taskName
-func AggregateTaskList(serverIp string, serverPort string, indexName string, analyServerId string) (sources []map[string]interface{}, err error) {
+func AggregateTaskList(serverIp string, serverPort string, indexName string, analyServerId string, cameraIds []string) (sources []map[string]interface{}, err error) {
 	url := "http://" + serverIp + ":" + serverPort +
 		"/" + indexName + "/_search"
 	serverFilterStr := ""
+	cameIdFilterStr := ""
+	if cameraIds != nil && len(cameraIds) > 0 {
+		cameIdsStr := strings.Replace(strings.Trim(fmt.Sprint(cameraIds), "[]"), " ", "\",\"", -1)
+		cameIdFilterStr = `,{
+				"term": {
+				"cameraId": "` + cameIdsStr + `"
+					}
+                }`
+	}
 	if analyServerId != "" {
 		serverFilterStr = `,
 			"query": {
@@ -1288,8 +1297,9 @@
 				{
 				"term": {
 				"analyServerId": "` + analyServerId + `"
+					}
 				}
-				}
+ 				` + cameIdFilterStr + `
 			]
 			}
 		}`
diff --git a/EsClient.go b/EsClient.go
index f63abff..d8c9db5 100644
--- a/EsClient.go
+++ b/EsClient.go
@@ -1033,8 +1033,15 @@
 	if !ok {
 		return -1, errors.New("first total change error!")
 	}
-	tmp := middle["total"].(float64)
-	total = int(tmp)
+
+	tmp,b := middle["total"].(map[string]interface{})
+	if b != true {
+		v := middle["total"].(float64)
+		t := int(v)
+		return t,nil
+	}
+	value := tmp["value"].(float64)
+	total = int(value)
 	return total, nil
 }
 

--
Gitblit v1.8.0