package model
|
|
import (
|
"apsClient/pkg/snowflake"
|
"github.com/jinzhu/gorm"
|
"time"
|
)
|
|
type CommonModel struct {
|
ID uint `gorm:"primary_key;autoIncrement:false"`
|
CreatedAt time.Time
|
UpdatedAt time.Time
|
DeletedAt *time.Time `sql:"index"`
|
}
|
|
func (c *CommonModel) BeforeCreate(db *gorm.DB) {
|
if c.ID == 0 {
|
id := snowflake.GenerateID()
|
if id < 0 {
|
id = snowflake.GenerateID()
|
}
|
c.ID = uint(id)
|
}
|
}
|