From 4ec7b884fcec0f2566b1ee132955ac051c22f950 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期三, 02 九月 2020 13:57:27 +0800
Subject: [PATCH] add all function outside sort

---
 EsApi.go |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/EsApi.go b/EsApi.go
index 2eb29eb..64235bf 100644
--- a/EsApi.go
+++ b/EsApi.go
@@ -257,20 +257,23 @@
 	if err != nil {
 		return nil, err
 	}
+	if len(source) == 0{
+		return source,nil
+	}
 	faceSource := make([]map[string]interface{}, 0)
 	for index, info := range source {
 		if int(info["stayTime"].(float64)) > thresholdStayTime {
 			faceSource = append(faceSource, source[index])
 		}
 	}
+	mapsSort := MapsSort{}
+	mapsSort.Key = "endTime"
+	mapsSort.MapList = faceSource
+	sort.Sort(&mapsSort)
 	if len(faceSource) > total {
-		mapsSort := MapsSort{}
-		mapsSort.Key = "endTime"
-		mapsSort.MapList = faceSource
-		sort.Sort(&mapsSort)
 		return mapsSort.MapList[:total], nil
 	}
-	return faceSource, nil
+	return mapsSort.MapList, nil
 }
 
 func GetFaceDataByTimeAndId(startTime string, endTime string, id string, thresholdTime int, thresholdStayTime int, serverIp string, serverPort string, indexName string) (resData []map[string]interface{}, err error) {
@@ -355,13 +358,20 @@
 	if err != nil {
 		return nil, err
 	}
+	if len(source) == 0{
+		return source,nil
+	}
 	faceSource := make([]map[string]interface{}, 0)
 	for index, info := range source {
 		if int(info["stayTime"].(float64)) > thresholdStayTime {
 			faceSource = append(faceSource, source[index])
 		}
 	}
-	return faceSource, nil
+	mapsSort := MapsSort{}
+	mapsSort.Key = "startTime"
+	mapsSort.MapList = faceSource
+	sort.Sort(&mapsSort)
+	return mapsSort.MapList, nil
 }
 
 func GetFaceIdDeduplication(startTime string, endTime string, serverIp string, serverPort string, indexName string) (ids []map[string]interface{}, err error) {
@@ -434,7 +444,7 @@
 	if err1 != nil {
 		return nil, err1
 	}
-	if len(ids) > 0 {
+	if len(ids) > 1 {
 		mapsSort := MapsSort{}
 		mapsSort.Key = "lastTime"
 		mapsSort.MapList = ids

--
Gitblit v1.8.0