| | |
| | | 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 |
| | | } |
| | |
| | | Id: sub.SubscribeID, |
| | | LocalTime: time.Now().Format("20060102150405"), |
| | | }) |
| | | } else { |
| | | logger.Error("Update receive subscribe failure, %s", err.Error()) |
| | | } |
| | | } |
| | | |
| | |
| | | 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 { |
| | |
| | | }) |
| | | |
| | | // 转发 |
| | | 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) |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | 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}) |
| | | } |