zhangzengfei
2024-05-17 2000b36f214b2c8edcec0d812e30a6db85a46482
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package controller
 
import (
    "gat1400Exchange/config"
    "gat1400Exchange/service"
    "net/http"
    "time"
 
    "gat1400Exchange/pkg/logger"
    "gat1400Exchange/repository"
    "gat1400Exchange/vo"
 
    "github.com/gin-gonic/gin"
)
 
type CaptureController struct {
    Repository repository.CaptureRepository
}
 
// 构造函数
func NewCaptureController() CaptureController {
    svr := repository.NewCaptureRepository()
    controller := CaptureController{Repository: svr}
 
    return controller
}
 
// 批量提交人脸
func (a CaptureController) Faces(c *gin.Context) {
    var req vo.RequestFaceList
    if err := c.BindJSON(&req); err != nil {
        c.AbortWithStatus(http.StatusBadRequest)
        return
    }
 
    if len(req.FaceListObject.FaceObject) == 0 {
        c.AbortWithStatus(http.StatusBadRequest)
        return
    }
 
    face := req.FaceListObject.FaceObject[0]
    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)
 
    // 如果开启了下级, 身份应该是消息代理, 不再转发到服务器
    if config.ClientConf.Enable && config.ServeConf.Role == "agent" {
        go a.Repository.VIIDMsgForward(&req)
    } else if config.ServeConf.Role == "cascade" {
        go service.AddFaceNotification(&face)
    }
 
    if config.ForwardConf.SyncServer != "" {
        go a.Repository.FaceForward(req.FaceListObject.FaceObject)
    }
 
    // 设备保活
    service.KeepDeviceAlive(face.DeviceID)
 
    rspMsg := vo.ResponseStatus{
        RequestURL:   c.FullPath(),
        StatusCode:   vo.StatusSuccess,
        StatusString: vo.StatusString[vo.StatusSuccess],
        Id:           face.FaceID,
        LocalTime:    time.Now().Format("20060102150405"),
    }
 
    c.JSON(http.StatusOK, gin.H{"ResponseStatusObject": rspMsg})
}
func (a CaptureController) VideoLabels(c *gin.Context) {
    var req vo.RequestVideoLabelList
    if err := c.BindJSON(&req); err != nil {
        c.AbortWithStatus(http.StatusBadRequest)
        return
    }
 
    if len(req.VideoLabelListObject.VideoLabelObject) == 0 {
        c.AbortWithStatus(http.StatusBadRequest)
        return
    }
 
    videoLabel := req.VideoLabelListObject.VideoLabelObject[0]
    logger.Debug("Receive new message, Id:%s Ip:%s faceId:%s, LeftTopX:%d, appearTime:%s", c.RemoteIP(), videoLabel.VideoLabelID)
 
    // 转人脸消息
    var face vo.FaceObject
    face.FaceID = videoLabel.VideoLabelID
    face.InfoKind = 1
    face.SourceID = videoLabel.VideoImageID
    face.SourceID = videoLabel.VideoImageID
    face.LocationMarkTime = videoLabel.CreateTimeAbs
    face.FaceAppearTime = videoLabel.BehaviorAnalysisObject.BehaviorBeginTime
    face.FaceDisAppearTime = videoLabel.BehaviorAnalysisObject.BehaviorEndTime
 
    for idx, _ := range videoLabel.SubImageList.SubImageInfoObject {
        videoLabel.SubImageList.SubImageInfoObject[idx].EventSort = 10
    }
 
    face.SubImageList.SubImageInfoObject = videoLabel.SubImageList.SubImageInfoObject
 
    // 如果开启了下级, 身份应该是消息代理, 不再转发到服务器
    if config.ClientConf.Enable && config.ServeConf.Role == "agent" {
        //go a.Repository.VIIDMsgForward(&req)
    } else if config.ServeConf.Role == "cascade" {
        go service.AddFaceNotification(&face)
    }
 
    if config.ForwardConf.SyncServer != "" {
        go a.Repository.FaceForward([]vo.FaceObject{face})
    }
 
    // 设备保活
    service.KeepDeviceAlive(videoLabel.IVADeviceID)
 
    rspMsg := vo.ResponseStatus{
        RequestURL:   c.FullPath(),
        StatusCode:   vo.StatusSuccess,
        StatusString: vo.StatusString[vo.StatusSuccess],
        Id:           videoLabel.VideoLabelID,
        LocalTime:    time.Now().Format("20060102150405"),
    }
 
    c.JSON(http.StatusOK, gin.H{"ResponseStatusObject": rspMsg})
}