From 5e664037b47b68b1ba28e07cefcfcec2795fbeed Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期一, 22 七月 2019 14:20:22 +0800 Subject: [PATCH] add initForCaptureData controller add initForMonitoringData controller fix capture fix monitoring --- /dev/null | 37 ------------ controllers/capture.go | 15 ---- controllers/monitoring.go | 8 +- controllers/initForData.go | 91 ++++++++++++++++++++++++++++++ router/router.go | 3 5 files changed, 99 insertions(+), 55 deletions(-) diff --git a/controllers/androidAction.go b/controllers/androidAction.go deleted file mode 100644 index 5f4618f..0000000 --- a/controllers/androidAction.go +++ /dev/null @@ -1,37 +0,0 @@ -package controllers - -import ( - "fmt" - "github.com/gin-gonic/gin" - "webserver/extend/code" - "webserver/extend/config" - "webserver/extend/esutil" - "webserver/extend/util" -) - -type AndroidAction struct { -} - -// @Summary Android瀹炴椂鑾峰彇鏁版嵁 -// @Description 瀹炴椂鑾峰彇鏁版嵁 -// @Accept json -// @Produce json -// @Tags es -// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" -// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" -// @Router /data/api-v/realTime/action [POST] -//瀹炴椂鎶撴媿 -func (rc *RealTimeController) PostAction(c *gin.Context) { - searchBody := make(map[string]interface{}, 0) - c.BindJSON(&searchBody) - sec := searchBody["sec"].(string) - index := config.EsInfo.EsIndex.VideoPersons.IndexName + "," + config.EsInfo.EsIndex.Personaction.IndexName - url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + - "/" + index + "/_search" - prama := "{\"query\":{\"bool\":{\"filter\":[{\"term\":{\"isAlarm\":\"1\"}},{\"range\":{\"picDate\":{\"gte\":\"now+8h-" + sec + "s\",\"lt\":\"now+8h\"}}}]}},\"size\":\"1000\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," + - "\"_source\":[\"baseInfo\",\"alarmRules\",\"sex\",\"analyServerName\",\"sdkName\",\"ageDescription\",\"content\",\"id\",\"cameraAddr\",\"picMaxUrl\",\"picDate\",\"race\",\"videoUrl\",\"picSmUrl\",\"taskName\",\"isAlarm\",\"isAlarm\",\"analyServerIp\",\"cameraId\"]" + - "}" - fmt.Println(prama) - tokenRes := esutil.GetEsDataReq(url, prama, true) - util.ResponseFormat(c, code.Success, tokenRes) -} diff --git a/controllers/capture.go b/controllers/capture.go index d74d6ae..68dcf52 100644 --- a/controllers/capture.go +++ b/controllers/capture.go @@ -17,7 +17,7 @@ // @Description 瀹炴椂鎶撴媿鏁版嵁 // @Accept json // @Produce json -// @Tags es +// @Tags realTime // @Param obj body map true "搴曞簱鏁版嵁" // @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" // @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" @@ -45,22 +45,11 @@ prama := "{\"query\":{\"bool\":{\"filter\":[" + cameraIdStr + analyServerFilterStr + - "{\"range\":{\"picDate\":{\"gte\":\"now+8h-5000s\",\"lt\":\"now+8h\"}}}]}}," + + "{\"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) 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 { - //fmt.Println(value.(map[string]interface{})[key],val) - value.(map[string]interface{})[key] = val - - } - } - }*/ - util.ResponseFormat(c, code.Success, tokenRes) } diff --git a/controllers/initForData.go b/controllers/initForData.go new file mode 100644 index 0000000..cce730b --- /dev/null +++ b/controllers/initForData.go @@ -0,0 +1,91 @@ +package controllers + +import ( + "fmt" + "github.com/gin-gonic/gin" + "strings" + "webserver/extend/code" + "webserver/extend/config" + "webserver/extend/esutil" + "webserver/extend/util" +) + +type InitForData struct { +} + +// @Summary 鎶撴媿瀹炴椂鍥炬暟鎹垵濮嬪寲 +// @Description 瀹炴椂鑾峰彇鏁版嵁 +// @Accept json +// @Produce json +// @Tags realTime +// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" +// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" +// @Router /data/api-v/realTime/action [POST] +//瀹炴椂鎶撴媿鏁版嵁鍒濆鍖� +func (rc *RealTimeController) InitForCaptureData(c *gin.Context) { + searchBody := make(map[string]interface{}, 0) + c.BindJSON(&searchBody) + index := config.EsInfo.EsIndex.VideoPersons.IndexName + "," + config.EsInfo.EsIndex.Personaction.IndexName + url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + + "/" + index + "/_search" + var setApi dbapi.SysSetApi + _, sysconf := setApi.GetServerInfo() + analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + sysconf.ServerId + "\"}}" + + prama := "{\"query\":{\"bool\":{\"filter\":[{\"term\":{\"isAlarm\":\"1\"}}," + + 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\"]" + + "}" + fmt.Println(prama) + tokenRes := esutil.GetEsDataReq(url, prama, true) + util.ResponseFormat(c, code.Success, tokenRes) +} + +// @Summary 瀹炴椂浠诲姟鐩戞帶鏁版嵁鍒濆鍖� +// @Description 瀹炴椂鐩戞帶姣斿鏁版嵁 +// @Accept json +// @Produce json +// @Tags realTime +// @Param obj body map 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) InitForMonitoringData(c *gin.Context) { + searchBody := make(map[string]interface{}, 0) + + c.BindJSON(&searchBody) + index := config.EsInfo.EsIndex.VideoPersons.IndexName + cameraIdStr := "" + cameraId := searchBody["treeNodes"].([]interface{}) + 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"].([]interface{}) + if taskId != nil && len(taskId) > 0 { + esTaskId := strings.Replace(strings.Trim(fmt.Sprint(taskId), "[]"), " ", "\",\"", -1) + taskIdStr = "{\"terms\":{\"taskId\":[\"" + esTaskId + "\"]}}," + } + //璇锋眰澶� + url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + + "/" + index + "/_search" + var setApi dbapi.SysSetApi + _, sysconf := setApi.GetServerInfo() + analyServerFilterStr := "{\"term\":{\"analyServerId\":\"" + sysconf.ServerId + "\"}}," + + prama := "{\"query\":{\"bool\":{\"filter\":[" + + cameraIdStr + + taskIdStr + + analyServerFilterStr + + "]}}," + + "\"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\"]}" + fmt.Println(prama) + tokenRes := esutil.GetEsDataReq(url, prama, true) + util.ResponseFormat(c, code.Success, tokenRes) +} \ No newline at end of file diff --git a/controllers/monitoring.go b/controllers/monitoring.go index 4bae956..af8d7a7 100644 --- a/controllers/monitoring.go +++ b/controllers/monitoring.go @@ -16,7 +16,7 @@ // @Description 瀹炴椂鐩戞帶姣斿鏁版嵁 // @Accept json // @Produce json -// @Tags es +// @Tags realTime // @Param obj body map true "搴曞簱鏁版嵁" // @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" // @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" @@ -34,7 +34,7 @@ cameraIdStr = "{\"terms\":{\"cameraId\":[\"" + esCameraId + "\"]}}," } //鍒ゆ柇浠诲姟ID - taskIdStr := "" + taskIdStr := "{\"terms\":{\"taskId\":[]}}," taskId := searchBody["tasks"].([]interface{}) if taskId != nil && len(taskId) > 0 { esTaskId := strings.Replace(strings.Trim(fmt.Sprint(taskId), "[]"), " ", "\",\"", -1) @@ -52,10 +52,10 @@ cameraIdStr + taskIdStr + analyServerFilterStr + - "{\"range\":{\"picDate\":{\"gte\":\"now+8h-5000s\",\"lt\":\"now+8h\"}}}]}}," + + "{\"range\":{\"picDate\":{\"gte\":\"now+8h-15s\",\"lt\":\"now+8h\"}}}]}}," + "\"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\"]}" + "\"_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) /* for _, value := range tokenRes["datalist"].([]interface{}) { diff --git a/router/router.go b/router/router.go index eaf01c5..f42cbc6 100644 --- a/router/router.go +++ b/router/router.go @@ -137,7 +137,8 @@ { realTime.POST("/capture", realTimeController.PostCapture) realTime.POST("/monitoring", realTimeController.PostMonitoring) - realTime.POST("/action", realTimeController.PostAction) + realTime.POST("/initForCaptureData", realTimeController.InitForCaptureData) + realTime.POST("/initForMonitoringData", realTimeController.InitForMonitoringData) } //搴曞簱 鎿嶄綔 vdbtable := r.Group(urlPrefix + "/dbtable") -- Gitblit v1.8.0