From 539a78196da60eb97cf7057c5c85dfaa9b240741 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期五, 11 十月 2024 16:21:32 +0800
Subject: [PATCH] 添加A3平层传感器数据获取方式

---
 repository/captureRepo.go |   85 +++++++++++++++++++++++++++++++-----------
 1 files changed, 63 insertions(+), 22 deletions(-)

diff --git a/repository/captureRepo.go b/repository/captureRepo.go
index 5c86f0f..bb82cf5 100644
--- a/repository/captureRepo.go
+++ b/repository/captureRepo.go
@@ -10,6 +10,7 @@
 	"gat1400Exchange/models"
 	"gat1400Exchange/pkg"
 	"gat1400Exchange/pkg/logger"
+	"gat1400Exchange/service"
 	"gat1400Exchange/util"
 	"gat1400Exchange/vo"
 )
@@ -92,15 +93,9 @@
 			}
 
 			// 澶勭悊姊帶濉啓鐨勬ゼ灞備俊鎭� 鏆傛椂浣跨敤otherFeature瀛楁
-			if face.OtherFeature != "" {
-				pd.CameraFloor, _ = pkg.RestoreFloor(face.OtherFeature)
+			if face.OtherFeature != "" && pd.CameraFloor == "" {
+				pd.Direction, pd.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)
 			if err != nil {
@@ -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)
@@ -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,31 @@
 		faceAppearTime = time.Now()
 	}
 
-	if config.ServeConf.Role == "server" {
+	// 鍒ゆ柇鏄惁闇�瑕佸尮閰嶆ゼ灞�
+	if config.NVCSConf.Model != "" {
 		// 鍖归厤妤煎眰
 		var devPos models.Positions
 		_ = devPos.FindDevicePosition(deviceId, faceAppearTime.Unix()+5) // 鍔�5绉掔數姊叧闂ㄧ殑鏃堕棿
 
 		floor = devPos.Pos
+
+		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 = ""
+				}
+
+				break
+			}
+
+			time.Sleep(1 * time.Second)
+		}
 	}
 
 	pd.PicMaxImages = append(pd.PicMaxImages, bgImgBytes)
@@ -235,6 +250,7 @@
 	pd.DataSource = "camera"
 	pd.CameraFloor = floor
 	pd.CameraId = deviceId
+	pd.Direction = runDir
 
 	return pd
 }
@@ -262,17 +278,38 @@
 			faceAppearTime = time.Now()
 		}
 
+		var floor, runDir string
 		var devPos models.Positions
 		_ = devPos.FindPositionByTime(faceAppearTime.Unix() + 5) // 鍔�5绉掔數姊叧闂ㄧ殑鏃堕棿
 		if devPos.Pos == "" {
 			devPos.Pos = "1F"
 		}
 
-		for idx, face := range msg.FaceListObject.FaceObject {
-			msg.FaceListObject.FaceObject[idx].OtherFeature, _ = pkg.ParseFloor(devPos.Pos)
-			if config.ClientConf.AddFloorToFaceId {
-				msg.FaceListObject.FaceObject[idx].FaceID = pkg.GenerateFaceIdContainFloor(face.FaceID, devPos.Pos)
+		floor = devPos.Pos
+
+		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"
+				}
+
+				break
 			}
+
+			time.Sleep(1 * time.Second)
+		}
+
+		for idx, _ := range msg.FaceListObject.FaceObject {
+			msg.FaceListObject.FaceObject[idx].OtherFeature, _ = pkg.ParseFloor(runDir, floor)
+			//if config.ClientConf.AddFloorToFaceId {
+			//	msg.FaceListObject.FaceObject[idx].FaceID = pkg.GenerateFaceIdContainFloor(face.FaceID, devPos.Pos)
+			//}
 		}
 
 	}
@@ -302,11 +339,11 @@
 		devPos.Pos = "1F"
 	}
 
-	for idx, v := range msg.PersonListObject.PersonObject {
+	for idx, _ := 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)
-		}
+		//if config.ClientConf.AddFloorToFaceId {
+		//	msg.PersonListObject.PersonObject[idx].PersonID = pkg.GenerateFaceIdContainFloor(v.PersonID, devPos.Pos)
+		//}
 	}
 
 	b, _ := json.Marshal(msg)
@@ -325,7 +362,11 @@
 		MsgId: msgId,
 	}
 
+	logger.Debug("Pub record message %s, %s", deviceId, msgId)
 	body, _ := json.Marshal(&msg)
 
-	util.HttpPost(config.ForwardConf.RecordServer, nil, body)
+	_, err := util.HttpPost(config.ForwardConf.RecordServer, nil, body)
+	if err != nil {
+		logger.Warn(err.Error())
+	}
 }

--
Gitblit v1.8.0