From 263c7b18ce7f18f1222318f6e0e499e907895a52 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期三, 13 十一月 2019 19:33:39 +0800 Subject: [PATCH] fix --- controllers/capture.go | 29 +++++++++++++++++++---------- 1 files changed, 19 insertions(+), 10 deletions(-) diff --git a/controllers/capture.go b/controllers/capture.go index 68dcf52..94abac1 100644 --- a/controllers/capture.go +++ b/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,34 +15,42 @@ type RealTimeController struct{} +type RealTimeArg struct { + TreeNodes []string `json:"treeNodes"` +} + +// @Security ApiKeyAuth // @Summary 瀹炴椂鎶撴媿 // @Description 瀹炴椂鎶撴媿鏁版嵁 // @Accept json // @Produce json // @Tags realTime -// @Param obj body map true "搴曞簱鏁版嵁" +// @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 cameraIdStr := "" - cameraId := searchBody["treeNodes"].([]interface{}) + cameraId := searchBody.TreeNodes if cameraId != nil && len(cameraId) > 0 { esCameraId := strings.Replace(strings.Trim(fmt.Sprint(cameraId), "[]"), " ", "\",\"", -1) cameraIdStr = "{\"terms\":{\"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 + "\"}}," + analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + localConf.ServerId + "\"}}," prama := "{\"query\":{\"bool\":{\"filter\":[" + cameraIdStr + @@ -49,7 +59,6 @@ "\"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) tokenRes := esutil.GetEsDataReq(url, prama, true) util.ResponseFormat(c, code.Success, tokenRes) } -- Gitblit v1.8.0