package model import ( "gorm.io/gorm" "knowledge/global" "time" ) // QuestionQaTimer 知识问答-计时设置 type QuestionQaTimer struct { TimerId int64 `gorm:"column:timer_id;type:bigint(19);primary_key;comment:主键id" json:"timer_id"` QaId int64 `gorm:"column:qa_id;type:bigint(19);comment:知识问答id;NOT NULL" json:"qa_id"` QuestionType int `gorm:"column:question_type;type:tinyint(1);default:1;comment:题目类型(1:单选 2:多选 3:问答 4:判断)" json:"question_type"` TimerRule int `gorm:"column:timer_rule;type:tinyint(1);default:1;comment:计时规则(1:正计时 2:倒计时)" json:"timer_rule"` Duration int `gorm:"column:duration;type:int(1);default:1;comment:时长(秒)" json:"duration"` Model } func (m *QuestionQaTimer) TableName() string { return "kb_question_qa_timer" } func (m *QuestionQaTimer) BeforeCreate(tx *gorm.DB) error { if m.TimerId == 0 { m.TimerId = 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 }