From f3863b12653fc47996073710b56e792de0be4c8d Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期二, 25 六月 2019 17:57:05 +0800 Subject: [PATCH] 根据新索引结构修改算法和接口 --- controllers/dbtablesCon.go | 26 ++--- extend/esutil/EsClient.go | 9 - controllers/capture.go | 16 +- controllers/monitoring.go | 14 +- controllers/es.go | 104 +++++++++++--------- controllers/esSearch.go | 28 ++-- service/CameraVideoService.go | 12 +- controllers/dbtableperson.go | 59 ++++++----- controllers/androidAction.go | 5 9 files changed, 144 insertions(+), 129 deletions(-) diff --git a/controllers/androidAction.go b/controllers/androidAction.go index d5b5dda..5f4618f 100644 --- a/controllers/androidAction.go +++ b/controllers/androidAction.go @@ -2,7 +2,6 @@ import ( "fmt" - "github.com/gin-gonic/gin" "webserver/extend/code" "webserver/extend/config" @@ -29,8 +28,8 @@ 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\":{\"personIsHub\":\"1\"}},{\"range\":{\"picDate\":{\"gte\":\"now+8h-" + sec + "s\",\"lt\":\"now+8h\"}}}]}},\"size\":\"1000\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," + - "\"_source\":[\"baseInfo\",\"gender\",\"indeviceName\",\"sdkType\",\"ageDescription\",\"content\",\"ID\",\"picAddress\",\"picMaxUrl\",\"picDate\",\"race\",\"videoNum\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"IDCard\",\"videoIp\",\"videoReqNum\"]" + + 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) diff --git a/controllers/capture.go b/controllers/capture.go index e15f750..9c784bb 100644 --- a/controllers/capture.go +++ b/controllers/capture.go @@ -3,11 +3,11 @@ import ( "fmt" "github.com/gin-gonic/gin" + "strings" "webserver/extend/code" "webserver/extend/config" "webserver/extend/esutil" "webserver/extend/util" - "strings" ) type RealTimeController struct{} @@ -27,22 +27,22 @@ c.BindJSON(&searchBody) index := config.EsInfo.EsIndex.VideoPersons.IndexName + "," + config.EsInfo.EsIndex.Personaction.IndexName - videoReqNumStr := "" - videoReqNum := searchBody["treeNodes"].([]interface{}) - if videoReqNum != nil && len(videoReqNum) > 0 { - esVideoReqNum := strings.Replace(strings.Trim(fmt.Sprint(videoReqNum), "[]"), " ", "\",\"", -1) - videoReqNumStr = "{\"terms\":{\"videoReqNum\":[\"" + esVideoReqNum + "\"]}}," + cameraIdStr := "" + cameraId := searchBody["treeNodes"].([]interface{}) + 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 + "/" + index + "/_search" prama := "{\"query\":{\"bool\":{\"filter\":[" + - videoReqNumStr + + cameraIdStr + "{\"range\":{\"picDate\":{\"gte\":\"now+8h-5s\",\"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\",\"videoReqNum\"]}" + "\"_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/controllers/dbtableperson.go b/controllers/dbtableperson.go index c41586f..86caa20 100644 --- a/controllers/dbtableperson.go +++ b/controllers/dbtableperson.go @@ -8,12 +8,12 @@ "time" "github.com/gin-gonic/gin" + "github.com/satori/go.uuid" "webserver/extend/code" "webserver/extend/config" "webserver/extend/esutil" "webserver/extend/util" "webserver/models" - "github.com/satori/go.uuid" ) type DbPersonController struct { @@ -52,14 +52,14 @@ dbperson.Uuid = personId dbperson.PriInsert() url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + - "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + personId+"?refresh=wait_for" + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + personId + "?refresh=wait_for" personbytes, e := json.Marshal(dbperson) if e != nil { fmt.Print("Json marshaling failed锛�%s\n", e) } params := string(personbytes) fmt.Print("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) - data ,_ := esutil.PutEsDataReq(url, params) + data, _ := esutil.PutEsDataReq(url, params) //c.JSON(200, changeEsRespData(data, "娣诲姞浜哄憳鎴愬姛")) result = changeEsRespData(data, "娣诲姞鎴愬姛") return result @@ -113,13 +113,16 @@ // @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" // @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" // @Router /data/api-v/dbperson/deleteDbPersonById/{uuid} [POST] + func (dbc DbPersonController) DeleteDbPerson(c *gin.Context) { uuid := c.Params.ByName("uuid") url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + uuid + "/_update?refresh=wait_for" - params := "{\"doc\":{\"del_flag\":\"1\",\"update_time\":\"" + time.Now().Format("2006-01-02 15:04:05") + "\"}}" + params := "{\"doc\":{\"isDelete\":\"1\",\"updateTime\":\"" + time.Now().Format("2006-01-02 15:04:05") + "\"}}" fmt.Print("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) + data := esutil.GetEsDataReq(url, params, false) + //c.JSON(200, changeEsRespData(data,"鍒犻櫎鎴愬姛")) result := changeEsRespData(data, "鍒犻櫎鎴愬姛") if result["success"].(bool) { @@ -130,6 +133,7 @@ util.ResponseFormat(c, code.ServiceInsideError, result["data"]) } } + // @Summary 鍒犻櫎搴曞簱浜哄憳 // @Description 鍒犻櫎搴撲汉鍛� // @Accept json @@ -139,25 +143,25 @@ // @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" // @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" // @Router /data/api-v/dbperson/deleteMoreDbPerson [POST] -func (dbc DbPersonController) DeleteMoreDbPerson(c *gin.Context) { - uuids := make([]string,0,5) +func (dbc DbPersonController) DeleteMoreDbPerson(c *gin.Context) { + uuids := make([]string, 0, 5) c.BindJSON(&uuids) bytes, _ := json.Marshal(uuids) s := string(bytes) url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + - "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_update_by_query?refresh=wait_for" // + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + "/" + s - params := "{\"script\":{\"lang\":\"painless\",\"inline\":\"ctx._source.del_flag = \\\"1\\\";" + - "ctx._source.update_time = \\\"" + time.Now().Format("2006-01-02 15:04:05") + "\\\"\"},\"query\":{\"terms\":{\"_id\":"+s+"}}}" + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_update_by_query?refresh=wait_for" // + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + "/" + s + params := "{\"script\":{\"lang\":\"painless\",\"inline\":\"ctx._source.isDelete = \\\"1\\\";" + + "ctx._source.updateTime = \\\"" + time.Now().Format("2006-01-02 15:04:05") + "\\\"\"},\"query\":{\"terms\":{\"_id\":" + s + "}}}" fmt.Print("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data := esutil.GetEsDataReq(url, params, false) //c.JSON(200, changeEsRespData(data,"鍒犻櫎鎴愬姛")) //result := changeEsRespData(data, "鍒犻櫎鎴愬姛") if data["error"] == nil { //code.Success.Message = "鍒犻櫎搴曞簱浜哄憳鎴愬姛" - util.ResponseFormat(c, code.Success,"鍒犻櫎搴曞簱浜哄憳鎴愬姛" ) + util.ResponseFormat(c, code.Success, "鍒犻櫎搴曞簱浜哄憳鎴愬姛") } else { //code.ServiceInsideError.Message += result["msg"].(string) - util.ResponseFormat(c, code.ServiceInsideError,data["error"]) + util.ResponseFormat(c, code.ServiceInsideError, data["error"]) } } @@ -209,7 +213,7 @@ } if contentValue != "" { contentParam = ",\"must\":[{\"multi_match\":{\"query\":\"" + contentValue + "\",\"type\":\"best_fields\"," + - "\"fields\":[\"personName\",\"sex\",\"idcard\",\"phoneNum\"],\"tie_breaker\":0.3}}]" + "\"fields\":[\"personName\",\"sex\",\"idCard\",\"phoneNum\"],\"tie_breaker\":0.3}}]" } if orderType == "desc" { @@ -219,13 +223,12 @@ } params := "{\"query\":{\"bool\":{\"filter\":[" + - "{\"term\":{\"del_flag\":\"0\"}}" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}" + "{\"term\":{\"isDelete\":\"0\"}}" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}" fmt.Print("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data := esutil.GetEsDataReq(url, params, true) //c.JSON(200, data) util.ResponseFormat(c, code.Success, data) } - // @Summary 鏌ヨ搴曞簱浜哄憳鍒楄〃 // @Description 鏌ヨ搴撲汉鍛樺垪琛� @@ -238,7 +241,7 @@ // @Router /data/api-v/dbperson/queryDbPersonsByCampare [POST] func (dbc DbPersonController) QueryDbPersonsByCampare(c *gin.Context) { url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + - "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_search" // ?refresh=wait_for + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_search" // ?refresh=wait_for reqBody := make(map[string]interface{}, 5) c.BindJSON(&reqBody) tableId := "" @@ -253,12 +256,13 @@ if reqBody["orderType"] != nil { orderType = reqBody["orderType"].(string) } // 鍒楃被鍨� - faceUrl := ""; var threshold float32 - if reqBody["faceUrl"] != nil && reqBody["threshold"] != nil{ + faceUrl := "" + var threshold float32 + if reqBody["faceUrl"] != nil && reqBody["threshold"] != nil { faceUrl = reqBody["faceUrl"].(string) threshold = float32(reqBody["threshold"].(float64)) - }else { - util.ResponseFormat(c, code.RequestParamError, nil); // 鍥剧墖璺緞鏈夐棶棰� + } else { + util.ResponseFormat(c, code.RequestParamError, nil) // 鍥剧墖璺緞鏈夐棶棰� return } //杈撳叆妗嗗唴瀹� @@ -285,10 +289,10 @@ } params := "{\"query\":{\"bool\":{\"filter\":[" + - "{\"term\":{\"del_flag\":\"0\"}}" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}" + "{\"term\":{\"isDelete\":\"0\"}}" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}" fmt.Print("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data := esutil.GetEsDataReq(url, params, true) - featByte := make([]byte,0,1024) + featByte := make([]byte, 0, 1024) if len(faceUrl) > 3 { // linux /*fileName := picUrl // picIp 瀹氫箟鍦� fileController weedfs 鏂囦欢鏈嶅姟鍣� 璁块棶 璺緞 鍓嶇紑 detect := gorun.GetSimpleFaceDetect(fileName) @@ -299,14 +303,17 @@ featByte = detect[0]["feature"].([]byte) }*/ // linux } - to := page*size - datalist := sourceCompare(data["datalist"].([]interface{}),false,featByte,threshold ) + to := page * size + datalist := sourceCompare(data["datalist"].([]interface{}), false, featByte, threshold) total := len(datalist) - if from > total { from = total } - if to > total { to = total } + if from > total { + from = total + } + if to > total { + to = total + } data["datalist"] = datalist[from:to] data["total"] = len(datalist) //c.JSON(200, data) util.ResponseFormat(c, code.Success, data) } - diff --git a/controllers/dbtablesCon.go b/controllers/dbtablesCon.go index 973a343..f6bf747 100644 --- a/controllers/dbtablesCon.go +++ b/controllers/dbtablesCon.go @@ -4,13 +4,13 @@ "encoding/json" "fmt" "github.com/gin-gonic/gin" + "github.com/satori/go.uuid" + "log" "webserver/extend/code" "webserver/extend/config" "webserver/extend/esutil" "webserver/extend/util" "webserver/models" - "github.com/satori/go.uuid" - "log" ) type DbTableController struct { @@ -31,13 +31,13 @@ isSync := c.Params.ByName("isSync") syncTerm := "" if isSync == "1" { - syncTerm = ",{\"term\":{\"syncType\":\"1\"}}" // 鍚屾搴� + syncTerm = ",{\"term\":{\"isSync\":\"1\"}}" // 鍚屾搴� } else if isSync == "2" { - syncTerm = ",{\"term\":{\"syncType\":\"2\"}}" // / 鏈湴搴� + syncTerm = ",{\"term\":{\"isSync\":\"2\"}}" // / 鏈湴搴� } params := "{\"query\":{\"bool\":{\"must\":[" + - "{\"term\":{\"del_flag\":\"0\"}}" + syncTerm + "]}}," + - "\"from\":0,\"size\":100,\"sort\":{\"uuid\":{\"order\":\"asc\"}}}" + "{\"term\":{\"isDelete\":\"0\"}}" + syncTerm + "]}}," + + "\"from\":0,\"size\":100,\"sort\":{\"id\":{\"order\":\"asc\"}}}" fmt.Print("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data := esutil.GetEsDataReq(url, params, true) @@ -46,17 +46,13 @@ } // 渚濇嵁搴曞簱id 鏌ヨ鏁版嵁 -func QueryDbTableInfo(tableId string) map[string]interface{} { +func QueryDbTableInfo(tableId string) map[string]interface{} { url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + - "/" + config.EsInfo.EsIndex.DbTables.IndexName +"/" + config.EsInfo.EsIndex.DbTables.IndexName + "/"+tableId + "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + tableId fmt.Print("璇锋眰url:%s;", url) data := esutil.GetEsDataInfo(url, true) return data - } - - - - +} // @Summary 淇敼搴曞簱 // @Description 淇敼鍚屾鎴栨湰鍦板簱 @@ -121,7 +117,7 @@ //fmt.Printf("%s\n", dbTableByte) params := string(dbTableByte) fmt.Print("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) - data,_ := esutil.PutEsDataReq(url, params) + data, _ := esutil.PutEsDataReq(url, params) //c.JSON(200, changeEsRespData(data, "娣诲姞鎴愬姛")) result := changeEsRespData(data, "娣诲姞鎴愬姛") if result["success"].(bool) { @@ -146,7 +142,7 @@ uuid := c.Params.ByName("uuid") url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexType + "/" + uuid + "/_update" - params := "{\"doc\":{\"del_flag\":\"1\"}}" + params := "{\"doc\":{\"isDelete\":\"1\"}}" fmt.Print("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data := esutil.GetEsDataReq(url, params, false) //c.JSON(200, changeEsRespData(data, "鍒犻櫎鎴愬姛")) diff --git a/controllers/es.go b/controllers/es.go index 18fe7cd..f3dd501 100644 --- a/controllers/es.go +++ b/controllers/es.go @@ -4,15 +4,15 @@ "encoding/json" "fmt" "github.com/gin-gonic/gin" + "math/rand" + "strconv" + "strings" "webserver/extend/code" "webserver/extend/config" "webserver/extend/esutil" "webserver/extend/util" "webserver/models" "webserver/service" - "math/rand" - "strconv" - "strings" ) type EsController struct{} @@ -31,15 +31,24 @@ c.BindJSON(&searchBody) isEsSource := true databases := searchBody.DataBases - page := searchBody.Page;if page <= 0 {page = 1} - size := searchBody.Size;if size <= 0 {size = 8} + page := searchBody.Page + if page <= 0 { + page = 1 + } + size := searchBody.Size + if size <= 0 { + size = 8 + } from := (page - 1) * size to := page * size - threshold := searchBody.Threshold;if threshold < 0 || threshold > 100 {threshold = 60} + threshold := searchBody.Threshold + if threshold < 0 || threshold > 100 { + threshold = 60 + } picUrl := searchBody.PicUrl /*feature := searchBody.Feature*/ - var featByte []byte; - if len(picUrl) > 3 { // linux + var featByte []byte + if len(picUrl) > 3 { // linux /*fileName := picUrl // picIp 瀹氫箟鍦� fileController weedfs 鏂囦欢鏈嶅姟鍣� 璁块棶 璺緞 鍓嶇紑 detect := gorun.GetSimpleFaceDetect(fileName) if len(detect) != 1 { @@ -76,25 +85,30 @@ if to > dataLen { to = dataLen } - sources = sources[from:to] // 鏁版嵁 閮ㄥ垎鑾峰彇 - if !isEsSource { // 浜哄憳鏁版嵁瑕佸姞搴曞簱鍚嶇О + sources = sources[from:to] // 鏁版嵁 閮ㄥ垎鑾峰彇 + if !isEsSource { // 浜哄憳鏁版嵁瑕佸姞搴曞簱鍚嶇О for _, sou := range sources { tableId := sou.(map[string]interface{})["tableId"] if tableId != nil { info := QueryDbTableInfo(tableId.(string)) - if info["tableName"] != nil {sou.(map[string]interface{})["tableName"] = info["tableName"] - }else {sou.(map[string]interface{})["tableName"] = "鍏朵粬"} - if info["bwType"] != nil {sou.(map[string]interface{})["bwType"] = info["bwType"] - }else {sou.(map[string]interface{})["bwType"] = "4"} + if info["tableName"] != nil { + sou.(map[string]interface{})["tableName"] = info["tableName"] + } else { + sou.(map[string]interface{})["tableName"] = "鍏朵粬" + } + if info["bwType"] != nil { + sou.(map[string]interface{})["bwType"] = info["bwType"] + } else { + sou.(map[string]interface{})["bwType"] = "4" + } } } } - dmap := make(map[string]interface{},2) + dmap := make(map[string]interface{}, 2) dmap["datalist"] = sources dmap["total"] = dataLen util.ResponseFormat(c, code.Success, dmap) } - // @Summary 鏌ヨ鎽勫儚鏈轰互鍙婂惎绠楁硶 // @Description 鍏宠仈鏌ヨ鎽勫儚鏈轰互鍙婂惎绠楁硶 @@ -111,51 +125,52 @@ util.ResponseFormat(c, code.ComError, "娌℃湁璁板綍") return } - camList := make([]map[string]interface{},0,5) + camList := make([]map[string]interface{}, 0, 5) for _, cam := range rows { newCam := make(map[string]interface{}) newCam["cameraid"] = cam.Id newCam["rtspUrl"] = cam.Rtsp tasks := cam.CamTask - taskList := make([]map[string]interface{},0) + taskList := make([]map[string]interface{}, 0) if tasks != nil { - taskmap:= make(map[string]interface{}) - for _,task := range tasks { + taskmap := make(map[string]interface{}) + for _, task := range tasks { taskId := taskmap[task.Taskid] if taskId != nil { cameraTasks := taskmap[task.Taskid].([]models.CameraTask) - cameraTasks = append(cameraTasks,task) + cameraTasks = append(cameraTasks, task) taskmap[task.Taskid] = cameraTasks - }else { - cameraTasks := make([]models.CameraTask,0) - taskmap[task.Taskid] = append(cameraTasks,task) + } else { + cameraTasks := make([]models.CameraTask, 0) + taskmap[task.Taskid] = append(cameraTasks, task) } } for key, value := range taskmap { i := make(map[string]interface{}) i["taskid"] = key i["sdklist"] = value - taskList = append(taskList,i) + taskList = append(taskList, i) } } newCam["tasklist"] = taskList - camList = append(camList,newCam) + camList = append(camList, newCam) } - c.JSON(200,camList) + c.JSON(200, camList) } func searchEsData(searchBody models.EsSearch) map[string]interface{} { //璇锋眰绱㈠紩 - index := config.EsInfo.EsIndex.VideoPersons.IndexName // wp鍙煡浜鸿劯鏁版嵁 - queryStr := ""; + index := config.EsInfo.EsIndex.VideoPersons.IndexName // wp鍙煡浜鸿劯鏁版嵁 + queryStr := "" queryBody := searchBody.InputValue //妫�绱㈡ if queryBody != "" { - queryStr = "\"must\":[{\"multi_match\":{\"query\":\"" + queryBody + "\",\"fields\":[\"tableName^1.5\",\"gender^2.0\",\"race^2.0\",\"content^1.0\",\"idcard^1.8\",\"picAddress^1.0\"]," + + queryStr = "\"must\":[{\"multi_match\":{\"query\":\"" + queryBody + "\",\"fields\":[\"tableName^1.5\",\"sex^2.0\",\"race^2.0\",\"content^1.0\",\"idCard^1.8\",\"cameraAddr^1.0\"]," + "\"type\":\"cross_fields\",\"operator\":\"OR\",\"slop\":0,\"prefix_length\":0,\"max_expansions\":50,\"zero_terms_query\":\"NONE\",\"auto_generate_synonyms_phrase_query\":true,\"fuzzy_transpositions\":true,\"boost\":1}}]," } - gteDate := searchBody.SearchTime[0];lteDate := searchBody.SearchTime[1] + gteDate := searchBody.SearchTime[0] + lteDate := searchBody.SearchTime[1] //鍒ゆ柇浠诲姟ID taskIdStr := "" taskId := searchBody.Tasks @@ -164,11 +179,11 @@ taskIdStr = "{\"terms\":{\"taskId\":[\"" + esTaskId + "\"]}}," } //鍒ゆ柇鎽勫儚鏈篒D - videoReqNumStr := "" - videoReqNum := searchBody.TreeNodes - if videoReqNum != nil && len(videoReqNum) > 0 { - esVideoReqNum := strings.Replace(strings.Trim(fmt.Sprint(videoReqNum), "[]"), " ", "\",\"", -1) - videoReqNumStr = "{\"terms\":{\"videoReqNum\":[\"" + esVideoReqNum + "\"]}}," + cameraIdStr := "" + cameraId := searchBody.TreeNodes + if cameraId != nil && len(cameraId) > 0 { + esCameraId := strings.Replace(strings.Trim(fmt.Sprint(cameraId), "[]"), " ", "\",\"", -1) + cameraIdStr = "{\"terms\":{\"cameraId\":[\"" + esCameraId + "\"]}}," } //鍒ゆ柇搴撹〃ID tableId := searchBody.Tabs @@ -178,10 +193,10 @@ esTableId = strings.Replace(strings.Trim(fmt.Sprint(tableId), "[]"), " ", "\",\"", -1) esTableIdStr = "{\"terms\":{\"tableId\":[\"" + esTableId + "\"]}}," } - collectionStr := "" - collection := searchBody.Collection - if collection != "" { - collectionStr = "{\"term\":{\"collection\":\"" + collection + "\"}}," + isCollectionStr := "" + isCollection := searchBody.Collection + if isCollection != "" { + isCollectionStr = "{\"term\":{\"collection\":\"" + isCollection + "\"}}," } webPage := searchBody.Page webSize := searchBody.Size @@ -194,22 +209,21 @@ "/" + index + "/_search?search_type=dfs_query_then_fetch" //璇锋眰浣� prama := "{\"from\":\"" + esFrom + "\",\"size\":\"" + esSize + "\"," + -// prama := "{\"size\":\"0\"," + + // prama := "{\"size\":\"0\"," + "\"query\":{\"bool\":{" + queryStr + "\"filter\":[" + - videoReqNumStr + + cameraIdStr + taskIdStr + - collectionStr + + isCollectionStr + esTableIdStr + "{\"range\":{\"picDate\":{\"from\":\"" + gteDate + "\",\"to\":\"" + lteDate + "\",\"include_lower\":true,\"include_upper\":true,\"boost\":1}}}]}}," + "\"sort\":[{\"_score\":{\"order\":\"desc\"}},{\"picDate\":{\"order\":\"desc\"}}]," + - "\"_source\":[\"tableName\",\"gender\",\"race\",\"content\",\"IDCard\",\"picAddress\",\"picDate\",\"sdkType\",\"age\",\"personId\",\"personIsHub\",\"personPicUrl\",\"picLocalUrl\",\"picSmUrl\",\"videoIp\",\"videoNum\",\"videoReqNum\",\"baseInfo\"]}"; + "\"_source\":[\"baseInfo\",\"alarmRules\",\"sex\",\"analyServerName\",\"sdkName\",\"ageDescription\",\"content\",\"id\",\"cameraAddr\",\"picMaxUrl\",\"picDate\",\"race\",\"videoUrl\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"isAlarm\",\"analyServerIp\",\"cameraId\"]}" fmt.Println(prama) //鏁版嵁瑙f瀽 tokenRes := esutil.GetEsDataReq(url, prama, true) return tokenRes } - func sourceCompare(sources []interface{}, isEsSource bool, campareByte []byte, threshold float32) []interface{} { var filterName = "feature" diff --git a/controllers/esSearch.go b/controllers/esSearch.go index d4dca24..9feb959 100644 --- a/controllers/esSearch.go +++ b/controllers/esSearch.go @@ -46,7 +46,7 @@ queryBody := searchBody["inputValue"].(string) //妫�绱㈡ if queryBody != "" { - queryStr = "\"must\":[{\"multi_match\":{\"query\":\"" + queryBody + "\",\"fields\":[\"BaseName^1.5\",\"Gender^2.0\",\"Race^2.0\",\"content^1.0\",\"idcard^1.8\",\"picAddress^1.0\"]," + + queryStr = "\"must\":[{\"multi_match\":{\"query\":\"" + queryBody + "\",\"fields\":[\"tableName^1.5\",\"sex^2.0\",\"race^2.0\",\"content^1.0\",\"idCard^1.8\",\"cameraAddr^1.0\"]," + "\"type\":\"cross_fields\",\"operator\":\"OR\",\"slop\":0,\"prefix_length\":0,\"max_expansions\":50,\"zero_terms_query\":\"NONE\",\"auto_generate_synonyms_phrase_query\":true,\"fuzzy_transpositions\":true,\"boost\":1}}]," } gteDate := searchBody["searchTime"].([]interface{})[0].(string) @@ -59,11 +59,11 @@ taskIdStr = "{\"terms\":{\"taskId\":[\"" + esTaskId + "\"]}}," } //鍒ゆ柇鎽勫儚鏈篒D - videoReqNumStr := "" - videoReqNum := searchBody["treeNodes"].([]interface{}) - if videoReqNum != nil && len(videoReqNum) > 0 { - esVideoReqNum := strings.Replace(strings.Trim(fmt.Sprint(videoReqNum), "[]"), " ", "\",\"", -1) - videoReqNumStr = "{\"terms\":{\"videoReqNum\":[\"" + esVideoReqNum + "\"]}}," + 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 @@ -75,10 +75,10 @@ index = config.EsInfo.EsIndex.VideoPersons.IndexName esTableIdStr = "{\"terms\":{\"tableId\":[\"" + esTableId + "\"]}}," } - collectionStr := "" - collection := searchBody["collection"].(string) - if collection != "" { - collectionStr = "{\"term\":{\"collection\":\"" + collection + "\"}}," + isCollectStr := "" + isCollect := searchBody["collection"].(string) + if isCollect != "" { + isCollectStr = "{\"term\":{\"isCollect\":\"" + isCollect + "\"}}," } //浣跨敤es搴曞眰鏈哄埗澶勭悊鍒嗛〉 @@ -90,13 +90,13 @@ "\"size\":\"" + size + "\"," + "\"query\":{\"bool\":{" + queryStr + "\"filter\":[" + - videoReqNumStr + + cameraIdStr + taskIdStr + - collectionStr + + isCollectStr + esTableIdStr + "{\"range\":{\"picDate\":{\"from\":\"" + gteDate + "\",\"to\":\"" + lteDate + "\",\"include_lower\":true,\"include_upper\":true,\"boost\":1}}}]}}," + "\"sort\":[{\"_score\":{\"order\":\"desc\"}},{\"picDate\":{\"order\":\"desc\"}}]," + - "\"_source\":[\"baseInfo\",\"gender\",\"indeviceName\",\"sdkType\",\"ageDescription\",\"content\",\"ID\",\"picAddress\",\"picMaxUrl\",\"picDate\",\"race\",\"videoNum\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"IDCard\",\"videoIp\",\"videoReqNum\"]" + + "\"_source\":[\"baseInfo\",\"alarmRules\",\"sex\",\"analyServerName\",\"sdkName\",\"ageDescription\",\"content\",\"id\",\"cameraAddr\",\"picMaxUrl\",\"picDate\",\"race\",\"videoUrl\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"isAlarm\",\"analyServerIp\",\"cameraId\"]" + "}" fmt.Println(prama) //鏁版嵁瑙f瀽 @@ -104,7 +104,7 @@ return tokenRes } -//sdkTYype瀛楀吀"\"_source\":[\"BaseName\",\"Gender\",\"Race\",\"content\",\"idcard\",\"picAddress\",\"picDate\",\"sdkType\",\"Age\",\"personId\",\"personIsHub\",\"personPicUrl\",\"picLocalUrl\",\"picSmUrl\",\"videoIp\",\"videoNum\",\"videoReqNum\",\"ageDescription\",\"likePer\"]" + +//sdkTYype瀛楀吀"\"_source\":[\"BaseName\",\"Gender\",\"Race\",\"content\",\"idcard\",\"picAddress\",\"picDate\",\"sdkType\",\"Age\",\"personId\",\"personIsHub\",\"personPicUrl\",\"picLocalUrl\",\"picSmUrl\",\"videoIp\",\"videoNum\",\"cameraId\",\"ageDescription\",\"likePer\"]" + //func sdkTypeToValue(i int) string { // value := []string{"浜鸿劯", "杞﹁締", "浜轰綋", "鍏ヤ镜", "鎷ユ尋", "闈犲彸琛�", "浜哄憳寮傚父", "涓綋闈欐"} // return value[i-1] diff --git a/controllers/monitoring.go b/controllers/monitoring.go index 6dc8bb4..6292953 100644 --- a/controllers/monitoring.go +++ b/controllers/monitoring.go @@ -26,11 +26,11 @@ c.BindJSON(&searchBody) index := config.EsInfo.EsIndex.VideoPersons.IndexName - videoReqNumStr := "" - videoReqNum := searchBody["treeNodes"].([]interface{}) - if videoReqNum != nil && len(videoReqNum) > 0 { - esVideoReqNum := strings.Replace(strings.Trim(fmt.Sprint(videoReqNum), "[]"), " ", "\",\"", -1) - videoReqNumStr = "{\"terms\":{\"videoReqNum\":[\"" + esVideoReqNum + "\"]}}," + 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 := "" @@ -44,12 +44,12 @@ "/" + index + "/_search" prama := "{\"query\":{\"bool\":{\"filter\":[" + - videoReqNumStr + + cameraIdStr + taskIdStr + "{\"range\":{\"picDate\":{\"gte\":\"now+8h-5s\",\"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\",\"videoReqNum\"]}" + "\"_source\":[\"baseInfo\",\"gender\",\"indeviceName\",\"sdkType\",\"ageDescription\",\"content\",\"ID\",\"picAddress\",\"picMaxUrl\",\"picDate\",\"race\",\"videoNum\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"IDCard\",\"videoIp\",\"cameraId\"]}" fmt.Println(prama) tokenRes := esutil.GetEsDataReq(url, prama, true) /* for _, value := range tokenRes["datalist"].([]interface{}) { diff --git a/extend/esutil/EsClient.go b/extend/esutil/EsClient.go index 20f3fa7..79ece4f 100644 --- a/extend/esutil/EsClient.go +++ b/extend/esutil/EsClient.go @@ -9,7 +9,6 @@ "log" "mime/multipart" "net/http" - "strconv" "strings" "time" @@ -46,11 +45,11 @@ for _, value := range dat["hits"].([]interface{}) { source := value.(map[string]interface{})["_source"].(map[string]interface{}) source["id"] = value.(map[string]interface{})["_id"] - sdkType := source["sdkType"] + /*sdkType := source["sdkType"] if sdkType != nil { sdk, _ := strconv.Atoi(sdkType.(string)) source["sdkType"] = sdkTypeToValue(sdk) - } + }*/ sources = append(sources, source) } data["datalist"] = sources @@ -62,10 +61,10 @@ } //sdk绫诲瀷 -func sdkTypeToValue(i int) string { +/*func sdkTypeToValue(i int) string { value := []string{"浜鸿劯", "杞﹁締", "浜轰綋", "鍏ヤ镜", "鎷ユ尋", "闈犲彸琛�", "浜哄憳寮傚父", "涓綋闈欐"} return value[i-1] -} +}*/ func PutEsDataReq(url string, parama string) (map[string]interface{}, error) { //fmt.Println("es 鏌ヨ璇锋眰璺緞" + url) // 閰嶇疆淇℃伅 鑾峰彇 diff --git a/service/CameraVideoService.go b/service/CameraVideoService.go index 74423c3..907dd8e 100644 --- a/service/CameraVideoService.go +++ b/service/CameraVideoService.go @@ -16,10 +16,12 @@ if reqBody.DataBases != nil { tableIds = reqBody.DataBases } - startDate := "";endDate := "" + startDate := "" + endDate := "" if reqBody.SearchTime != nil && len(reqBody.SearchTime) >= 2 { dates := reqBody.SearchTime - startDate = dates[0];endDate = dates[1] // 璧峰缁撴潫鏃堕棿 + startDate = dates[0] + endDate = dates[1] // 璧峰缁撴潫鏃堕棿 } contentValue := reqBody.InputValue //杈撳叆妗嗗唴瀹� /*page := 1 ;if reqBody["page"] != nil { page = int(reqBody["page"].(float64)) } // 椤电爜 @@ -35,7 +37,7 @@ syncTerm += ",{\"terms\":{\"tableId\":" + string(bytes) + "}}" // 搴曞簱浜哄憳 } if startDate != "" && endDate != "" { - syncTerm += ",{\"range\":{\"create_time\":{\"from\":\"" + startDate + "\"," + + syncTerm += ",{\"range\":{\"createTime\":{\"from\":\"" + startDate + "\"," + "\"to\":\"" + endDate + "\",\"include_lower\":true,\"include_upper\":true,\"boost\":1}}}" // 搴曞簱浜哄憳 } if contentValue != "" { @@ -43,10 +45,8 @@ "\"fields\":[\"personName\",\"sex\",\"idcard\",\"phoneNum\",\"reserved\"],\"boost\":1}}]" } params := "{\"query\":{\"bool\":{\"filter\":[" + - "{\"term\":{\"del_flag\":\"0\"}}" + syncTerm + "]" + contentParam + "}},\"from\":0,\"size\":10000,\"sort\":{\"uuid\":{\"order\":\"desc\"}}}" + "{\"term\":{\"isDelete\":\"0\"}}" + syncTerm + "]" + contentParam + "}},\"from\":0,\"size\":10000,\"sort\":{\"uuid\":{\"order\":\"desc\"}}}" fmt.Print("鏌ヨ鍏ㄩ儴搴曞簱浜哄憳 璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params) data := esutil.GetEsDataReq(url, params, true) return data } - - -- Gitblit v1.8.0