39 lines
1.5 KiB
Go
39 lines
1.5 KiB
Go
package model
|
||
|
||
import (
|
||
"case-open-api/global"
|
||
"gorm.io/gorm"
|
||
"time"
|
||
)
|
||
|
||
// UserAnswerRecords 用户答题记录表
|
||
type UserAnswerRecords struct {
|
||
CaseUserQuestionId int64 `gorm:"column:case_user_question_id;type:bigint(19);primary_key;comment:主键id" json:"case_user_question_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"`
|
||
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:题目id;NOT NULL" json:"question_id"`
|
||
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
|
||
Answer string `gorm:"column:answer;type:varchar(255);comment:答案" json:"answer"`
|
||
IsTrue int `gorm:"column:is_true;type:tinyint(1);comment:是否正确(0:否 1:是)" json:"is_true"`
|
||
Model
|
||
CaseItemQuestion *CaseItemQuestion `gorm:"foreignKey:QuestionId;references:question_id" json:"case_item_question"`
|
||
}
|
||
|
||
func (m *UserAnswerRecords) TableName() string {
|
||
return "user_answer_records"
|
||
}
|
||
|
||
func (m *UserAnswerRecords) BeforeCreate(tx *gorm.DB) error {
|
||
if m.CaseUserQuestionId == 0 {
|
||
m.CaseUserQuestionId = 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
|
||
}
|