feat: 迁移plant
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user