From 61c76d09c574cbd308294dae7a2e9115d1ce5004 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期四, 30 五月 2024 13:42:08 +0800
Subject: [PATCH] 调整进出异常过滤 置在数据段

---
 db/elastic.go |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/db/elastic.go b/db/elastic.go
index de9734d..2f0f9d3 100644
--- a/db/elastic.go
+++ b/db/elastic.go
@@ -34,7 +34,8 @@
 	return captureInfos, nil
 }
 
-func QueryTimesByDocNumberDays(days int, docNumber string) (int, error) {
+func QueryTimesByDocNumberDays(docNumber string, communityId string, cameraIds []string, days int) (int, error) {
+	cameraIdsStr := strings.Replace(strings.Trim(fmt.Sprint(cameraIds), "[]"), " ", "\",\"", -1)
 	esURL := "http://" + config.Elastic.Host + ":" + config.Elastic.Port + "/" + config.Elastic.Index + "/_search"
 	queryDSL := `{
     "query": {
@@ -50,6 +51,16 @@
                 {
                     "term": {
                         "documentNumber": "` + docNumber + `"
+                    }
+                },
+                {
+                    "term": {
+                        "communityId": "` + communityId + `"
+                    }
+                },
+                {
+                    "terms": {
+                        "cameraId": ["` + cameraIdsStr + `"]
                     }
                 }
             ]
@@ -68,7 +79,8 @@
 	return total, nil
 }
 
-func QueryLastIdByDayRange(dayGte, dayLt int) (map[string]string, error) {
+func QueryLastIdByDayRange(communityId string, cameraIds []string, dayGte, dayLt int) (map[string]string, error) {
+	cameraIdsStr := strings.Replace(strings.Trim(fmt.Sprint(cameraIds), "[]"), " ", "\",\"", -1)
 	esURL := "http://" + config.Elastic.Host + ":" + config.Elastic.Port + "/" + config.Elastic.Index + "/_search"
 	queryDSL := `{
     "query": {
@@ -81,6 +93,16 @@
                             "lt": "now-` + strconv.Itoa(dayLt) + `d/d"
                         }
                     }
+                },
+                {
+                    "term": {
+                        "communityId": "` + communityId + `"
+                    }
+                },
+                {
+                    "terms": {
+                        "cameraId": ["` + cameraIdsStr + `"]
+                    }
                 }
             ]
         }

--
Gitblit v1.8.0