From 2c77f012601b7788dc58b0c9fd99aad587983b0d Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期二, 22 十月 2024 21:20:19 +0800
Subject: [PATCH] 完善楼层相关操作

---
 client/system.go          |    4 
 nvcs/a2.go                |    5 -
 pkg/floor.go              |   40 ++++++++++++-
 controller/captureCtl.go  |    3 
 service/device.go         |    4 
 service/resend.go         |    4 
 client/faces.go           |    6 +-
 repository/captureRepo.go |   52 ++++------------
 client/notify.go          |   10 +-
 pkg/http.go               |    2 
 pkg/file.go               |    2 
 11 files changed, 69 insertions(+), 63 deletions(-)

diff --git a/client/faces.go b/client/faces.go
index 42e3827..690e92c 100644
--- a/client/faces.go
+++ b/client/faces.go
@@ -2,11 +2,11 @@
 
 import (
 	"fmt"
+	"gat1400Exchange/pkg"
 
 	"encoding/json"
 	"gat1400Exchange/config"
 	"gat1400Exchange/pkg/logger"
-	"gat1400Exchange/util"
 	"gat1400Exchange/vo"
 )
 
@@ -21,7 +21,7 @@
 	}
 
 	url := fmt.Sprintf("%s://%s:%s%s", config.ClientConf.Proto, config.ClientConf.ServerAddr, config.ClientConf.ServerPort, FacesUrI)
-	rsp, err := util.HttpPost(url, headers, msg)
+	rsp, err := pkg.HttpPost(url, headers, msg)
 	if err != nil {
 		logger.Warn("Post faces failed, %s", err.Error())
 		return vo.StatusOtherError
@@ -44,7 +44,7 @@
 	}
 
 	url := fmt.Sprintf("%s://%s:%s%s", config.ClientConf.Proto, config.ClientConf.ServerAddr, config.ClientConf.ServerPort, PersonsUrI)
-	rsp, err := util.HttpPost(url, headers, msg)
+	rsp, err := pkg.HttpPost(url, headers, msg)
 	if err != nil {
 		logger.Warn("Post person failed, %s", err.Error())
 		return vo.StatusOtherError
diff --git a/client/notify.go b/client/notify.go
index 66e9584..15cc0ac 100644
--- a/client/notify.go
+++ b/client/notify.go
@@ -2,8 +2,8 @@
 
 import (
 	"encoding/json"
+	"gat1400Exchange/pkg"
 	"gat1400Exchange/pkg/logger"
-	"gat1400Exchange/util"
 	"gat1400Exchange/vo"
 )
 
@@ -12,7 +12,7 @@
 		return clientStatus
 	}
 
