From c738ec5996011f51549d18dd2ff2417e509f1399 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期四, 20 八月 2020 22:25:52 +0800
Subject: [PATCH] add get person data

---
 EsApi.go |   75 ++++++++++++++++++++++++++++++++++---
 1 files changed, 69 insertions(+), 6 deletions(-)

diff --git a/EsApi.go b/EsApi.go
index eabf7cf..caea6e1 100644
--- a/EsApi.go
+++ b/EsApi.go
@@ -159,8 +159,71 @@
 
 }
 
+//鏍规嵁鎽勫儚鏈哄垪琛ㄥ拰鏃堕棿鏌ヨ浜哄憳娴忚杞ㄨ抗
+func GetPersonDataByCameraIdAndTime(cameraId []string, startTime string, endTime string, serverIp string, ServerPort string, indexName string) ([]map[string]interface{}, error) {
+	esCameraId := strings.Replace(strings.Trim(fmt.Sprint(cameraId), "[]"), " ", "\",\"", -1)
+	personUrl := "http://" + serverIp + ":" + ServerPort + "/" + indexName + "/_search"
+	personBody := `{
+    "query": {
+        "bool": {
+            "filter": [
+                {
+                    "range": {
+                        "picDate": {
+                            "gte": "` + startTime + `",
+                            "lte": "` + endTime + `"
+                        }
+                    }
+                },
+                {
+                    "term": {
+                        "targetInfo.targetType.raw": "Yolo"
+                    }
+                },
+                {
+                    "terms": {
+                        "cameraId": [
+                           "` + esCameraId + `"
+                        ]
+                    }
+                }
+            ]
+        }
+    },
+    "size": 10,
+    "_source": {
+        "includes": [
+            "cameraId",
+            "cameraName",
+            "cameraAddr",
+            "targetInfo.targetScore",
+            "picDate",
+            "updateTime",
+            "picMaxUrl",
+            "targetInfo.belongsTargetId",
+            "targetInfo.targetLocation"
+        ]
+    }
+}`
+	//fmt.Println(personUrl)
+	//fmt.Println(personBody)
+	buf, err := EsReq("POST", personUrl, []byte(personBody))
+	if err != nil {
+		return nil, err
+	}
+
+	sources, err := Sourcelist(buf)
+	if err != nil {
+		return nil, err
+	}
+	resData,err := PerSonAnalysis(sources)
+	//println(sources)
+	return resData, nil
+
+}
+
 //鏍规嵁鏃堕棿鑼冨洿锛屾憚鍍忔満鍒楄〃锛屽垎缁勮仛鍚堜汉鑴稿垪琛�
-func GetfaceDataBucketsBycameraIdAndTime(cameraId []string, startTime string, endTime string, thresholdTime float64, serverIp string, ServerPort string, indexName string) (buckersDate map[string]interface{}, err error) {
+func GetFaceDataBucketsByCameraIdAndTime(cameraId []string, startTime string, endTime string, thresholdTime float64, serverIp string, ServerPort string, indexName string) (buckersDate map[string]interface{}, err error) {
 	esCameraId := strings.Replace(strings.Trim(fmt.Sprint(cameraId), "[]"), " ", "\",\"", -1)
 	var buckersUrl = "http://" + serverIp + ":" + ServerPort + "/" + indexName + "/_search"
 	var buckersBody = `{
@@ -242,9 +305,9 @@
 	return sources, nil
 }
 
-//鏍规嵁鎶撴媿浜哄憳id鏇存柊锛坧icurl锛夊浘鐗囧湴鍧�---棰勫紑鍙�
+//鏍规嵁鎶撴媿浜哄憳id鏇存柊锛坧icurl锛夊浘鐗囧湴鍧�
 func UpdatePicUrlById(id string, picUrl string, indexName string, serverIp string, serverPort string) (err error) {
-
+    updateTime := time.Now().Format("2006-01-02 15:04:05")
 	tRes, err := AIOceaninfosbyid([]string{id}, indexName, serverIp, serverPort)
 	if err != nil || len(tRes) == 0 {
 		return err
@@ -252,10 +315,10 @@
 	picMaxUrls := tRes[0].PicMaxUrl
 	sourceStr := `    	
         "lang":"painless",
-        "inline": "ctx._source.picMaxUrl.add(` + picUrl + `)"
+        "inline": "ctx._source.picMaxUrl.add('` + picUrl + `');ctx._source.updateTime='`+updateTime+`'"
 `
 	if len(picMaxUrls) >= 2 {
-		sourceStr = `"source": "ctx._source.picMaxUrl[1]='` + picUrl + `'"`
+		sourceStr = `"source": "ctx._source.picMaxUrl[1]='` + picUrl + `';ctx._source.updateTime='`+updateTime+`'"`
 	}
 	var info interface{}
 	url := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_update_by_query?refresh=true"
@@ -279,7 +342,7 @@
         }
         `
 	//logPrint("url: ", url, videoUrlInfo)
-	//fmt.Println(url, picUrlInfo)
+	fmt.Println(url, picUrlInfo)
 	buf, err := EsReq("POST", url, []byte(picUrlInfo))
 	if err != nil {
 		logPrint("http request videoUrlInfo info is err!")

--
Gitblit v1.8.0