case-api/api/model/UserAnswerRecord.go
2025-03-07 16:57:28 +08:00

39 lines
1.4 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"case-api/global"
"gorm.io/gorm"
"time"
)
// UserAnswerRecord 用户答题记录表
type UserAnswerRecord struct {
RecordId int64 `gorm:"column:record_id;type:bigint(19);primary_key;comment:主键id" json:"record_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 *UserAnswerRecord) TableName() string {
return "user_answer_record"
}
func (m *UserAnswerRecord) BeforeCreate(tx *gorm.DB) error {
if m.RecordId == 0 {
m.RecordId = 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
}