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

---
 service/SdkInstall.go |   35 +++++++++++
 controllers/task.go   |   88 ++++++++++++++---------------
 controllers/sdk.go    |   38 ++++++++++--
 router/router.go      |    1 
 4 files changed, 109 insertions(+), 53 deletions(-)

diff --git a/controllers/sdk.go b/controllers/sdk.go
index d314a68..479c16c 100644
--- a/controllers/sdk.go
+++ b/controllers/sdk.go
@@ -47,7 +47,7 @@
 // @Description 绠楁硶淇濆瓨
 // @Accept json
 // @Produce json
-// @Tags sdk
+// @Tags 绠楁硶
 // @Param reqMap body controllers.SdkVo true "浜鸿劯妫�娴�"
 // @Success 200 {string} json "{"code":200, msg:"璇锋眰澶勭悊鎴愬姛",data:"",success:true}"
 // @Failure 500 {string} json "{"code":500, msg:"璇锋眰澶辫触",data:"",success:false}"
@@ -73,7 +73,7 @@
 // @Summary 鏌ユ壘鎵�鏈夌畻娉�
 // @Description 鏌ユ壘鎵�鏈夌畻娉�
 // @Produce json
-// @Tags sdk
+// @Tags 绠楁硶
 // @Param sdkName query string false "鍙�夊弬鏁�"
 // @Success 200 {string} json "{"code":200, msg:"璇锋眰澶勭悊鎴愬姛",data:"绠楁硶鍒楄〃",success:true}"
 // @Failure 500 {string} json "{"code":500, msg:"璇锋眰澶辫触",data:"[]",success:false}"
@@ -91,7 +91,7 @@
 // @Summary 鏍规嵁id鑾峰彇绠楁硶淇℃伅
 // @Description 鏍规嵁id鑾峰彇绠楁硶淇℃伅
 // @Produce json
-// @Tags sdk
+// @Tags 绠楁硶
 // @Param id query string true "绠楁硶id锛屽繀濉�"
 // @Success 200 {string} json "{"code":200, msg:"璇锋眰澶勭悊鎴愬姛",data:"绠楁硶淇℃伅",success:true}"
 // @Failure 500 {string} json "{"code":500, msg:"璇锋眰澶辫触",data:"",success:false}"
@@ -134,7 +134,7 @@
 // @Summary 鏍规嵁taskId鑾峰彇绠楁硶淇℃伅
 // @Description 鏍规嵁taskId鑾峰彇绠楁硶淇℃伅
 // @Produce json
-// @Tags sdk
+// @Tags 绠楁硶
 // @Param taskId query string true "taskId锛屽繀濉�"
 // @Success 200 {string} json "{"code":200, msg:"璇锋眰澶勭悊鎴愬姛",data:"绠楁硶淇℃伅",success:true}"
 // @Failure 500 {string} json "{"code":500, msg:"璇锋眰澶辫触",data:"",success:false}"
@@ -158,7 +158,7 @@
 // @Description 绠楁硶瀹夎鍖呬笂浼�(鍒嗗潡妫�鏌�)
 // @Accept multipart/form-data
 // @Produce json
-// @Tags sdk
+// @Tags 绠楁硶
 // @Param chunkNumber formData int true "褰撳墠鏄鍑犱釜鍒嗗潡"
 // @Param chunkSize formData int true "姣忎竴鍧楃殑澶у皬"
 // @Param currentChunkSize formData int true "褰撳墠鍧楃殑澶у皬"
@@ -210,7 +210,7 @@
 // @Description 绠楁硶瀹夎鍖呬笂浼�
 // @Accept multipart/form-data
 // @Produce json
-// @Tags sysset
+// @Tags 绠楁硶
 // @Param chunkNumber formData int true "褰撳墠鏄鍑犱釜鍒嗗潡"
 // @Param chunkSize formData int true "姣忎竴鍧楃殑澶у皬"
 // @Param currentChunkSize formData int true "褰撳墠鍧楃殑澶у皬"
@@ -278,7 +278,7 @@
 // @Summary 浠庡晢鍩庝笅杞芥垨鍗囩骇绠楁硶
 // @Description 浠庡晢鍩庝笅杞芥垨鍗囩骇绠楁硶
 // @Produce json
