42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package model
|
|
|
|
import (
|
|
"github.com/bwmarrin/snowflake"
|
|
"gorm.io/gorm"
|
|
"hospital-admin-api/config"
|
|
"time"
|
|
)
|
|
|
|
// DiseaseClassExpertise 疾病分类表-医生专长
|
|
type DiseaseClassExpertise struct {
|
|
ExpertiseId int64 `gorm:"column:expertise_id;type:bigint(19);primary_key;comment:主键id" json:"expertise_id"`
|
|
ExpertiseName string `gorm:"column:expertise_name;type:varchar(255);comment:专长名称" json:"expertise_name"`
|
|
ExpertiseSort int `gorm:"column:expertise_sort;type:int(11);default:0;comment:排序(越大排序越靠前)" json:"expertise_sort"`
|
|
Model
|
|
}
|
|
|
|
func (m *DiseaseClassExpertise) TableName() string {
|
|
return "gdxz_disease_class_expertise"
|
|
}
|
|
|
|
func (m *DiseaseClassExpertise) BeforeCreate(tx *gorm.DB) error {
|
|
if m.ExpertiseId == 0 {
|
|
// 创建雪花算法实例
|
|
sf, err := snowflake.NewNode(config.C.Snowflake)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 生成新的雪花算法 ID
|
|
m.ExpertiseId = sf.Generate().Int64()
|
|
}
|
|
|
|
m.CreatedAt = LocalTime(time.Now())
|
|
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
|
|
|
m.UpdatedAt = LocalTime(time.Now())
|
|
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
|
|
|
return nil
|
|
}
|