From 11f5369e44c2ff32967b215d9884f9cac6f2a9cd Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期三, 25 九月 2019 18:09:46 +0800
Subject: [PATCH] add compare result search person id filter option
---
controllers/initForData.go | 74 +++++++++++++++++++++++++------------
1 files changed, 50 insertions(+), 24 deletions(-)
diff --git a/controllers/initForData.go b/controllers/initForData.go
index 7e03f79..2dcb218 100644
--- a/controllers/initForData.go
+++ b/controllers/initForData.go
@@ -1,14 +1,15 @@
package controllers
import (
- "basic.com/dbapi.git"
+ "basic.com/valib/logger.git"
"fmt"
"github.com/gin-gonic/gin"
+ "strconv"
"strings"
+ "webserver/cache"
"webserver/extend/code"
"webserver/extend/config"
"webserver/extend/esutil"
- "webserver/extend/logger"
"webserver/extend/util"
)
@@ -20,28 +21,49 @@
// @Accept json
// @Produce json
// @Tags realTime
-// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
-// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}"
+// @Param obj body controllers.RealTimeArg false "鎶撴媿瀹炴椂鍥惧垵濮嬪寲鍙傛暟"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/realTime/initForCaptureData [POST]
//瀹炴椂鎶撴媿鏁版嵁鍒濆鍖�
func (rc *RealTimeController) InitForCaptureData(c *gin.Context) {
- searchBody := make(map[string]interface{}, 0)
+ //searchBody := make(map[string]interface{}, 0)
+ var searchBody RealTimeArg
c.BindJSON(&searchBody)
index := config.EsInfo.EsIndex.VideoPersons.IndexName + "," + config.EsInfo.EsIndex.Personaction.IndexName
- url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
+ localConf, err2 := cache.GetServerInfo()
+ if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
+ logger.Debug("localConfig is wrong!!!")
+ util.ResponseFormat(c,code.ComError,"localConf wrong")
+ return
+ }
+ url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) +
"/" + index + "/_search"
- var setApi dbapi.SysSetApi
- _, sysconf := setApi.GetServerInfo()
- analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + sysconf.ServerId + "\"}}"
+ cameraIdStr := ""
+ if searchBody.TreeNodes !=nil {
+ cameraId := searchBody.TreeNodes
+ if cameraId != nil && len(cameraId) > 0 {
+ esCameraId := strings.Replace(strings.Trim(fmt.Sprint(cameraId), "[]"), " ", "\",\"", -1)
+ cameraIdStr = "{\"terms\":{\"cameraId\":[\"" + esCameraId + "\"]}},"
+ }
+ }
+
+ analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + localConf.ServerId + "\"}}"
prama := "{\"query\":{\"bool\":{\"filter\":[{\"term\":{\"isAlarm\":\"1\"}}," +
+ cameraIdStr +
analyServerFilterStr +
"]}},\"size\":\"20\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," +
"\"_source\":[\"baseInfo\",\"alarmRules\",\"sex\",\"analyServerName\",\"sdkName\",\"ageDescription\",\"content\",\"id\",\"cameraAddr\",\"picMaxUrl\",\"picDate\",\"race\",\"videoUrl\",\"picSmUrl\",\"taskName\",\"isAlarm\",\"isAlarm\",\"analyServerIp\",\"cameraId\"]" +
"}"
- logger.Debug("InitForCaptureData:", prama)
+ //logger.Debug("InitForCaptureData:", prama)
tokenRes := esutil.GetEsDataReq(url, prama, true)
util.ResponseFormat(c, code.Success, tokenRes)
+}
+
+type InitForMonitorArg struct {
+ TreeNodes []string `json:"treeNodes"`
+ Tasks []string `json:"tasks"`
}
// @Summary 瀹炴椂浠诲姟鐩戞帶鏁版嵁鍒濆鍖�
@@ -49,35 +71,39 @@
// @Accept json
// @Produce json
// @Tags realTime
-// @Param obj body map true "搴曞簱鏁版嵁"
+// @Param obj body controllers.InitForMonitorArg true "瀹炴椂浠诲姟鐩戞帶鍙傛暟"
// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}"
// @Router /data/api-v/realTime/initForMonitoringData [POST]
-//瀹炴椂鐩戞帶鏁版嵁鍒濆鍖�
func (rc *RealTimeController) InitForMonitoringData(c *gin.Context) {
- searchBody := make(map[string]interface{}, 0)
-
+ //searchBody := make(map[string]interface{}, 0)
+ var searchBody InitForMonitorArg
c.BindJSON(&searchBody)
- index := config.EsInfo.EsIndex.VideoPersons.IndexName +","+config.EsInfo.EsIndex.Personaction.IndexName
+ index := config.EsInfo.EsIndex.VideoPersons.IndexName + "," + config.EsInfo.EsIndex.Personaction.IndexName
cameraIdStr := ""
- cameraId := searchBody["treeNodes"].([]interface{})
+ cameraId := searchBody.TreeNodes
if cameraId != nil && len(cameraId) > 0 {
esCameraId := strings.Replace(strings.Trim(fmt.Sprint(cameraId), "[]"), " ", "\",\"", -1)
cameraIdStr = "{\"terms\":{\"cameraId\":[\"" + esCameraId + "\"]}},"
}
//鍒ゆ柇浠诲姟ID
taskIdStr := "{\"terms\":{\"taskId\":[]}},"
- taskId := searchBody["tasks"].([]interface{})
+ taskId := searchBody.Tasks
if taskId != nil && len(taskId) > 0 {
esTaskId := strings.Replace(strings.Trim(fmt.Sprint(taskId), "[]"), " ", "\",\"", -1)
taskIdStr = "{\"terms\":{\"taskId\":[\"" + esTaskId + "\"]}},"
}
//璇锋眰澶�
- url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
+ localConf, err2 := cache.GetServerInfo()
+ if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
+ logger.Debug("localConfig is wrong!!!")
+ util.ResponseFormat(c,code.ComError,"localConf wrong")
+ return
+ }
+ url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) +
"/" + index + "/_search"
- var setApi dbapi.SysSetApi
- _, sysconf := setApi.GetServerInfo()
- analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + sysconf.ServerId + "\"}}"
+
+ analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + localConf.ServerId + "\"}}"
prama := "{\"query\":{\"bool\":{\"filter\":[" +
cameraIdStr +
@@ -87,8 +113,8 @@
"\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," +
"\"size\":\"20\"," +
"\"_source\":[\"baseInfo\",\"alarmRules\",\"sex\",\"analyServerName\",\"sdkName\",\"ageDescription\",\"content\",\"id\",\"cameraAddr\",\"picMaxUrl\",\"picDate\",\"race\",\"videoUrl\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"isAlarm\",\"analyServerIp\",\"cameraId\"]}"
- logger.Debug("url:", url)
- logger.Debug("InitForMonitoringData:", prama)
+ //logger.Debug("url:", url)
+ //logger.Debug("InitForMonitoringData:", prama)
tokenRes := esutil.GetEsDataReq(url, prama, true)
util.ResponseFormat(c, code.Success, tokenRes)
-}
\ No newline at end of file
+}
--
Gitblit v1.8.0