liuxiaolong
2020-06-05 7c811247ecf143e08c576986a884bedadc57dd66
controllers/capture.go
@@ -1,10 +1,12 @@
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"
@@ -13,54 +15,63 @@
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
   index := config.EsInfo.EsIndex.AiOcean.IndexName
   cameraIdStr := ""
   cameraId := searchBody["treeNodes"].([]interface{})
   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"
   var setApi dbapi.SysSetApi
   _, sysconf := setApi.GetServerInfo()
   analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + sysconf.ServerId + "\"}},"
   prama := "{\"query\":{\"bool\":{\"filter\":[" +
   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-5000s\",\"lt\":\"now+8h\"}}}]}}," +
      "{\"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\",\"alarmRules\",\"sex\",\"analyServerName\",\"sdkName\",\"ageDescription\",\"content\",\"id\",\"cameraAddr\",\"picMaxUrl\",\"picDate\",\"race\",\"videoUrl\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"isAlarm\",\"analyServerIp\",\"cameraId\"]}"
   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)
}