feat: 迁移plant

This commit is contained in:
Blizzard
2026-05-23 13:55:05 +08:00
parent a93477ea8e
commit ae6d03d351
228 changed files with 25296 additions and 917 deletions
+13 -4
View File
@@ -9,10 +9,11 @@ import (
// 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:"-"`
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:"-"`
CreatedAtStr string `gorm:"-" json:"createdAtStr"`
}
// BeforeCreate 创建前自动生成雪花ID
@@ -26,3 +27,11 @@ func (m *BaseModel) BeforeUpdate(db *gorm.DB) (err error) {
db.Statement.SetColumn("updated_at", time.Now())
return
}
// AfterFind 查询后自动填充 createdAtStr
func (m *BaseModel) AfterFind(db *gorm.DB) (err error) {
if !m.CreatedAt.IsZero() {
m.CreatedAtStr = m.CreatedAt.Format("2006-01-02 15:04:05")
}
return
}