package db
|
|
import (
|
"gorm.io/gorm"
|
"model-engine/pkg/snowflake"
|
"time"
|
)
|
|
type BaseModel struct {
|
ID string `gorm:"primary_key;column:id;type:varchar(255);" json:"id"`
|
CreatedAt time.Time
|
UpdatedAt time.Time
|
//swagger:ignore
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-" swaggerignore:"true"`
|
}
|
|
func (m *BaseModel) BeforeCreate(tx *gorm.DB) (err error) {
|
if m.ID == "" {
|
m.ID = snowflake.GenerateIdStr()
|
}
|
return
|
}
|
|
type CommonStatus int
|
|
const (
|
CommonStatusEnabled = 1 //启用
|
CommonStatusDisabled = 2 //禁用
|
)
|
|
func (c CommonStatus) Valid() bool {
|
return c == CommonStatusEnabled || c == CommonStatusDisabled
|
}
|