41 lines
1.6 KiB
Go
41 lines
1.6 KiB
Go
package model
|
|
|
|
import (
|
|
"case-open-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"`
|
|
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
|
|
}
|