zhangzengfei
2024-10-22 2c77f012601b7788dc58b0c9fd99aad587983b0d
repository/captureRepo.go
@@ -8,9 +8,9 @@
   "gat1400Exchange/client"
   "gat1400Exchange/config"
   "gat1400Exchange/models"
   "gat1400Exchange/nvcs"
   "gat1400Exchange/pkg"
   "gat1400Exchange/pkg/logger"
   "gat1400Exchange/service"
   "gat1400Exchange/util"
   "gat1400Exchange/vo"
)
@@ -51,7 +51,7 @@
               bgImageStr = image.Data
            }
         } else if image.StoragePath != "" {
            imgData, err := util.ImageDownload(image.StoragePath, nil)
            imgData, err := pkg.ImageDownload(image.StoragePath, nil)
            if err != nil {
               logger.Warn("Image download failure, %s", err.Error())
            } else {
@@ -87,24 +87,24 @@
      // 转发图像
      logger.Debug("Prepare forward image, deviceId:%s, bgImage len:%d, smImage len:%d server:%s", deviceId, len(bgImageBytes), len(faceImageBytes), config.ForwardConf.SyncServer)
      if deviceId != "" && bgImageStr != "" && config.ForwardConf.SyncServer != "" {
         pd := c.PackPushDataV2(deviceId, faceId, face.FaceAppearTime, bgImageBytes, faceImageBytes)
         if pd == nil {
         pushData := c.PackPushDataV2(deviceId, faceId, face.FaceAppearTime, bgImageBytes, faceImageBytes)
         if pushData == nil {
            return
         }
         // 处理梯控填写的楼层信息 暂时使用otherFeature字段
         if face.OtherFeature != "" && pd.CameraFloor == "" {
            pd.Direction, pd.CameraFloor, _ = pkg.RestoreFloor(face.OtherFeature)
         if face.OtherFeature != "" && pushData.CameraFloor == "" {
            pushData.Direction, pushData.CameraFloor, _ = pkg.RestoreFloor(face.OtherFeature)
         }
         payload, err := json.Marshal(pd)
         payload, err := json.Marshal(pushData)
         if err != nil {
            logger.Warn("Marshal error, %s", err.Error())
            return
         }
         if !util.SendData(payload, config.ForwardConf.SyncServer) {
            cacheItem, _ := json.Marshal(pd)
         if !pkg.SendData(payload, config.ForwardConf.SyncServer) {
            cacheItem, _ := json.Marshal(pushData)
            c.CacheData(cacheItem, "basic")
            logger.Warn("The data forwarding failed, adding to local cache.")
         } else {
@@ -145,7 +145,7 @@
               bgImageStr = image.Data
            }
         } else if image.StoragePath != "" {
            imgData, err := util.ImageDownload(image.StoragePath, nil)
            imgData, err := pkg.ImageDownload(image.StoragePath, nil)
            if err != nil {
               logger.Warn("Image download failure, %s", err.Error())
            } else {
@@ -188,7 +188,7 @@
            return
         }
         if !util.SendData(payload, config.ForwardConf.SyncServer) {
         if !pkg.SendData(payload, config.ForwardConf.SyncServer) {
            cacheItem, _ := json.Marshal(pd)
            c.CacheData(cacheItem, "basic")
            logger.Warn("The data forwarding failed, adding to local cache.")
@@ -214,24 +214,12 @@
   // 判断是否需要匹配楼层
   if config.NVCSConf.Model != "" {
      // 匹配楼层
      var devPos models.Positions
      _ = devPos.FindDevicePosition(deviceId, faceAppearTime.Unix()+5) // 加5秒电梯关门的时间
      floor = devPos.Pos
      runState := nvcs.FindPositionByTime(faceAppearTime.Unix() + 3) // 加3秒电梯关门的时间
      floor = runState.Floor
      for i := 0; i < config.NVCSConf.WaitRunTime; i++ {
         var dbPos models.Positions
         if err := dbPos.FindMovePosition(faceAppearTime.Unix()+5, floor); err == nil {
            switch dbPos.RunDir {
            case service.RunUp:
               runDir = "in"
            case service.RunDown:
               runDir = "out"
            case service.RunStop:
               runDir = ""
            }
         if runState = nvcs.CurrentRunState(); runState.Floor != "" && runState.Floor != floor {
            runDir = pkg.CheckDirection(floor, runState.Floor)
            break
         }
@@ -268,6 +256,7 @@
func (c CaptureRepository) VIIDFaceMsgForward(msg *vo.RequestFaceList) {
   faceInfo := msg.FaceListObject.FaceObject[0]
   var floor, runDir string
   // 判断是否开启了梯控
   if config.NVCSConf.Model != "" {
@@ -278,27 +267,12 @@
         faceAppearTime = time.Now()
      }
      var floor, runDir string
      var devPos models.Positions
      _ = devPos.FindPositionByTime(faceAppearTime.Unix() + 5) // 加5秒电梯关门的时间
      if devPos.Pos == "" {
         devPos.Pos = "1F"
      }
      floor = devPos.Pos
      runState := nvcs.FindPositionByTime(faceAppearTime.Unix() + 3) // 加3秒电梯关门的时间
      floor = runState.Floor
      for i := 0; i < config.NVCSConf.WaitRunTime; i++ {
         var dbPos models.Positions
         if err := dbPos.FindMovePosition(faceAppearTime.Unix()+5, floor); err == nil {
            switch dbPos.RunDir {
            case service.RunUp:
               runDir = "1"
            case service.RunDown:
               runDir = "2"
            case service.RunStop:
               runDir = "0"
            }
         if runState = nvcs.CurrentRunState(); runState.Floor != "" && runState.Floor != floor {
            runDir = pkg.CheckDirection(floor, runState.Floor)
            break
         }
@@ -306,12 +280,11 @@
      }
      for idx, _ := range msg.FaceListObject.FaceObject {
         msg.FaceListObject.FaceObject[idx].OtherFeature, _ = pkg.ParseFloor(runDir, floor)
         msg.FaceListObject.FaceObject[idx].OtherFeature, _ = pkg.BuildFloorString(runDir, floor)
         //if config.ClientConf.AddFloorToFaceId {
         //   msg.FaceListObject.FaceObject[idx].FaceID = pkg.GenerateFaceIdContainFloor(face.FaceID, devPos.Pos)
         //}
      }
   }
   b, _ := json.Marshal(msg)
@@ -333,14 +306,10 @@
      appearTime = time.Now()
   }
   var devPos models.Positions
   _ = devPos.FindPositionByTime(appearTime.Unix() + 5) // 加5秒电梯关门的时间
   if devPos.Pos == "" {
      devPos.Pos = "1F"
   }
   runState := nvcs.FindPositionByTime(appearTime.Unix() + 3) // 加3秒电梯关门的时间
   for idx, _ := range msg.PersonListObject.PersonObject {
      msg.PersonListObject.PersonObject[idx].BehaviorDescription = devPos.Pos
      msg.PersonListObject.PersonObject[idx].BehaviorDescription = runState.Floor
      //if config.ClientConf.AddFloorToFaceId {
      //   msg.PersonListObject.PersonObject[idx].PersonID = pkg.GenerateFaceIdContainFloor(v.PersonID, devPos.Pos)
      //}
@@ -365,7 +334,7 @@
   logger.Debug("Pub record message %s, %s", deviceId, msgId)
   body, _ := json.Marshal(&msg)
   _, err := util.HttpPost(config.ForwardConf.RecordServer, nil, body)
   _, err := pkg.HttpPost(config.ForwardConf.RecordServer, nil, body)
   if err != nil {
      logger.Warn(err.Error())
   }