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] if config.ClientConf.Enable && config.ServeConf.Role == "agent" { 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) } 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) } // 设备保活 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}) }