package controllers
|
|
import (
|
"basic.com/dbapi.git"
|
"basic.com/valib/logger.git"
|
"fmt"
|
"strconv"
|
"strings"
|
"webserver/cache"
|
|
"github.com/gin-gonic/gin"
|
"webserver/extend/code"
|
"webserver/extend/config"
|
"webserver/extend/esutil"
|
"webserver/extend/util"
|
)
|
|
// @Summary 实时监控
|
// @Description 实时监控比对数据
|
// @Accept json
|
// @Produce json
|
// @Tags realTime
|
// @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/monitoring [POST]
|
func (rc *RealTimeController) PostMonitoring(c *gin.Context) {
|
//searchBody := make(map[string]interface{}, 0)
|
var searchBody InitForMonitorArg
|
|
c.BindJSON(&searchBody)
|
index := config.EsInfo.EsIndex.VideoPersons.IndexName + "," + config.EsInfo.EsIndex.Personaction.IndexName
|
cameraIdStr := ""
|
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
|
if taskId != nil && len(taskId) > 0 {
|
esTaskId := strings.Replace(strings.Trim(fmt.Sprint(taskId), "[]"), " ", "\",\"", -1)
|
taskIdStr = "{\"terms\":{\"taskId\":[\"" + esTaskId + "\"]}},"
|
}
|
//请求头
|
localConf, err2 := cache.GetServerInfo()
|
if err2 !=nil || localConf.AlarmIp == "" {
|
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 + "\"}},"
|
|
prama := "{\"query\":{\"bool\":{\"filter\":[" +
|
cameraIdStr +
|
taskIdStr +
|
analyServerFilterStr +
|
"{\"range\":{\"picDate\":{\"gte\":\"now+8h-15s\",\"lt\":\"now+8h\"}}}]}}," +
|
"\"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)
|
fmt.Println(url)
|
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 {
|
value.(map[string]interface{})[key] = val
|
}
|
}
|
}*/
|
util.ResponseFormat(c, code.Success, tokenRes)
|
}
|