package model import ( "gorm.io/gorm" "knowledge/global" "time" ) // QuestionOption 题目选项表 type QuestionOption struct { OptionId int64 `gorm:"column:option_id;type:bigint(19);primary_key;comment:主键id" json:"option_id"` QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:题目id" json:"question_id"` OptionValue string `gorm:"column:option_value;type:varchar(255);comment:选项内容" json:"option_value"` Model } func (m *QuestionOption) TableName() string { return "kb_question_option" } func (m *QuestionOption) BeforeCreate(tx *gorm.DB) error { if m.OptionId == 0 { m.OptionId = 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 }