From d94f80d854d09e89715ca7c2361cd6057f98f396 Mon Sep 17 00:00:00 2001
From: sunty <suntianyu0923@163.com>
Date: 星期三, 31 七月 2019 17:21:42 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 controllers/fileController.go |   96 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 95 insertions(+), 1 deletions(-)

diff --git a/controllers/fileController.go b/controllers/fileController.go
index 080660d..f0eb62f 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()
@@ -203,10 +218,15 @@
 
 		logger.Debug("arg.TableIds:", arg.TableIds, ",alarmLevel:",arg.AlarmLevel,",treeNodes:",arg.TreeNodes,",searchTime:",arg.SearchTime,
 			",inputValue:",arg.InputValue,",tasks:",arg.Tasks,",compThreshold:",arg.CompareThreshold)
+		timeStart := time.Now()
+
 		compareService := service.NewFaceCompareService(arg)
 		compareOnce := compareService.Compare()
-		logger.Debug("compareResult:",*compareOnce)
+		//logger.Debug("compareResult.len:",*compareOnce)
 		dataList := compareOnce.CompareData
+
+		logger.Debug("comp 姣斿缁撴潫锛岀敤鏃讹細",time.Since(timeStart))
+
 		service.SortByScore(dataList)
 		totalList := len(dataList)
 		m := make(map[string]interface{},3)
@@ -217,10 +237,84 @@
 		} else {
 			m["totalList"] = dataList[0:searchBody.Size]
 		}
+		logger.Debug("comp 姣斿鍔犳帓搴忚繑鍥炵敤鏃�:", time.Since(timeStart))
 		util.ResponseFormat(c,code.Success,m)
 	}
 }
 
+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 {
+			lte := len(resultList)
+			m["totalList"] = resultList[from:lte]
+		}
+	} 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