From 0625c22f72e5fb2c5f60a59fae22ddd1982acb8d Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期一, 08 六月 2020 14:45:28 +0800
Subject: [PATCH] fix fmt
---
controllers/capture.go | 75 +++++++++++++++++++++++--------------
1 files changed, 46 insertions(+), 29 deletions(-)
diff --git a/controllers/capture.go b/controllers/capture.go
index e15f750..fd70180 100644
--- a/controllers/capture.go
+++ b/controllers/capture.go
@@ -1,60 +1,77 @@
package controllers
import (
+ "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/util"
- "strings"
)
type RealTimeController struct{}
+type RealTimeArg struct {
+ TreeNodes []string `json:"treeNodes"`
+}
+
+// @Security ApiKeyAuth
// @Summary 瀹炴椂鎶撴媿
// @Description 瀹炴椂鎶撴媿鏁版嵁
// @Accept json
// @Produce json
-// @Tags es
-// @Param obj body map true "搴曞簱鏁版嵁"
+// @Tags realTime
+// @Param obj body controllers.RealTimeArg true "搴曞簱鏁版嵁"
// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}"
// @Router /data/api-v/realTime/capture [POST]
//瀹炴椂鎶撴媿
func (rc *RealTimeController) PostCapture(c *gin.Context) {
- searchBody := make(map[string]interface{}, 0)
-
+ var searchBody RealTimeArg
c.BindJSON(&searchBody)
- index := config.EsInfo.EsIndex.VideoPersons.IndexName + "," + config.EsInfo.EsIndex.Personaction.IndexName
- videoReqNumStr := ""
- videoReqNum := searchBody["treeNodes"].([]interface{})
- if videoReqNum != nil && len(videoReqNum) > 0 {
- esVideoReqNum := strings.Replace(strings.Trim(fmt.Sprint(videoReqNum), "[]"), " ", "\",\"", -1)
- videoReqNumStr = "{\"terms\":{\"videoReqNum\":[\"" + esVideoReqNum + "\"]}},"
+ index := config.EsInfo.EsIndex.AiOcean.IndexName
+ cameraIdStr := ""
+ linkTagInfoCameraIdStr := ""
+ cameraId := searchBody.TreeNodes
+ if cameraId != nil && len(cameraId) > 0 {
+ esCameraId := strings.Replace(strings.Trim(fmt.Sprint(cameraId), "[]"), " ", "\",\"", -1)
+ cameraIdStr = "{\"terms\":{\"cameraId\":[\"" + esCameraId + "\"]}},"
+ linkTagInfoCameraIdStr = "{\"terms\":{\"linkTagInfo.cameraId\":[\"" + esCameraId + "\"]}},"
}
//璇锋眰澶�
- 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, "es config err")
+ return
+ }
+ url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) +
"/" + index + "/_search"
- prama := "{\"query\":{\"bool\":{\"filter\":[" +
- videoReqNumStr +
- "{\"range\":{\"picDate\":{\"gte\":\"now+8h-5s\",\"lt\":\"now+8h\"}}}]}}," +
+ analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + localConf.ServerId + "\"}},"
+ linkTagInfoAnalyServerFilterStr := "{\"term\":{\"linkTagInfo.analyServerId\":\"" + localConf.ServerId + "\"}},"
+ prama := "{\"query\":{\"bool\":{\"should\":[" +
+ "{\"bool\":{\"filter\":[" +
+ "{\"term\":{\"isAlarm\":true}}," +
+ cameraIdStr +
+ analyServerFilterStr +
+ "{\"range\":{\"picDate\":{\"gte\":\"now+8h-15s\",\"lt\":\"now+8h\"}}}" +
+ "]}}," +
+ "{\"bool\":{\"filter\":[" +
+ "{\"term\":{\"isAlarm\":true}}," +
+ linkTagInfoCameraIdStr +
+ linkTagInfoAnalyServerFilterStr +
+ "{\"range\":{\"linkTagInfo.picDate\":{\"gte\":\"now+8h-15s\",\"lt\":\"now+8h\"}}}" +
+ "]}}" +
+ "],\"minimum_should_match\":1}}," +
"\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," +
"\"size\":\"1000\"," +
- "\"_source\":[\"baseInfo\",\"gender\",\"indeviceName\",\"sdkType\",\"ageDescription\",\"content\",\"ID\",\"picAddress\",\"picMaxUrl\",\"picDate\",\"race\",\"videoNum\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"IDCard\",\"videoIp\",\"videoReqNum\"]}"
- fmt.Println(prama)
+ "\"_source\":{\"includes\":[],\"excludes\":[\"*.feature\"]}}"
tokenRes := esutil.GetEsDataReq(url, prama, true)
- /*for _, value := range tokenRes["datalist"].([]interface{}) {
- if value.(map[string]interface{})["personId"] != nil {
- info := getDBPersonInfo(value.(map[string]interface{})["personId"].(string))
- for key, val := range info {
- //fmt.Println(value.(map[string]interface{})[key],val)
- value.(map[string]interface{})[key] = val
-
- }
- }
- }*/
-
- util.ResponseFormat(c, code.Success, tokenRes)
+ tmpAllDate := esutil.ResponseData(tokenRes)
+ util.ResponseFormat(c, code.Success, tmpAllDate)
}
--
Gitblit v1.8.0