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

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

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"
+	}
+}

--
Gitblit v1.8.0