From b2782f7b8b49806ac67663e2ec9e25c44b69d041 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期六, 27 七月 2019 15:04:06 +0800
Subject: [PATCH] fix twice searchByPhoto
---
controllers/fileController.go | 87 +++++++++++++++++++++++++++++
extend/code/code.go | 2
controllers/es.go | 52 ++++++-----------
models/esSearch.go | 1
4 files changed, 109 insertions(+), 33 deletions(-)
diff --git a/controllers/es.go b/controllers/es.go
index fe2afbc..46cb2f5 100644
--- a/controllers/es.go
+++ b/controllers/es.go
@@ -33,40 +33,26 @@
util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
return
}
- databases := searchBody.DataBases
- from := 0
- to := 0
-
- data := make(map[string]interface{})
- searchBody.Page = 1
- searchBody.Size = 15000
-
- if len(databases) == 1 && databases[0] == "esData" {
- searchBody.IsAggs = false
- } else {
- data = service.QueryDbPersonsForCompare(*searchBody)
+ if searchBody.CompareNum !="" {
+ //浜屾鎼滅储锛屼笉闇�瑕佸啀姣斿浜�
+ co := service.GetCompResultByNum(searchBody.CompareNum)
+ if co != nil {
+ //浜屾鎼滅储鍜屾帓搴�
+ twiceM := GetCompareDataTwice(co,searchBody)
+ util.ResponseFormat(c,code.Success,twiceM)
+ } else {
+ m :=make(map[string]interface{},0)
+ m["compareNum"] = searchBody.CompareNum
+ m["total"] = 0
+ m["totalList"] = []service.CompareResult{}
+ util.ResponseFormat(c,code.CompareResultGone,m)
+ }
}
- sources := data["datalist"].([]interface{})
-
- if len(sources) > 0 {
- //杩涜姣斿
- } else {
- fmt.Println("鏌ヨ鏉′欢涓嬫棤鏁版嵁 source 鏁版嵁涓虹┖锛�" + string(len(sources)))
- }
- dataLen := len(sources)
- if from > dataLen-1 {
- from = 0
- to = 0
- }
- if to > dataLen {
- to = dataLen
- }
-
- dmap := make(map[string]interface{}, 2)
- dmap["datalist"] = sources
- dmap["total"] = dataLen
- util.ResponseFormat(c, code.Success, dmap)
-
+ m :=make(map[string]interface{},0)
+ m["compareNum"] = searchBody.CompareNum
+ m["total"] = 0
+ m["totalList"] = []service.CompareResult{}
+ util.ResponseFormat(c,code.CompareResultGone,m)
}
func searchEsData(searchBody models.EsSearch) map[string]interface{} {
diff --git a/controllers/fileController.go b/controllers/fileController.go
index 080660d..a82d000 100644
--- a/controllers/fileController.go
+++ b/controllers/fileController.go
@@ -163,6 +163,21 @@
util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
return
}
+ if searchBody.CompareNum !="" {
+ //浜屾鎼滅储锛屼笉闇�瑕佸啀姣斿浜�
+ co := service.GetCompResultByNum(searchBody.CompareNum)
+ if co != nil {
+ //浜屾鎼滅储鍜屾帓搴�
+ twiceM := GetCompareDataTwice(co,&searchBody)
+ util.ResponseFormat(c,code.Success,twiceM)
+ } else {
+ m :=make(map[string]interface{},0)
+ m["compareNum"] = searchBody.CompareNum
+ m["total"] = 0
+ m["totalList"] = []service.CompareResult{}
+ util.ResponseFormat(c,code.CompareResultGone,m)
+ }
+ }
var sysSetApi dbapi.SysSetApi
analyServerId := ""
flag, sysconf := sysSetApi.GetServerInfo()
@@ -221,6 +236,78 @@
}
}
+func GetCompareDataTwice(co *service.CompareOnce,arg *models.EsSearch) map[string]interface{} {
+ camIds := arg.TreeNodes
+ tabIds := arg.Tabs
+ taskIds := arg.Tasks
+ alarmLevels := arg.AlarmLevel
+ timeArr := arg.SearchTime
+ input := arg.InputValue
+ resultList := make([]service.CompareResult,0)
+ for _,cr :=range co.CompareData {
+ if cr.Id !=""{
+ n :=0
+ if len(camIds) == 0 || isInArr(cr.CameraId,camIds) {
+ n++
+ }
+ if len(tabIds) == 0 {
+ n++
+ }
+ if len(taskIds) == 0 || isInArr(cr.TaskId, taskIds) {
+ n++
+ }
+ //鍒ゆ柇鎶ヨ绛夌骇
+ if len(alarmLevels) == 0 {
+
+ }
+ n++
+ //鍒ゆ柇鏃堕棿
+ if len(timeArr) == 0 {
+
+ }
+ n++
+ if input == ""{
+
+ }
+ n++
+ if n == 6 {
+ resultList = append(resultList,cr)
+ }
+ } else {
+ resultList = append(resultList,cr)
+ }
+ }
+ logger.Debug("GetCompareDataTwice.data:",resultList)
+ service.SortByScore(resultList)
+ from := (arg.Page-1)*arg.Size
+ to := from + arg.Size
+ lenth := len(resultList)
+ m := make(map[string]interface{},0)
+ m["total"] = lenth
+ m["compareNum"] = arg.CompareNum
+
+ if from < len(resultList) {
+ if to <= len(resultList) {
+ m["totalList"] = resultList[from:to]
+ } else {
+ m["totalList"] = resultList[from:len(resultList)]
+ }
+ } else {
+ m["totalList"] = []service.CompareResult{}
+ }
+ return m
+}
+
+func isInArr(id string,arr []string) bool {
+ for _,v :=range arr {
+ if v == id {
+ return true
+ }
+ }
+ return false
+}
+
+
// @Description 浜哄憳鐓х墖涓婁紶骞惰幏鍙栫壒寰佸��
// @Router /data/api-v/dbperson/fileUploadTest [POST]
func (controller FileController) UploadPersonTest(c *gin.Context) {
diff --git a/extend/code/code.go b/extend/code/code.go
index 943a100..b54c52c 100644
--- a/extend/code/code.go
+++ b/extend/code/code.go
@@ -50,5 +50,7 @@
NotLogin = &Code{ http.StatusUnauthorized, false, "鐧诲綍澶辨晥锛岃閲嶆柊鐧诲綍"}
DbPersonUploadSuccess = &Code{ http.StatusOK, true, "浜哄憳涓婁紶鎴愬姛"}
DbPersonUpdateSuccess = &Code{ http.StatusOK, true, "浜哄憳鏇存柊鎴愬姛"}
+
+ CompareResultGone = &Code{ http.StatusOK,true,"涓婃姣斿宸插け鏁堬紝璇蜂粠鏂版瘮瀵�"}
ComError = &Code{http.StatusInternalServerError, false, ""}
)
diff --git a/models/esSearch.go b/models/esSearch.go
index 81e4c76..2141121 100644
--- a/models/esSearch.go
+++ b/models/esSearch.go
@@ -15,4 +15,5 @@
InputValue string `json:"inputValue"`//杈撳叆妗�
Collection string `json:"collection"`//
AlarmLevel []string `json:"alarmLevel"`//甯冮槻绛夌骇
+ CompareNum string `json:"compareNum"`//姣斿缂栧彿
}
--
Gitblit v1.8.0