From 1b4337e04bc35c8b6f4931a5896f04884fef69c6 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期四, 02 七月 2020 15:18:43 +0800
Subject: [PATCH] fix AggregateTaskList

---
 controllers/task.go |   88 +++++++++++++++++++++-----------------------
 1 files changed, 42 insertions(+), 46 deletions(-)

diff --git a/controllers/task.go b/controllers/task.go
index b66a0f1..51f3a81 100644
--- a/controllers/task.go
+++ b/controllers/task.go
@@ -1,9 +1,14 @@
 package controllers
 
 import (
+	"basic.com/dbapi.git"
+	"basic.com/pubsub/esutil.git"
 	"github.com/gin-gonic/gin"
+	"strconv"
 	"time"
+	"webserver/cache"
 	"webserver/extend/code"
+	"webserver/extend/config"
 	"webserver/extend/util"
 )
 
@@ -72,52 +77,43 @@
 // @Router /data/api-v/task/aggregateTaskList [GET]
 func (tc TaskController) AggregateTaskList(c *gin.Context) {
 	// 鏄剧ず鎵�鏈変换鍔�: 鑾峰彇淇℃伅
-	//var taskApi dbapi.TaskApi
-	//
-	//taskInfos := taskApi.FindAll()
-	//m := make(map[string]string)
-	//var arr []protomsg.TaskSdkInfo
-	//for _,ti :=range taskInfos{
-	//	if ti.Task.Taskid != FaceExtract_VirtualTaskId{
-	//		arr = append(arr,ti)
-	//		m[ti.Task.Taskid] = ti.Task.Taskid
-	//	}
-	//}
-	//var tasks []TaskSdkVo
-	//dataBytes, err := json.Marshal(arr)
-	//if err !=nil {
-	//	util.ResponseFormat(c,code.ComError,[]TaskSdkVo{})
-	//} else {
-	//	if err := json.Unmarshal(dataBytes, &tasks);err !=nil {
-	//		util.ResponseFormat(c,code.ComError,[]TaskSdkVo{})
-	//	} else {
-	//		//澶勭悊宸茶鍒犻櫎鐨勪换鍔�
-	//		localConf, _ := cache.GetServerInfo()
-	//		if localConf.AlarmIp != "" && localConf.ServerId != "" && localConf.AlarmPort>0 {
-	//			indexName := config.EsInfo.EsIndex.AiOcean.IndexName
-	//			esTaskM, e := esutil.AggregateTaskList(localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort)), indexName, localConf.ServerId)
-	//			if e==nil && esTaskM !=nil {
-	//				for _,tM :=range esTaskM {
-	//					if _,ok := m[tM["taskId"].(string)];!ok {//琛ㄧず姝や换鍔″凡琚垹闄�
-	//						taskId := tM["taskId"].(string)
-	//						m[taskId] = taskId
-	//						tasks = append(tasks, TaskSdkVo{
-	//							Task:TaskVo{
-	//								Taskid:	taskId,
-	//								Taskname: tM["taskName"].(string),
-	//								DelFlag: true,
-	//							},
-	//							Sdks:[]SdkVo{},
-	//						})
-	//					}
-	//				}
-	//			}
-	//		}
-	//
-	//		util.ResponseFormat(c,code.Success,tasks)
-	//	}
-	//}
-	util.ResponseFormat(c,code.Success,[]interface{}{})
+	var api dbapi.CameraRuleApi
+
+	var result []SceneIfDelResult
+	m := make(map[string]string)
+	if b, allRules := api.FindAll(); b {
+		for _,cg :=range allRules {
+			for _,g := range cg.Rules {
+				m[g.Id] = g.SceneName
+				result = append(result, SceneIfDelResult{
+					Id: g.Id,
+					Name: g.SceneName,
+					IsDelete: false,
+				})
+			}
+		}
+	}
+
+	localConf, _ := cache.GetServerInfo()
+	if localConf.AlarmIp != "" && localConf.ServerId != "" && localConf.AlarmPort>0 {
+		indexName := config.EsInfo.EsIndex.AiOcean.IndexName
+		esTaskM, e := esutil.AggregateTaskList(localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort)), indexName, localConf.ServerId)
+		if e==nil && esTaskM !=nil {
+			for _,tM :=range esTaskM {
+				if _,ok := m[tM["taskId"].(string)];!ok {//琛ㄧず姝や换鍔″凡琚垹闄�
+					taskId := tM["taskId"].(string)
+					taskName := tM["taskName"].(string)
+					m[taskId] = taskName
+					result = append(result, SceneIfDelResult{
+						Id: taskId,
+						Name: taskName,
+						IsDelete: true,
+					})
+				}
+			}
+		}
+	}
+	util.ResponseFormat(c, code.Success, result)
 }
 
 //// @Security ApiKeyAuth

--
Gitblit v1.8.0