新增雪花算法核心文件

This commit is contained in:
2023-07-17 16:13:47 +08:00
parent ffa14d1241
commit da49a8273a
24 changed files with 73 additions and 215 deletions
+2 -10
View File
@@ -1,9 +1,8 @@
package model
import (
"github.com/bwmarrin/snowflake"
"gorm.io/gorm"
"hospital-admin-api/config"
"hospital-admin-api/global"
"time"
)
@@ -21,14 +20,7 @@ func (m *AdminPost) TableName() string {
func (m *AdminPost) BeforeCreate(tx *gorm.DB) error {
if m.PostId == 0 {
// 创建雪花算法实例
sf, err := snowflake.NewNode(config.C.Snowflake)
if err != nil {
return err
}
// 生成新的雪花算法 ID
m.PostId = sf.Generate().Int64()
m.PostId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())