38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
package model
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"hepa-calc-api/global"
|
|
"time"
|
|
)
|
|
|
|
// UserCaseDiseaseItem 用户-病例-所患疾病列表
|
|
type UserCaseDiseaseItem struct {
|
|
ItemId int64 `gorm:"column:item_id;type:bigint(19);primary_key;comment:主键id" json:"item_id"`
|
|
UserCaseId int64 `gorm:"column:user_case_id;type:bigint(19);comment:用户病例id" json:"user_case_id"`
|
|
DiseaseClassId int64 `gorm:"column:disease_class_id;type:bigint(19);comment:疾病分类id" json:"disease_class_id"`
|
|
AppIden string `gorm:"column:app_iden;type:varchar(50);comment:app唯一标识" json:"app_iden"`
|
|
Duration *int `gorm:"column:duration;type:int(5);comment:患病时长(年)" json:"duration"`
|
|
Genotype string `gorm:"column:genotype;type:varchar(20);comment:基因型(仅丙肝存在)" json:"genotype"`
|
|
Model
|
|
BaseDiseaseClass *BaseDiseaseClass `gorm:"foreignKey:DiseaseClassId;references:disease_class_id" json:"disease_class"`
|
|
}
|
|
|
|
func (m *UserCaseDiseaseItem) TableName() string {
|
|
return "user_case_disease_item"
|
|
}
|
|
|
|
func (m *UserCaseDiseaseItem) BeforeCreate(tx *gorm.DB) error {
|
|
if m.ItemId == 0 {
|
|
m.ItemId = global.Snowflake.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
|
|
}
|