zhangqian
2024-04-25 2d6875c93b25d0b7336c7fa11e066d213259fe2e
model/model.go
@@ -2,23 +2,18 @@
import (
   "apsClient/pkg/snowflake"
   "github.com/jinzhu/gorm"
   "time"
)
type CommonModel struct {
   ID        uint `gorm:"primary_key;autoIncrement:false"`
   ID        uint `gorm:"primary_key" json:"ID,string"`
   CreatedAt time.Time
   UpdatedAt time.Time
   DeletedAt *time.Time `sql:"index"`
}
func (c *CommonModel) BeforeCreate(db *gorm.DB) {
func (c *CommonModel) BeforeCreate() {
   if c.ID == 0 {
      id := snowflake.GenerateID()
      if id < 0 {
         id = snowflake.GenerateID()
      }
      c.ID = uint(id)
      c.ID = uint(snowflake.GenerateID())
   }
}