zhangzengfei
2024-04-29 fe763eba27addfe615d2c107b8984484baef9a23
repository/captureRepo.go
@@ -3,6 +3,7 @@
import (
   "encoding/base64"
   "encoding/json"
   "gat1400Exchange/client"
   "time"
   "gat1400Exchange/config"
@@ -77,6 +78,13 @@
            return
         }
         // 部署在服务端的1400代理, 仅接收1400信息, 楼层信息暂存在oherFeature字段
         if config.ServeConf.Role == "proxy" {
            if face.OtherFeature != "" {
               pd.CameraFloor = face.OtherFeature
            }
         }
         payload, err := json.Marshal(pd)
         if err != nil {
            logger.Warn("Marshal error, %s", err.Error())
@@ -85,7 +93,7 @@
         if !util.SendData(payload, config.ForwardConf.SyncServer) {
            cacheItem, _ := json.Marshal(pd)
            c.CacheData(cacheItem)
            c.CacheData(cacheItem, "basic")
            logger.Warn("The data forwarding failed, adding to local cache.")
         } else {
            logger.Debug("The data forwarding successful. deviceId:%s", deviceId)
@@ -152,6 +160,15 @@
func (c CaptureRepository) PackPushDataV2(deviceId, faceId, appearTime string, bgImgBytes, faceImgBytes []byte) *vo.PushDataInfoV2 {
   var pd = new(vo.PushDataInfoV2)
   var floor string
   faceAppearTime, err := time.ParseInLocation("20060102150405", appearTime, time.Local)
   if err != nil {
      logger.Warn("Parse face appear time error, %s", err.Error())
      faceAppearTime = time.Now()
   }
   if config.ServeConf.Role == "server" {
   var device models.Device
   if err := device.FindById(deviceId); err != nil {
@@ -160,16 +177,13 @@
   }
   // 匹配楼层
   faceAppearTime, err := time.ParseInLocation("20060102150405", appearTime, time.Local)
   if err != nil {
      logger.Warn("Parse face appear time error, %s", err.Error())
      faceAppearTime = time.Now()
   }
   var devPos models.Positions
   _ = devPos.FindDevicePosition(deviceId, faceAppearTime.Unix()+5) // 加5秒电梯关门的时间
   if devPos.Pos == "" {
      devPos.Pos = device.Floor
      }
      floor = devPos.Pos
   }
   pd.PicMaxImages = append(pd.PicMaxImages, bgImgBytes)
@@ -181,14 +195,15 @@
   pd.PicId = faceId
   pd.PicDate = faceAppearTime.Format("2006-01-02 15:04:05")
   pd.DataSource = "camera"
   pd.CameraFloor = devPos.Pos
   pd.CameraFloor = floor
   pd.CameraId = deviceId
   return pd
}
func (c CaptureRepository) CacheData(payload []byte) {
func (c CaptureRepository) CacheData(payload []byte, msgType string) {
   var cacheItem = models.Cache{
      Type:       msgType,
      Data:       string(payload),
      CreateTime: time.Now().Unix(),
      Retry:      0,
@@ -196,3 +211,32 @@
   cacheItem.Save()
}
func (c CaptureRepository) MsgForward(msg *vo.RequestFaceList) {
   faceInfo := msg.FaceListObject.FaceObject[0]
   // 匹配楼层
   faceAppearTime, err := time.ParseInLocation("20060102150405", faceInfo.FaceAppearTime, time.Local)
   if err != nil {
      logger.Warn("Parse face appear time error, %s", err.Error())
      faceAppearTime = time.Now()
   }
   var devPos models.Positions
   _ = devPos.FindPositionByTime(faceAppearTime.Unix() + 5) // 加5秒电梯关门的时间
   if devPos.Pos == "" {
      devPos.Pos = "1F"
   }
   for idx, _ := range msg.FaceListObject.FaceObject {
      msg.FaceListObject.FaceObject[idx].OtherFeature = devPos.Pos
   }
   b, _ := json.Marshal(msg)
   if client.FaceCapture(b) != vo.StatusSuccess {
      cacheItem, _ := json.Marshal(msg)
      c.CacheData(cacheItem, "1400")
      logger.Warn("The data forwarding failed, adding to local cache.")
   }
   return
}