44 lines
2.2 KiB
Go
44 lines
2.2 KiB
Go
package model
|
||
|
||
import (
|
||
"gorm.io/gorm"
|
||
"knowledge/global"
|
||
"time"
|
||
)
|
||
|
||
// Question 题目表(单选-多选-问答-判断)
|
||
type Question struct {
|
||
QuestionId int64 `gorm:"column:question_id;type:bigint(19);primary_key;comment:主键id" json:"question_id"`
|
||
QuestionName string `gorm:"column:question_name;type:varchar(1000);comment:题目名称;NOT NULL" json:"question_name"`
|
||
QuestionType int `gorm:"column:question_type;type:tinyint(1);default:1;comment:题目类型(1:单选 2:多选 3:问答 4:判断);NOT NULL" json:"question_type"`
|
||
QuestionStatus int `gorm:"column:question_status;type:tinyint(1);default:1;comment:状态(1:正常 2:禁用)" json:"question_status"`
|
||
IsDelete int `gorm:"column:is_delete;type:tinyint(1);default:0;comment:是否删除(0:否 1:是)" json:"is_delete"`
|
||
QuestionSource int `gorm:"column:question_source;type:tinyint(1);comment:题目来源(1:本题库 2:外部数据);NOT NULL" json:"question_source"`
|
||
QuestionImage string `gorm:"column:question_image;type:varchar(500);comment:题目图片(逗号分隔)" json:"question_image"`
|
||
QuestionAnswer string `gorm:"column:question_answer;type:varchar(255);comment:答案" json:"question_answer"`
|
||
QuestionAnalysis string `gorm:"column:question_analysis;type:text;comment:解析" json:"question_analysis"`
|
||
Difficulty int `gorm:"column:difficulty;type:tinyint(1);default:0;comment:难度(0:未知 1:低 2:中 3:高)" json:"difficulty"`
|
||
FirstLabelId *int64 `gorm:"column:first_label_id;type:bigint(19);comment:一级标签id" json:"first_label_id"`
|
||
SecondLabelId *int64 `gorm:"column:second_label_id;type:bigint(19);comment:二级标签id" json:"second_label_id"`
|
||
Model
|
||
QuestionOption []*QuestionOption `gorm:"foreignKey:QuestionId;references:question_id" json:"question_option"`
|
||
}
|
||
|
||
func (m *Question) TableName() string {
|
||
return "kb_question"
|
||
}
|
||
|
||
func (m *Question) BeforeCreate(tx *gorm.DB) error {
|
||
if m.QuestionId == 0 {
|
||
m.QuestionId = 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
|
||
}
|