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 |   79 ++++++++++++---------------------------
 1 files changed, 24 insertions(+), 55 deletions(-)

diff --git a/repository/captureRepo.go b/repository/captureRepo.go
index bb82cf5..87ae032 100644
--- a/repository/captureRepo.go
+++ b/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())
 	}

--
Gitblit v1.8.0