zhangzengfei
2024-05-16 5179bc5c1501aa12e87c1162d5a1f91aea33abd4
添加订阅接收,转发
4个文件已修改
58 ■■■■ 已修改文件
controller/captureCtl.go 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controller/subscribeCtl.go 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
vo/constant.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
vo/subscribe.go 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controller/captureCtl.go
@@ -41,13 +41,13 @@
    // 如果开启了下级, 身份应该是消息代理, 不再转发到服务器
    face := req.FaceListObject.FaceObject[0]
    if config.ClientConf.Enable && config.ServeConf.Role == "agent" {
        a.Repository.VIIDMsgForward(&req)
        go a.Repository.VIIDMsgForward(&req)
    } else if config.ServeConf.Role == "cascade" {
        logger.Debug("Receive new message, Id:%s Ip:%s faceId:%s, LeftTopX:%d, appearTime:%s", c.RemoteIP(), face.DeviceID, face.FaceID, face.LeftTopX, face.FaceAppearTime)
        service.AddFaceCapture(&face)
        go service.AddFaceCapture(&face)
    } else {
        logger.Debug("Receive new message, Id:%s Ip:%s faceId:%s, LeftTopX:%d, appearTime:%s", c.RemoteIP(), face.DeviceID, face.FaceID, face.LeftTopX, face.FaceAppearTime)
        a.Repository.FaceForward(req.FaceListObject.FaceObject)
        go a.Repository.FaceForward(req.FaceListObject.FaceObject)
    }
    // 设备保活
controller/subscribeCtl.go
@@ -1,7 +1,7 @@
package controller
import (
    "fmt"
    "gat1400Exchange/pkg/logger"
    "gat1400Exchange/repository"
    "gat1400Exchange/vo"
    "net/http"
@@ -13,12 +13,14 @@
type SubscribeController struct {
    Repository repository.SubscribeRepository
    Srv        repository.CaptureRepository
}
// 构造函数
func NewSubscribeController() SubscribeController {
    svr := repository.NewSubscribeRepository()
    controller := SubscribeController{svr}
    svr1 := repository.NewCaptureRepository()
    controller := SubscribeController{svr, svr1}
    return controller
}
@@ -101,11 +103,28 @@
}
func (s SubscribeController) Notifications(c *gin.Context) {
    data, err := c.GetRawData()
    if err != nil {
    var rsp vo.ResponseStatusList
    var req vo.RequestSubscribeNotificationBind
    if err := c.BindJSON(&req); err != nil {
        c.JSON(http.StatusBadRequest, gin.H{"ResponseStatusListObject": rsp})
        return
    }
    fmt.Println("Notifications:", string(data))
    c.JSON(http.StatusOK, gin.H{"ResponseStatusListObject": ""})
    logger.Debug("Receive notifications: %+v", req)
    for _, msg := range req.SubscribeNotificationListObject.SubscribeNotificationObject {
        rsp.ResponseStatusObject = append(rsp.ResponseStatusObject, vo.ResponseStatus{
            RequestURL:   c.FullPath(),
            StatusCode:   vo.StatusSuccess,
            StatusString: vo.StatusString[vo.StatusSuccess],
            Id:           msg.SubscribeID,
            LocalTime:    time.Now().Format("20060102150405"),
        })
        // 转发
        go s.Srv.FaceForward(msg.FaceObjectList.FaceObject)
    }
    c.Header("Content-Type", "application/VIID+json;charset=UTF-8")
    c.JSON(http.StatusOK, gin.H{"ResponseStatusListObject": rsp})
}
vo/constant.go
@@ -15,7 +15,7 @@
)
var StatusString = [10]string{
    StatusSuccess:            "正常",
    StatusSuccess:            "成功",
    StatusOtherError:         "其他未知错误",
    StatusDeviceBusy:         "设备忙",
    StatusDeviceError:        "设备错",
vo/subscribe.go
@@ -56,6 +56,12 @@
    } `json:"SubscribeNotificationListObject"`
}
type RequestSubscribeNotificationBind struct {
    SubscribeNotificationListObject struct {
        SubscribeNotificationObject []Notification `json:"SubscribeNotificationObject"`
    } `json:"SubscribeNotificationListObject"`
}
type DeviceNotification struct {
    NotificationID   string
    SubscribeID      string
@@ -75,3 +81,14 @@
    ExecuteOperation int
    FaceObjectList   NotificationFaceList
}
type Notification struct {
    NotificationID   string
    SubscribeID      string
    Title            string
    TriggerTime      string
    InfoIDs          string
    ExecuteOperation int
    DeviceList       NotificationApeList
    FaceObjectList   NotificationFaceList
}