liuxiaolong
2020-06-05 7c811247ecf143e08c576986a884bedadc57dd66
controllers/initForData.go
@@ -31,40 +31,53 @@
   //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
   localConf, err2 := cache.GetServerInfo()
   if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
   if err2 != nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
      logger.Debug("localConfig is wrong!!!")
      util.ResponseFormat(c,code.ComError,"localConf wrong")
      util.ResponseFormat(c, code.ComError, "localConf wrong")
      return
   }
   url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) +
      "/" + index + "/_search"
   cameraIdStr := ""
   if searchBody.TreeNodes !=nil {
   linkTagInfoCameraIdStr := ""
   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 + "\"]}},"
         linkTagInfoCameraIdStr = "{\"terms\":{\"linkTagInfo.cameraId\":[\"" + esCameraId + "\"]}},"
      }
   }
   analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + localConf.ServerId + "\"}}"
   linkTagInfoAnalyServerFilterStr := "{\"term\":{\"linkTagInfo.analyServerId\":\"" + localConf.ServerId + "\"}}"
   prama := "{\"query\":{\"bool\":{\"filter\":[{\"term\":{\"isAlarm\":\"1\"}}," +
   prama := "{\"query\":{\"bool\":{\"should\":[" +
      "{\"bool\":{\"filter\":[" +
      "{\"term\":{\"isAlarm\":true}}," +
      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\"]" +
      "]}}," +
      "{\"bool\":{\"filter\":[" +
      "{\"term\":{\"isAlarm\":true}}," +
      linkTagInfoCameraIdStr +
      linkTagInfoAnalyServerFilterStr +
      "]}}" +
      "],\"minimum_should_match\":1}}," +
      "\"size\":\"20\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," +
      "\"_source\":{\"includes\":[],\"excludes\":[\"*.feature\"]}" +
      "}"
   //logger.Debug("InitForCaptureData:", prama)
   logger.Debug("InitForCaptureData:", prama)
   tokenRes := esutil.GetEsDataReq(url, prama, true)
   util.ResponseFormat(c, code.Success, tokenRes)
   tmpAllDate := esutil.ResponseData(tokenRes)
   util.ResponseFormat(c, code.Success, tmpAllDate)
}
type InitForMonitorArg struct {
   TreeNodes []string `json:"treeNodes"`
   Tasks []string `json:"tasks"`
   Tasks     []string `json:"tasks"`
}
// @Security ApiKeyAuth
@@ -81,42 +94,55 @@
   //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.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 + "\"]}},"
   }
   //判断任务ID
   taskIdStr := "{\"terms\":{\"taskId\":[]}},"
   taskIdStr := ""
   linkTagInfoTaskIdStr := ""
   taskId := searchBody.Tasks
   if taskId != nil && len(taskId) > 0 {
      esTaskId := strings.Replace(strings.Trim(fmt.Sprint(taskId), "[]"), " ", "\",\"", -1)
      taskIdStr = "{\"terms\":{\"taskId\":[\"" + esTaskId + "\"]}},"
      linkTagInfoTaskIdStr = "{\"terms\":{\"linkTagInfo.taskId\":[\"" + esTaskId + "\"]}},"
   }
   //请求头
   localConf, err2 := cache.GetServerInfo()
   if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
   if err2 != nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
      logger.Debug("localConfig is wrong!!!")
      util.ResponseFormat(c,code.ComError,"localConf wrong")
      util.ResponseFormat(c, code.ComError, "localConf wrong")
      return
   }
   url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) +
      "/" + index + "/_search"
   analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + localConf.ServerId + "\"}}"
   linkTagInfoAnalyServerFilterStr := "{\"term\":{\"linkTagInfo.analyServerId\":\"" + localConf.ServerId + "\"}}"
   prama := "{\"query\":{\"bool\":{\"filter\":[" +
      cameraIdStr +
   prama := "{\"query\":{\"bool\":{\"should\":[" +
      "{\"bool\":{\"filter\":[" +
      taskIdStr +
      cameraIdStr +
      analyServerFilterStr +
      "]}}," +
      "{\"bool\":{\"filter\":[" +
      linkTagInfoTaskIdStr +
      linkTagInfoCameraIdStr +
      linkTagInfoAnalyServerFilterStr +
      "]}}" +
      "],\"minimum_should_match\":1}}," +
      "\"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\"]}"
      "\"_source\":{\"includes\":[],\"excludes\":[\"*.feature\"]}}"
   //logger.Debug("url:", url)
   //logger.Debug("InitForMonitoringData:", prama)
   tokenRes := esutil.GetEsDataReq(url, prama, true)
   util.ResponseFormat(c, code.Success, tokenRes)
   tmpAllDate := esutil.ResponseData(tokenRes)
   util.ResponseFormat(c, code.Success, tmpAllDate)
}