package model import ( "case-open-api/global" "gorm.io/gorm" "time" ) // Case 病历表 type Case struct { CaseId int64 `gorm:"column:case_id;type:bigint(19);primary_key;comment:主键id" json:"case_id"` ProjectId int64 `gorm:"column:project_id;type:bigint(19);comment:所属项目id;NOT NULL" json:"project_id"` CaseStatus int `gorm:"column:case_status;type:tinyint(1);default:1;comment:病例状态(1:正常 2:禁用)" json:"case_status"` CaseName string `gorm:"column:case_name;type:varchar(100);comment:病例名称" json:"case_name"` CaseAuthor string `gorm:"column:case_author;type:varchar(100);comment:病例作者" json:"case_author"` IssuedScore int `gorm:"column:issued_score;type:int(5);default:0;comment:多平台已发放积分" json:"issued_score"` JoinNum int `gorm:"column:join_num;type:int(5);default:0;comment:多平台参加总人数" json:"join_num"` JoinWhiteNum int `gorm:"column:join_white_num;type:int(5);default:0;comment:多平台白名单参加总人数" json:"join_white_num"` MessageNum int `gorm:"column:message_num;type:int(5);default:0;comment:多平台留言人数" json:"message_num"` Model CasePlatform *CasePlatform `gorm:"foreignKey:CaseId;references:CaseId" json:"case_platform"` } func (m *Case) TableName() string { return "case" } func (m *Case) BeforeCreate(tx *gorm.DB) error { if m.CaseId == 0 { m.CaseId = 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 }