From 2c77f012601b7788dc58b0c9fd99aad587983b0d Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期二, 22 十月 2024 21:20:19 +0800
Subject: [PATCH] 完善楼层相关操作
---
repository/captureRepo.go | 126 +++++++++++++++++++++++++----------------
1 files changed, 76 insertions(+), 50 deletions(-)
diff --git a/repository/captureRepo.go b/repository/captureRepo.go
index e05a343..87ae032 100644
--- a/repository/captureRepo.go
+++ b/repository/captureRepo.go
@@ -8,6 +8,7 @@
"gat1400Exchange/client"
"gat1400Exchange/config"
"gat1400Exchange/models"
+ "gat1400Exchange/nvcs"
"gat1400Exchange/pkg"
"gat1400Exchange/pkg/logger"
"gat1400Exchange/util"
@@ -50,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 {
@@ -86,30 +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 = face.OtherFeature
+ if face.OtherFeature != "" && pushData.CameraFloor == "" {
+ pushData.Direction, pushData.CameraFloor, _ = pkg.RestoreFloor(face.OtherFeature)
}
- // 灏濊瘯浠巉aceId鎻愬彇妤煎眰
- if pd.CameraFloor == "" && config.ClientConf.AddFloorToFaceId {
- pd.CameraFloor, _ = pkg.ParseFloorFromId(face.FaceID)
- }
- //logger.Debug("device %s, CameraFloor:%s", deviceId, pd.CameraFloor)
-
- 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 {
@@ -150,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 {
@@ -181,10 +176,10 @@
pd.CameraFloor = v.BehaviorDescription
}
- // 灏濊瘯浠巉aceId鎻愬彇妤煎眰
- if pd.CameraFloor == "" && config.ClientConf.AddFloorToFaceId {
- pd.CameraFloor, _ = pkg.ParseFloorFromId(v.PersonID)
- }
+ //// 灏濊瘯浠巉aceId鎻愬彇妤煎眰
+ //if pd.CameraFloor == "" && config.ClientConf.AddFloorToFaceId {
+ // pd.CameraFloor, _ = pkg.ParseFloorFromId(v.PersonID)
+ //}
//logger.Debug("device %s, CameraFloor:%s", deviceId, pd.CameraFloor)
payload, err := json.Marshal(pd)
@@ -193,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.")
@@ -209,6 +204,7 @@
func (c CaptureRepository) PackPushDataV2(deviceId, faceId, appearTime string, bgImgBytes, faceImgBytes []byte) *vo.PushDataInfoV2 {
var pd = new(vo.PushDataInfoV2)
var floor string
+ var runDir string
faceAppearTime, err := time.ParseInLocation("20060102150405", appearTime, time.Local)
if err != nil {
@@ -216,12 +212,19 @@
faceAppearTime = time.Now()
}
- if config.ServeConf.Role == "server" {
- // 鍖归厤妤煎眰
- var devPos models.Positions
- _ = devPos.FindDevicePosition(deviceId, faceAppearTime.Unix()+5) // 鍔�5绉掔數姊叧闂ㄧ殑鏃堕棿
+ // 鍒ゆ柇鏄惁闇�瑕佸尮閰嶆ゼ灞�
+ if config.NVCSConf.Model != "" {
+ runState := nvcs.FindPositionByTime(faceAppearTime.Unix() + 3) // 鍔�3绉掔數姊叧闂ㄧ殑鏃堕棿
+ floor = runState.Floor
- floor = devPos.Pos
+ for i := 0; i < config.NVCSConf.WaitRunTime; i++ {
+ if runState = nvcs.CurrentRunState(); runState.Floor != "" && runState.Floor != floor {
+ runDir = pkg.CheckDirection(floor, runState.Floor)
+ break
+ }
+
+ time.Sleep(1 * time.Second)
+ }
}
pd.PicMaxImages = append(pd.PicMaxImages, bgImgBytes)
@@ -235,6 +238,7 @@
pd.DataSource = "camera"
pd.CameraFloor = floor
pd.CameraId = deviceId
+ pd.Direction = runDir
return pd
}
@@ -252,23 +256,34 @@
func (c CaptureRepository) VIIDFaceMsgForward(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 floor, runDir string
- var devPos models.Positions
- _ = devPos.FindPositionByTime(faceAppearTime.Unix() + 5) // 鍔�5绉掔數姊叧闂ㄧ殑鏃堕棿
- if devPos.Pos == "" {
- devPos.Pos = "1F"
- }
+ // 鍒ゆ柇鏄惁寮�鍚簡姊帶
+ if config.NVCSConf.Model != "" {
+ // 鍖归厤妤煎眰
+ 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()
+ }
- for idx, face := range msg.FaceListObject.FaceObject {
- msg.FaceListObject.FaceObject[idx].OtherFeature = devPos.Pos
- if config.ClientConf.AddFloorToFaceId {
- msg.FaceListObject.FaceObject[idx].FaceID = pkg.GenerateFaceIdContainFloor(face.FaceID, devPos.Pos)
+ runState := nvcs.FindPositionByTime(faceAppearTime.Unix() + 3) // 鍔�3绉掔數姊叧闂ㄧ殑鏃堕棿
+ floor = runState.Floor
+
+ for i := 0; i < config.NVCSConf.WaitRunTime; i++ {
+ if runState = nvcs.CurrentRunState(); runState.Floor != "" && runState.Floor != floor {
+ runDir = pkg.CheckDirection(floor, runState.Floor)
+ break
+ }
+
+ time.Sleep(1 * time.Second)
+ }
+
+ for idx, _ := range msg.FaceListObject.FaceObject {
+ msg.FaceListObject.FaceObject[idx].OtherFeature, _ = pkg.BuildFloorString(runDir, floor)
+ //if config.ClientConf.AddFloorToFaceId {
+ // msg.FaceListObject.FaceObject[idx].FaceID = pkg.GenerateFaceIdContainFloor(face.FaceID, devPos.Pos)
+ //}
}
}
@@ -291,17 +306,13 @@
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, v := range msg.PersonListObject.PersonObject {
- msg.PersonListObject.PersonObject[idx].BehaviorDescription = devPos.Pos
- if config.ClientConf.AddFloorToFaceId {
- msg.PersonListObject.PersonObject[idx].PersonID = pkg.GenerateFaceIdContainFloor(v.PersonID, devPos.Pos)
- }
+ for idx, _ := range msg.PersonListObject.PersonObject {
+ msg.PersonListObject.PersonObject[idx].BehaviorDescription = runState.Floor
+ //if config.ClientConf.AddFloorToFaceId {
+ // msg.PersonListObject.PersonObject[idx].PersonID = pkg.GenerateFaceIdContainFloor(v.PersonID, devPos.Pos)
+ //}
}
b, _ := json.Marshal(msg)
@@ -313,3 +324,18 @@
return
}
+
+func (c CaptureRepository) PubRecordMessage(deviceId, msgId string) {
+ var msg = vo.RecordMsg{
+ CamId: deviceId,
+ MsgId: msgId,
+ }
+
+ logger.Debug("Pub record message %s, %s", deviceId, msgId)
+ body, _ := json.Marshal(&msg)
+
+ _, err := pkg.HttpPost(config.ForwardConf.RecordServer, nil, body)
+ if err != nil {
+ logger.Warn(err.Error())
+ }
+}
--
Gitblit v1.8.0