From 539a78196da60eb97cf7057c5c85dfaa9b240741 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期五, 11 十月 2024 16:21:32 +0800
Subject: [PATCH] 添加A3平层传感器数据获取方式

---
 controller/subscribeCtl.go |   77 ++++++++++++++++++++++++++++++++++----
 1 files changed, 69 insertions(+), 8 deletions(-)

diff --git a/controller/subscribeCtl.go b/controller/subscribeCtl.go
index 6f2995d..cf4fe73 100644
--- a/controller/subscribeCtl.go
+++ b/controller/subscribeCtl.go
@@ -1,27 +1,30 @@
 package controller
 
 import (
+	"net/http"
+	"strings"
+	"time"
+
 	"gat1400Exchange/config"
 	"gat1400Exchange/pkg/logger"
 	"gat1400Exchange/repository"
 	"gat1400Exchange/vo"
-	"net/http"
-	"strings"
-	"time"
 
 	"github.com/gin-gonic/gin"
 )
 
 type SubscribeController struct {
 	Repository repository.SubscribeRepository
-	Srv        repository.CaptureRepository
+	Capture    repository.CaptureRepository
+	Ape        repository.ApeRepository
 }
 
 // 鏋勯�犲嚱鏁�
 func NewSubscribeController() SubscribeController {
 	svr := repository.NewSubscribeRepository()
 	svr1 := repository.NewCaptureRepository()
-	controller := SubscribeController{svr, svr1}
+	svr2 := repository.NewApeRepository()
+	controller := SubscribeController{svr, svr1, svr2}
 
 	return controller
 }
@@ -77,6 +80,8 @@
 				Id:           sub.SubscribeID,
 				LocalTime:    time.Now().Format("20060102150405"),
 			})
+		} else {
+			logger.Error("Update receive subscribe failure, %s", err.Error())
 		}
 	}
 
@@ -104,7 +109,7 @@
 	c.JSON(http.StatusOK, gin.H{"ResponseStatusListObject": rsp})
 }
 
-func (s SubscribeController) Notifications(c *gin.Context) {
+func (s SubscribeController) VIIDNotifications(c *gin.Context) {
 	var rsp vo.ResponseStatusList
 	var req vo.RequestSubscribeNotificationBind
 	if err := c.BindJSON(&req); err != nil {
@@ -124,8 +129,17 @@
 		})
 
 		// 杞彂
-		if config.ForwardConf.SyncServer != "" {
-			go s.Srv.FaceForward(msg.FaceObjectList.FaceObject)
+		if config.ForwardConf.SyncServer != "" && len(msg.FaceObjectList.FaceObject) > 0 {
+			go s.Capture.FaceForward(msg.FaceObjectList.FaceObject)
+		}
+
+		if config.ForwardConf.SyncServer != "" && len(msg.PersonObjectList.PersonObject) > 0 {
+			go s.Capture.PersonForward(msg.PersonObjectList.PersonObject)
+		}
+
+		if len(msg.DeviceList.APEObject) > 0 {
+			fromId := c.GetHeader("User-Identify")
+			go s.Ape.HandleNotification(fromId, msg.DeviceList.APEObject)
 		}
 	}
 
@@ -172,3 +186,50 @@
 
 	c.JSON(http.StatusOK, gin.H{"msg": "ok"})
 }
+
+func (s SubscribeController) CancelSubscribes(c *gin.Context) {
+	var req vo.Subscribe
+	if err := c.BindJSON(&req); err != nil {
+		c.JSON(http.StatusBadRequest, gin.H{"msg": err.Error()})
+		return
+	}
+
+	if c.Param("id") == "" {
+		c.JSON(http.StatusBadRequest, gin.H{"msg": "涓嬬骇id涓虹┖"})
+	}
+
+	if err := s.Repository.CancelSubscribe(c.Param("id"), &req); err != nil {
+		c.JSON(http.StatusInternalServerError, gin.H{"msg": err.Error()})
+		return
+	}
+
+	c.JSON(http.StatusOK, gin.H{"msg": "ok"})
+}
+
+func (s SubscribeController) List(c *gin.Context) {
+	if c.Param("id") == "" {
+		c.JSON(http.StatusBadRequest, gin.H{"msg": "涓嬬骇id涓虹┖"})
+	}
+
+	list, err := s.Repository.ListByFromId(c.Param("id"))
+	if err != nil {
+		c.JSON(http.StatusInternalServerError, gin.H{"msg": err.Error()})
+		return
+	}
+
+	c.JSON(http.StatusOK, gin.H{"msg": "ok", "data": list})
+}
+
+func (s SubscribeController) RemoteList(c *gin.Context) {
+	if c.Param("id") == "" {
+		c.JSON(http.StatusBadRequest, gin.H{"msg": "涓嬬骇id涓虹┖"})
+	}
+
+	data, err := s.Repository.RemoteList(c.Param("id"))
+	if err != nil {
+		c.JSON(http.StatusInternalServerError, gin.H{"msg": err.Error()})
+		return
+	}
+
+	c.JSON(http.StatusOK, gin.H{"msg": "ok", "data": data})
+}

--
Gitblit v1.8.0