-	rsp, err := util.HttpPost(url, headers, msg)
+	rsp, err := pkg.HttpPost(url, headers, msg)
 	if err != nil {
 		logger.Warn("Post notification failed, %s", err.Error())
 		return vo.StatusOtherError
@@ -35,7 +35,7 @@
 	//	return clientStatus
 	//}
 
-	rsp, err := util.HttpPost(url, headers, msg)
+	rsp, err := pkg.HttpPost(url, headers, msg)
 	if err != nil {
 		logger.Warn("Post subscribe failed, %s", err.Error())
 		return vo.StatusOtherError
@@ -55,7 +55,7 @@
 }
 
 func UpdateSubscribe(url string, msg []byte) int {
-	rsp, err := util.HttpPut(url, headers, msg)
+	rsp, err := pkg.HttpPut(url, headers, msg)
 	if err != nil {
 		logger.Warn("Put subscribe failed, %s", err.Error())
 		return vo.StatusOtherError
@@ -75,7 +75,7 @@
 }
 
 func GetSubscribes(url string) ([]byte, error) {
-	rsp, err := util.HttpGet(url, headers)
+	rsp, err := pkg.HttpGet(url, headers)
 	if err != nil {
 		logger.Warn("Get subscribe failed, %s", err.Error())
 	}
diff --git a/client/system.go b/client/system.go
index b2e540b..52b4d68 100644
--- a/client/system.go
+++ b/client/system.go
@@ -3,11 +3,11 @@
 import (
 	"encoding/json"
 	"fmt"
+	"gat1400Exchange/pkg"
 	"io/ioutil"
 
 	"gat1400Exchange/config"
 	"gat1400Exchange/pkg/logger"
-	"gat1400Exchange/util"
 	"gat1400Exchange/vo"
 
 	dac "github.com/xinsnake/go-http-digest-auth-client"
@@ -91,7 +91,7 @@
 
 	url := fmt.Sprintf("%s://%s:%s%s", config.ClientConf.Proto, config.ClientConf.ServerAddr, config.ClientConf.ServerPort, KeepaliveUrI)
 	b, _ := json.Marshal(body)
-	rsp, err := util.HttpPost(url, headers, b)
+	rsp, err := pkg.HttpPost(url, headers, b)
 	if err != nil {
 		logger.Warn("Keepalive request failed, %s", err.Error())
 		return vo.StatusOtherError
diff --git a/controller/captureCtl.go b/controller/captureCtl.go
index 79efc0f..7727a24 100644
--- a/controller/captureCtl.go
+++ b/controller/captureCtl.go
@@ -14,7 +14,6 @@
 	"gat1400Exchange/pkg/logger"
 	"gat1400Exchange/repository"
 	"gat1400Exchange/service"
-	"gat1400Exchange/util"
 	"gat1400Exchange/vo"
 
 	"github.com/gin-gonic/gin"
@@ -63,7 +62,7 @@
 
 			today := time.Now().Format("2006-01-02")
 			imagePath := path.Join(config.LogConf.Path, "gat1400_face_images", today, img.ImageID+".jpeg")
-			err = util.WriteToFile(imagePath, imageBytes)
+			err = pkg.WriteToFile(imagePath, imageBytes)
 			if err == nil {
 				face.SubImageList.SubImageInfoObject[idx].Data = ""
 				face.SubImageList.SubImageInfoObject[idx].StoragePath = config.ImageConf.ImageUriPrefix + "/" + today + "/" + img.ImageID + ".jpeg"
diff --git a/nvcs/a2.go b/nvcs/a2.go
index 2ffd4fd..0ecd38f 100644
--- a/nvcs/a2.go
+++ b/nvcs/a2.go
@@ -3,14 +3,13 @@
 import (
 	"encoding/json"
 	"fmt"
+	"gat1400Exchange/pkg"
 	"net/http"
 	"strings"
 	"time"
 
 	"gat1400Exchange/config"
 	"gat1400Exchange/pkg/logger"
-	"gat1400Exchange/util"
-
 	"github.com/gin-gonic/gin"
 )
 
@@ -58,7 +57,7 @@
 		"Cookie": "eyJuYW1lIjoiYWRtaW4iLCAicGFzZCI6ImFkbWluMTIzIn0=",
 	}
 
-	rsp, err := util.HttpPost(url, header, payload)
+	rsp, err := pkg.HttpPost(url, header, payload)
 	if err != nil {
 		logger.Warn("Get A2 floor data failure,%s", err.Error())
 		return
diff --git a/util/file.go b/pkg/file.go
similarity index 97%
rename from util/file.go
rename to pkg/file.go
index 875628e..672d91f 100644
--- a/util/file.go
+++ b/pkg/file.go
@@ -1,4 +1,4 @@
-package util
+package pkg
 
 import (
 	"fmt"
diff --git a/pkg/floor.go b/pkg/floor.go
index ad14c3b..36a3c3d 100644
--- a/pkg/floor.go
+++ b/pkg/floor.go
@@ -10,7 +10,7 @@
 // 鐢熸垚涓�涓寘鍚ゼ灞傜殑浜鸿劯id,瑙f瀽妤煎眰
 // 浣跨敤48浣嶆簮id, 鍏朵腑鍓�41浣嶆槸imageid, 涓嶅彲浠ヤ慨鏀� 41-43浣嶅~ 06 浠h〃鍥惧儚, +99 + 3浣嶆ゼ灞�(绗竴浣�0琛ㄧず姝�,1琛ㄧず璐�)
 func GenerateFaceIdContainFloor(srcId, floorStr string) string {
-	floorNum, _ := ParseFloor("0", floorStr)
+	floorNum, _ := BuildFloorString("0", floorStr)
 	newId := srcId[0:43] + "99" + floorNum
 	//newId := srcId[0:43] + "99" + floorNum + snowflake.CreateRandomNumber(1)
 
@@ -29,10 +29,20 @@
 	return RestoreFloor(srcId[45:48])
 }
 
-// ParseFloor parses the floor string and returns a three-character string
-func ParseFloor(direction, floor string) (string, error) {
+// BuildFloorString parses the floor string and returns a string
+func BuildFloorString(direction, floor string) (string, error) {
+	var dire string
 	var sign string
 	var number string
+
+	switch direction {
+	case "in":
+		dire = "1"
+	case "out":
+		dire = "2"
+	default:
+		dire = "0"
+	}
 
 	// Check if the floor is negative
 	if strings.HasPrefix(floor, "-") {
@@ -51,7 +61,7 @@
 	// Format the number to be two digits
 	formattedNumber := fmt.Sprintf("%02s", number)
 
-	return direction + sign + formattedNumber, nil
+	return dire + sign + formattedNumber, nil
 }
 
 // RestoreFloor restores the three-character string back to the original floor string
@@ -93,3 +103,25 @@
 
 	return directionStr, floorStr, nil
 }
+
+func CheckDirection(str1, str2 string) string {
+	// 鍘绘帀瀛楃涓叉渶鍚庝竴涓瓧绗� 'F'
+	numStr1 := strings.TrimSuffix(str1, "F")
+	numStr2 := strings.TrimSuffix(str2, "F")
+
+	// 杞崲涓� int 绫诲瀷
+	num1, err1 := strconv.Atoi(numStr1)
+	num2, err2 := strconv.Atoi(numStr2)
+
+	// 妫�鏌ヨ浆鎹㈡槸鍚︽垚鍔�
+	if err1 != nil || err2 != nil {
+		return ""
+	}
+
+	// 姣旇緝涓や釜鏁存暟鐨勫ぇ灏�
+	if num1 > num2 {
+		return "out"
+	} else {
+		return "in"
+	}
+}
diff --git a/util/http.go b/pkg/http.go
similarity index 99%
rename from util/http.go
rename to pkg/http.go
index ff0dcc8..a616aae 100644
--- a/util/http.go
+++ b/pkg/http.go
@@ -1,4 +1,4 @@
-package util
+package pkg
 
 import (
 	"bytes"
diff --git a/repository/captureRepo.go b/repository/captureRepo.go
index 2b41e5b..87ae032 100644
--- a/repository/captureRepo.go
+++ b/repository/captureRepo.go
@@ -3,8 +3,6 @@
 import (
 	"encoding/base64"
 	"encoding/json"
-	"strconv"
-	"strings"
 	"time"
 
 	"gat1400Exchange/client"
@@ -53,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 {
@@ -89,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 {
@@ -147,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 {
@@ -190,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.")
@@ -221,7 +219,7 @@
 
 		for i := 0; i < config.NVCSConf.WaitRunTime; i++ {
 			if runState = nvcs.CurrentRunState(); runState.Floor != "" && runState.Floor != floor {
-				runDir = compareFloor(floor, runState.Floor)
+				runDir = pkg.CheckDirection(floor, runState.Floor)
 				break
 			}
 
@@ -274,7 +272,7 @@
 
 		for i := 0; i < config.NVCSConf.WaitRunTime; i++ {
 			if runState = nvcs.CurrentRunState(); runState.Floor != "" && runState.Floor != floor {
-				runDir = compareFloor(floor, runState.Floor)
+				runDir = pkg.CheckDirection(floor, runState.Floor)
 				break
 			}
 
@@ -282,7 +280,7 @@
 		}
 
 		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)
 			//}
@@ -336,30 +334,8 @@
 	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())
-	}
-}
-
-func compareFloor(str1, str2 string) string {
-	// 鍘绘帀瀛楃涓叉渶鍚庝竴涓瓧绗� 'F'
-	numStr1 := strings.TrimSuffix(str1, "F")
-	numStr2 := strings.TrimSuffix(str2, "F")
-
-	// 杞崲涓� int 绫诲瀷
-	num1, err1 := strconv.Atoi(numStr1)
-	num2, err2 := strconv.Atoi(numStr2)
-
-	// 妫�鏌ヨ浆鎹㈡槸鍚︽垚鍔�
-	if err1 != nil || err2 != nil {
-		return ""
-	}
-
-	// 姣旇緝涓や釜鏁存暟鐨勫ぇ灏�
-	if num1 > num2 {
-		return "2"
-	} else {
-		return "1"
 	}
 }
diff --git a/service/device.go b/service/device.go
index c552a4c..8c3ca96 100644
--- a/service/device.go
+++ b/service/device.go
@@ -3,11 +3,11 @@
 import (
 	"encoding/json"
 	"fmt"
+	"gat1400Exchange/pkg"
 	"time"
 
 	"gat1400Exchange/config"
 	"gat1400Exchange/models"
-	"gat1400Exchange/util"
 )
 
 type DevReportData struct {
@@ -85,7 +85,7 @@
 		}
 
 		headers := map[string]string{"Content-Type": "application/json; charset=UTF-8"}
-		_, err = util.HttpPost(config.ForwardConf.ReportServer, headers, data)
+		_, err = pkg.HttpPost(config.ForwardConf.ReportServer, headers, data)
 		if err != nil {
 			return err
 		}
diff --git a/service/resend.go b/service/resend.go
index 6961f45..aeba513 100644
--- a/service/resend.go
+++ b/service/resend.go
@@ -4,8 +4,8 @@
 	"gat1400Exchange/client"
 	"gat1400Exchange/config"
 	"gat1400Exchange/models"
+	"gat1400Exchange/pkg"
 	"gat1400Exchange/pkg/logger"
-	"gat1400Exchange/util"
 	"gat1400Exchange/vo"
 )
 
@@ -46,7 +46,7 @@
 				return
 			}
 		} else {
-			if !util.SendData([]byte(c.Data), config.ForwardConf.SyncServer) {
+			if !pkg.SendData([]byte(c.Data), config.ForwardConf.SyncServer) {
 				c.UpdateRetryCount()
 				logger.Warn("The data resend failed. retry count %d", c.Retry+1)
 				return

--
Gitblit v1.8.0