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

---
 pkg/floor.go |   67 ++++++++++++++++++++-------------
 1 files changed, 40 insertions(+), 27 deletions(-)

diff --git a/pkg/floor.go b/pkg/floor.go
index 30629ee..ad14c3b 100644
--- a/pkg/floor.go
+++ b/pkg/floor.go
@@ -4,33 +4,33 @@
 	"fmt"
 	"strconv"
 	"strings"
-
-	"gat1400Exchange/pkg/snowflake"
 )
 
+// 宸插純鐢�
 // 鐢熸垚涓�涓寘鍚ゼ灞傜殑浜鸿劯id,瑙f瀽妤煎眰
-// 鏂癷d鐨勮鍒�, 20浣嶈澶囩紪鐮� +02 +14浣嶆椂闂� + 5555 + 3浣嶆ゼ灞�(绗竴浣�0琛ㄧず姝�,1琛ㄧず璐�) + 5浣嶉殢鏈烘暟
+// 浣跨敤48浣嶆簮id, 鍏朵腑鍓�41浣嶆槸imageid, 涓嶅彲浠ヤ慨鏀� 41-43浣嶅~ 06 浠h〃鍥惧儚, +99 + 3浣嶆ゼ灞�(绗竴浣�0琛ㄧず姝�,1琛ㄧず璐�)
 func GenerateFaceIdContainFloor(srcId, floorStr string) string {
-	floorNum, _ := parseFloor(floorStr)
-	newId := srcId[0:36] + "5555" + floorNum + snowflake.CreateRandomNumber(5)
+	floorNum, _ := ParseFloor("0", floorStr)
+	newId := srcId[0:43] + "99" + floorNum
+	//newId := srcId[0:43] + "99" + floorNum + snowflake.CreateRandomNumber(1)
 
 	return newId
 }
 
-func ParseFloorFromId(srcId string) (string, error) {
+func ParseFloorFromId(srcId string) (string, string, error) {
 	if len(srcId) != 48 {
-		return "", fmt.Errorf("invalid id %s", srcId)
+		return "", "", fmt.Errorf("invalid id %s", srcId)
 	}
 
-	if srcId[36:40] != "5555" {
-		return "", fmt.Errorf("invalid flag %s", srcId[36:40])
+	if srcId[43:45] != "99" {
+		return "", "", fmt.Errorf("invalid flag %s", srcId[43:45])
 	}
 
-	return restoreFloor(srcId[40:43])
+	return RestoreFloor(srcId[45:48])
 }
 
-// parseFloor parses the floor string and returns a three-character string
-func parseFloor(floor string) (string, error) {
+// ParseFloor parses the floor string and returns a three-character string
+func ParseFloor(direction, floor string) (string, error) {
 	var sign string
 	var number string
 
@@ -51,32 +51,45 @@
 	// Format the number to be two digits
 	formattedNumber := fmt.Sprintf("%02s", number)
 
-	return sign + formattedNumber, nil
+	return direction + sign + formattedNumber, nil
 }
 
-// restoreFloor restores the three-character string back to the original floor string
-func restoreFloor(encoded string) (string, error) {
-	if len(encoded) != 3 {
-		return "", fmt.Errorf("encoded string must be 3 characters long")
-	}
+// RestoreFloor restores the three-character string back to the original floor string
+func RestoreFloor(encoded string) (string, string, error) {
+	var direction, sign uint8
+	var floorNumber, floorStr, directionStr string
 
-	sign := encoded[0]
-	number := encoded[1:]
+	// 3浣嶆槸鏃х殑鏍煎紡, 涓轰簡鍏煎, 鏆傛椂淇濈暀
+	if len(encoded) == 3 {
+		sign = encoded[0]
+		floorNumber = encoded[1:]
+	} else if len(encoded) == 4 {
+		direction = encoded[0]
+		sign = encoded[1]
+		floorNumber = encoded[2:]
+	} else {
+		return "", "", fmt.Errorf("encoded string must be 3 characters long")
+	}
 
 	// Convert the number back to integer to remove any leading zeros
-	parsedNumber, err := strconv.Atoi(number)
+	parsedNumber, err := strconv.Atoi(floorNumber)
 	if err != nil {
-		return "", err
+		return "", "", err
 	}
 
-	var restoredFloor string
 	if sign == '1' {
-		restoredFloor = fmt.Sprintf("-%dF", parsedNumber)
+		floorStr = fmt.Sprintf("-%dF", parsedNumber)
 	} else if sign == '0' {
-		restoredFloor = fmt.Sprintf("%dF", parsedNumber)
+		floorStr = fmt.Sprintf("%dF", parsedNumber)
 	} else {
-		return "", fmt.Errorf("invalid sign character in encoded string")
+		return "", "", fmt.Errorf("invalid sign character in encoded string")
 	}
 
-	return restoredFloor, nil
+	if direction == '1' {
+		directionStr = "in"
+	} else if direction == '2' {
+		directionStr = "out"
+	}
+
+	return directionStr, floorStr, nil
 }

--
Gitblit v1.8.0