mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[优化]
This commit is contained in:
@@ -7,13 +7,11 @@ import (
|
||||
"errors"
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
"math/rand"
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/apps/system/services"
|
||||
"pandax/pkg/cache"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type DeviceAuth struct {
|
||||
@@ -44,6 +42,7 @@ func (token *DeviceAuth) MD5ID() string {
|
||||
access = strings.TrimRight(access, "=")
|
||||
return access
|
||||
}
|
||||
|
||||
func (token *DeviceAuth) GetMarshal() string {
|
||||
marshal, _ := json.Marshal(*token)
|
||||
return string(marshal)
|
||||
@@ -82,12 +81,3 @@ func OrgAuthSet(tx *gorm.DB, roleId int64, owner string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
func GenerateID() string {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
id := make([]byte, 7) // 由于base64编码会增加字符数,这里使用7个字节生成10位ID
|
||||
_, err := rand.Read(id)
|
||||
if err != nil {
|
||||
panic(err) // 错误处理,根据实际情况进行处理
|
||||
}
|
||||
return base64.URLEncoding.EncodeToString(id)[:10]
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"pandax/apps/device/entity"
|
||||
"pandax/apps/device/services"
|
||||
"pandax/kit/utils"
|
||||
"pandax/pkg/global"
|
||||
"pandax/pkg/global/model"
|
||||
"pandax/pkg/rule_engine/message"
|
||||
"time"
|
||||
)
|
||||
@@ -48,7 +48,7 @@ func (n *createAlarmNode) Handle(msg *message.Message) error {
|
||||
}
|
||||
} else {
|
||||
alarm = &entity.DeviceAlarm{}
|
||||
alarm.Id = model.GenerateID()
|
||||
alarm.Id = utils.GenerateID()
|
||||
alarm.DeviceId = msg.Metadata.GetValue("deviceId").(string)
|
||||
alarm.ProductId = msg.Metadata.GetValue("productId").(string)
|
||||
alarm.Name = msg.Metadata.GetValue("deviceName").(string)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package tool
|
||||
|
||||
import (
|
||||
"pandax/pkg/global/model"
|
||||
"pandax/kit/utils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -11,7 +11,7 @@ func TestToCamelCase(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGenerateID(t *testing.T) {
|
||||
id := model.GenerateID()
|
||||
id := utils.GenerateID()
|
||||
t.Log(id)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user