新增雪花算法核心文件
This commit is contained in:
+2
-10
@@ -1,9 +1,8 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/bwmarrin/snowflake"
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/config"
|
||||
"hospital-admin-api/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -22,14 +21,7 @@ func (m *AdminRole) TableName() string {
|
||||
|
||||
func (m *AdminRole) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.RoleId == 0 {
|
||||
// 创建雪花算法实例
|
||||
sf, err := snowflake.NewNode(config.C.Snowflake)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 生成新的雪花算法 ID
|
||||
m.RoleId = sf.Generate().Int64()
|
||||
m.RoleId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
|
||||
Reference in New Issue
Block a user