zhangqian
2024-12-12 378445b97b115be44b25957ef71e01caae598593
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
}