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"
|
)
|
|
type RealTimeController struct{}
|
|
type RealTimeArg struct {
|
TreeNodes []string `json:"treeNodes"`
|
}
|
|
// @Security ApiKeyAuth
|
// @Summary 实时抓拍
|
// @Description 实时抓拍数据
|
// @Accept json
|
// @Produce json
|
// @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) {
|
var searchBody RealTimeArg
|
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 + "\"]}},"
|
}
|
//请求头
|
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"
|
|
analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + localConf.ServerId + "\"}},"
|
|
prama := "{\"query\":{\"bool\":{\"filter\":[" +
|
cameraIdStr +
|
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\"]}"
|
tokenRes := esutil.GetEsDataReq(url, prama, true)
|
util.ResponseFormat(c, code.Success, tokenRes)
|
}
|