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 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)

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) {

--
Gitblit v1.8.0