zhangzengfei
2024-06-13 4151389fb92c3f1444d033c1eed0a76165799eea
pkg/floor.go
@@ -4,15 +4,14 @@
   "fmt"
   "strconv"
   "strings"
   "gat1400Exchange/pkg/snowflake"
)
// 生成一个包含楼层的人脸id,解析楼层
// 使用48位源id, 其中前41位是imageid, 不可以修改  +99 + 3位楼层(第一位0表示正,1表示负) + 2位随机数
// 使用48位源id, 其中前41位是imageid, 不可以修改 41-43位填 06 代表图像, +99 + 3位楼层(第一位0表示正,1表示负)
func GenerateFaceIdContainFloor(srcId, floorStr string) string {
   floorNum, _ := parseFloor(floorStr)
   newId := srcId[0:41] + "99" + floorNum + snowflake.CreateRandomNumber(2)
   floorNum, _ := ParseFloor(floorStr)
   newId := srcId[0:43] + "99" + floorNum
   //newId := srcId[0:43] + "99" + floorNum + snowflake.CreateRandomNumber(1)
   return newId
}
@@ -22,15 +21,15 @@
      return "", fmt.Errorf("invalid id %s", srcId)
   }
   if srcId[41:43] != "99" {
      return "", fmt.Errorf("invalid flag %s", srcId[41:43])
   if srcId[43:45] != "99" {
      return "", fmt.Errorf("invalid flag %s", srcId[43:45])
   }
   return restoreFloor(srcId[43:46])
   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(floor string) (string, error) {
   var sign string
   var number string
@@ -54,8 +53,8 @@
   return sign + formattedNumber, nil
}
// restoreFloor restores the three-character string back to the original floor string
func restoreFloor(encoded string) (string, error) {
// 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")
   }