| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "basic.com/valib/logger.git" |
| | | "fmt" |
| | | "strconv" |
| | | "strings" |
| | | "webserver/cache" |
| | | |
| | | "github.com/gin-gonic/gin" |
| | | "webserver/extend/code" |
| | |
| | | "webserver/extend/util" |
| | | ) |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 实时监控 |
| | | // @Description 实时监控比对数据 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags es |
| | | // @Param obj body map true "底库数据" |
| | | // @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"返回错误信息", success:false}" |
| | | // @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) |
| | | //searchBody := make(map[string]interface{}, 0) |
| | | var searchBody InitForMonitorArg |
| | | |
| | | c.BindJSON(&searchBody) |
| | | index := config.EsInfo.EsIndex.VideoPersons.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 + "\"]}}," |
| | | } |
| | | //判断任务ID |
| | | taskIdStr := "" |
| | | taskId := searchBody["tasks"].([]interface{}) |
| | | 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 + "\"]}}," |
| | | } |
| | | //请求头 |
| | | 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, "localConf wrong") |
| | | return |
| | | } |
| | | url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) + |
| | | "/" + index + "/_search" |
| | | |
| | | prama := "{\"query\":{\"bool\":{\"filter\":[" + |
| | | analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + localConf.ServerId + "\"}}," |
| | | linkTagInfoAnalyServerFilterStr := "{\"term\":{\"linkTagInfo.analyServerId\":\"" + localConf.ServerId + "\"}}," |
| | | |
| | | prama := "{\"query\":{\"bool\":{\"should\":[" + |
| | | "{\"bool\":{\"filter\":[" + |
| | | cameraIdStr + |
| | | taskIdStr + |
| | | "{\"range\":{\"picDate\":{\"gte\":\"now+8h-5s\",\"lt\":\"now+8h\"}}}]}}," + |
| | | analyServerFilterStr + |
| | | "{\"range\":{\"picDate\":{\"gte\":\"now+8h-15s\",\"lt\":\"now+8h\"}}}" + |
| | | "]}}," + |
| | | "{\"bool\":{\"filter\":[" + |
| | | linkTagInfoCameraIdStr + |
| | | linkTagInfoTaskIdStr + |
| | | 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\",\"cameraId\"]}" |
| | | fmt.Println(prama) |
| | | "\"_source\":{\"includes\":[],\"excludes\":[\"*.feature\"]}}" |
| | | logger.Debug("monitor param:", prama) |
| | | logger.Debug("monitor url:", url) |
| | | tokenRes := esutil.GetEsDataReq(url, prama, true) |
| | | /* for _, value := range tokenRes["datalist"].([]interface{}) { |
| | | if value.(map[string]interface{})["personId"] != nil { |
| | |
| | | } |
| | | } |
| | | }*/ |
| | | util.ResponseFormat(c, code.Success, tokenRes) |
| | | tmpAllDate := esutil.ResponseData(tokenRes) |
| | | util.ResponseFormat(c, code.Success, tmpAllDate) |
| | | } |