-// @Tags sysset
+// @Tags 绠楁硶
 // @Param path query string true "绠楁硶id"
 // @Success 200 {string} json "{"code":200, msg:"", success:true}"
 // @Failure 500 {string} json "{"code":500, msg:"", success:false}"
@@ -296,3 +296,27 @@
 		util.ResponseFormat(c, &code.Code{http.StatusBadRequest, false, err.Error()}, err.Error())
 	}
 }
+
+// @Security ApiKeyAuth
+// @Summary 浣跨敤婵�娲荤爜婵�娲诲畨瑁呯畻娉�
+// @Description 浣跨敤婵�娲荤爜婵�娲诲畨瑁呯畻娉�
+// @Produce json
+// @Tags 绠楁硶
+// @Param code query string true "婵�娲荤爜"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/sdk/active [get]
+func (sc SdkController) Active(c *gin.Context) {
+	cod := c.GetString("code")
+	if cod == "" {
+		util.ResponseFormat(c, code.RequestParamError, "婵�娲荤爜涓嶈兘涓虹┖")
+		return
+	}
+	var sv service.SdkInstallService
+	err := sv.Active(cod)
+	if err == nil {
+		util.ResponseFormat(c,code.Success,  "婵�娲绘垚鍔�")
+	} else {
+		util.ResponseFormat(c,code.ComError, err.Error())
+	}
+}
\ No newline at end of file
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
diff --git a/router/router.go b/router/router.go
index 436faf5..255aa90 100644
--- a/router/router.go
+++ b/router/router.go
@@ -292,6 +292,7 @@
 		sdkApi.GET("/sdkDownload", sdkController.SdkDownLoad)
 		sdkApi.GET("/upload", sdkController.Upload)
 		sdkApi.POST("/upload", sdkController.UploadPack)
+		sdkApi.GET("/active", sdkController.Active)
 	}
 
 	//绠楁硶鍙傛暟
diff --git a/service/SdkInstall.go b/service/SdkInstall.go
index 2f6c74a..62e7af2 100644
--- a/service/SdkInstall.go
+++ b/service/SdkInstall.go
@@ -2,6 +2,7 @@
 
 import (
 	"basic.com/dbapi.git"
+	"basic.com/valib/licence.git"
 	"basic.com/valib/logger.git"
 	"encoding/json"
 	"errors"
@@ -13,12 +14,46 @@
 	"strings"
 	"webserver/extend/config"
 	"webserver/extend/util"
+	reqUtil "webserver/extend/util"
 )
 
 type SdkInstallService struct {
 
 }
 
+func (sv SdkInstallService) Active(cod string) error {
+	//浣跨敤婵�娲荤爜婵�娲荤畻娉�
+	url := "http://"+config.ShopConf.Url+"/data/api-s/sdk/activeByAINode"
+	machineCode := licence.GetMachineCode()
+	if machineCode == "" {
+		logger.Debug("鑾峰彇鏈哄櫒鐮佸け璐�")
+		return errors.New("鑾峰彇鏈哄櫒鐮佸け璐�")
+	}
+	paramBody := map[string]interface{}{
+		"code": cod,
+		"machineCode": machineCode,
+	}
+	header := map[string]string {
+		"Authorization": token,
+	}
+	respBody, err := reqUtil.DoPostRequest(url, reqUtil.CONTENT_TYPE_JSON, paramBody, nil, header)
+	if err != nil {
+		logger.Debug("DoPostRequest err:", err)
+		return err
+	}
+	var res dbapi.Result
+	if err = json.Unmarshal(respBody, &res); err != nil {
+		logger.Debug("unmarshal err:", err)
+		return err
+	}
+	if !res.Success {
+		logger.Debug("res.Data:", res.Data)
+		return errors.New("璇锋眰鍟嗗煄澶辫触")
+	}
+
+	return nil
+}
+
 //绠楁硶瀹夎鍖呭畨瑁�
 func (sv SdkInstallService) SdkInstall(identifier string,filename string) (bool,error) {
 	configPatchPath := ""

--
Gitblit v1.8.0