This commit is contained in:
panda
2024-06-06 20:36:50 +08:00
parent 14c5b453b6
commit 41b61ebf1e
19 changed files with 41 additions and 288 deletions

View File

@@ -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]
}

View File

@@ -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)

View File

@@ -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)
}