This commit is contained in:
2025-01-24 16:00:57 +08:00
parent 5d21087a6d
commit 6c51011a0d
3 changed files with 187 additions and 5 deletions
+38
View File
@@ -0,0 +1,38 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CaseUserAnswer 用户参与表-答题记录
type CaseUserAnswer struct {
AnswerId int64 `gorm:"column:answer_id;type:bigint(19);primary_key;comment:主键id" json:"answer_id"`
CaseUserId int64 `gorm:"column:case_user_id;type:bigint(19);comment:用户参与id;NOT NULL" json:"case_user_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);default:0;comment:是否正确(0:否 1:是)" json:"is_true"`
Model
CaseItemQuestion *CaseItemQuestion `gorm:"foreignKey:QuestionId;references:question_id" json:"case_item_question"`
}
func (m *CaseUserAnswer) TableName() string {
return "case_user_answer"
}
func (m *CaseUserAnswer) BeforeCreate(tx *gorm.DB) error {
if m.AnswerId == 0 {
m.AnswerId = 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
}