feat: 数据库引用变更

This commit is contained in:
TsMask
2025-04-22 11:41:22 +08:00
parent 44c4847f5c
commit 26f71f8dc8
33 changed files with 923 additions and 354 deletions

View File

@@ -91,31 +91,16 @@ func ConvertToCamelCase(str string) string {
return strings.Join(words, "")
}
// Bit 比特位为单位
// Bit 比特位为单位 1023.00 B --> 1.00 KB
func Bit(bit float64) string {
var GB, MB, KB string
if bit > float64(1<<30) {
GB = fmt.Sprintf("%0.2f", bit/(1<<30))
}
if bit > float64(1<<20) && bit < (1<<30) {
MB = fmt.Sprintf("%.2f", bit/(1<<20))
}
if bit > float64(1<<10) && bit < (1<<20) {
KB = fmt.Sprintf("%.2f", bit/(1<<10))
}
if GB != "" {
return GB + "GB"
} else if MB != "" {
return MB + "MB"
} else if KB != "" {
return KB + "KB"
} else {
return fmt.Sprintf("%vB", bit)
units := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
for i := 0; i < len(units); i++ {
if bit < 1024 || i == len(units)-1 {
return fmt.Sprintf("%.2f %s", bit, units[i])
}
bit /= 1024
}
return ""
}
// CronExpression 解析 Cron 表达式,返回下一次执行的时间戳(毫秒)
@@ -146,11 +131,11 @@ func SafeContent(value string) string {
}
// RemoveDuplicates 数组内字符串去重
func RemoveDuplicates(ids []string) []string {
func RemoveDuplicates(arr []string) []string {
uniqueIDs := make(map[string]bool)
uniqueIDSlice := make([]string, 0)
for _, id := range ids {
for _, id := range arr {
_, ok := uniqueIDs[id]
if !ok && id != "" {
uniqueIDs[id] = true
@@ -161,6 +146,29 @@ func RemoveDuplicates(ids []string) []string {
return uniqueIDSlice
}
// RemoveDuplicatesToArray 数组内字符串分隔去重转为字符数组
func RemoveDuplicatesToArray(keyStr, sep string) []string {
arr := make([]string, 0)
if keyStr == "" {
return arr
}
if strings.Contains(keyStr, sep) {
// 处理字符转数组后去重
strArr := strings.Split(keyStr, sep)
uniqueKeys := make(map[string]bool)
for _, str := range strArr {
_, ok := uniqueKeys[str]
if !ok && str != "" {
uniqueKeys[str] = true
arr = append(arr, str)
}
}
} else {
arr = append(arr, keyStr)
}
return arr
}
// Color 解析颜色 #fafafa
func Color(colorStr string) *color.RGBA {
// 去除 # 号

View File

@@ -8,8 +8,8 @@ import (
"be.ems/src/framework/config"
cachekeyConstants "be.ems/src/framework/constants/cachekey"
tokenConstants "be.ems/src/framework/constants/token"
redisCahe "be.ems/src/framework/database/redis"
"be.ems/src/framework/logger"
redisCahe "be.ems/src/framework/redis"
"be.ems/src/framework/utils/generate"
"be.ems/src/framework/utils/machine"
"be.ems/src/framework/vo"
@@ -28,7 +28,7 @@ func Remove(tokenStr string) string {
uuid := claims[tokenConstants.JWT_UUID].(string)
tokenKey := cachekeyConstants.LOGIN_TOKEN_KEY + uuid
hasKey, _ := redisCahe.Has("", tokenKey)
if hasKey {
if hasKey > 0 {
redisCahe.Del("", tokenKey)
}
return claims[tokenConstants.JWT_NAME].(string)
@@ -141,7 +141,7 @@ func LoginUser(claims jwt.MapClaims) vo.LoginUser {
tokenKey := cachekeyConstants.LOGIN_TOKEN_KEY + uuid
hasKey, _ := redisCahe.Has("", tokenKey)
var loginUser vo.LoginUser
if hasKey {
if hasKey > 0 {
loginUserStr, _ := redisCahe.Get("", tokenKey)
if loginUserStr == "" {
return loginUser