zhangzengfei
2024-10-11 539a78196da60eb97cf7057c5c85dfaa9b240741
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})
}