package model import ( "case-admin-api/global" "gorm.io/gorm" "time" ) // CaseUser 统计数据-病例-用户 type CaseUser struct { CaseUserId int64 `gorm:"column:case_user_id;type:bigint(19);primary_key;comment:主键id" json:"case_user_id"` CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:所属病例id;NOT NULL" json:"case_id"` PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:用户所属平台id;NOT NULL" json:"platform_id"` UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"` ShareUserIden string `gorm:"column:share_user_iden;type:varchar(100);comment:分享人标识" json:"share_user_iden"` ReadDuration int `gorm:"column:read_duration;type:int(5);default:0;comment:阅读时长(秒)" json:"read_duration"` TotalScore int `gorm:"column:total_score;type:int(5);default:0;comment:单个病例领取总积分" json:"total_score"` StartTime LocalTime `gorm:"column:start_time;type:datetime;comment:开始参与时间" json:"start_time"` EndTime LocalTime `gorm:"column:end_time;type:datetime;comment:结束参与时间" json:"end_time"` Model Platform *Platform `gorm:"foreignKey:PlatformId;references:platform_id" json:"platform"` User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"` Case *Case `gorm:"foreignKey:CaseId;references:case_id" json:"case"` } func (m *CaseUser) TableName() string { return "case_user" } func (m *CaseUser) BeforeCreate(tx *gorm.DB) error { if m.CaseUserId == 0 { m.CaseUserId = 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 }