init: init refactor

This commit is contained in:
Blizzard
2026-04-27 00:02:18 +08:00
commit e515f6a287
360 changed files with 30713 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
package model
import (
"sundynix-micro-go/common/utils/uniqueid"
"time"
"gorm.io/gorm"
)
// BaseModel 基础模型,所有表的公共字段
type BaseModel struct {
ID string `gorm:"size:50;primaryKey" json:"id"`
CreatedAt time.Time `json:"createdAt" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updatedAt" gorm:"autoCreateTime;autoUpdateTime"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// BeforeCreate 创建前自动生成雪花ID
func (m *BaseModel) BeforeCreate(db *gorm.DB) (err error) {
db.Statement.SetColumn("id", uniqueid.GenerateID())
return
}
// BeforeUpdate 更新前自动更新时间
func (m *BaseModel) BeforeUpdate(db *gorm.DB) (err error) {
db.Statement.SetColumn("updated_at", time.Now())
return
}