主要变更: - 数据库ID字段统一从 uint 改为 int64,提升数据容量和兼容性 - 重构答题检查逻辑,采用策略模式替代 switch-case - 新增 PracticeProgress 模型,支持练习进度持久化 - 优化错题本系统,自动记录答题进度和错误历史 - 添加 lib/pq PostgreSQL 驱动依赖 - 移除错题标签管理 API(待后续迁移) - 前端类型定义同步更新,适配后端模型变更 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
52 lines
2.5 KiB
Go
52 lines
2.5 KiB
Go
package models
|
|
|
|
// PracticeQuestion 练习题目模型
|
|
type PracticeQuestion struct {
|
|
ID int64 `gorm:"primarykey"`
|
|
QuestionID string `gorm:"size:50;not null" json:"question_id"` // 题目ID (原JSON中的id字段)
|
|
Type string `gorm:"index;size:30;not null" json:"type"` // 题目类型
|
|
TypeName string `gorm:"size:50" json:"type_name"` // 题型名称(中文)
|
|
Question string `gorm:"type:text;not null" json:"question"` // 题目内容
|
|
AnswerData string `gorm:"type:jsonb" json:"-"` // 答案数据(JSON格式存储)
|
|
OptionsData string `gorm:"type:jsonb" json:"-"` // 选项数据(JSON格式存储,用于选择题)
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (PracticeQuestion) TableName() string {
|
|
return "practice_questions"
|
|
}
|
|
|
|
// PracticeQuestionDTO 用于前端返回的数据传输对象
|
|
type PracticeQuestionDTO struct {
|
|
ID int64 `json:"id"` // 数据库自增ID
|
|
QuestionID string `json:"question_id"` // 题目编号(原JSON中的id)
|
|
Type string `json:"type"` // 前端使用的简化类型: single, multiple, judge, fill
|
|
Content string `json:"content"` // 题目内容
|
|
Options []Option `json:"options"` // 选择题选项数组
|
|
Category string `json:"category"` // 题目分类
|
|
Answer interface{} `json:"answer"` // 正确答案(用于题目管理编辑)
|
|
}
|
|
|
|
// PracticeAnswerSubmit 练习题答案提交
|
|
type PracticeAnswerSubmit struct {
|
|
QuestionID int64 `json:"question_id" binding:"required"` // 数据库ID
|
|
Answer interface{} `json:"answer" binding:"required"` // 用户答案
|
|
}
|
|
|
|
// PracticeAnswerResult 练习题答案结果
|
|
type PracticeAnswerResult struct {
|
|
Correct bool `json:"correct"` // 是否正确
|
|
UserAnswer interface{} `json:"user_answer"` // 用户答案
|
|
CorrectAnswer interface{} `json:"correct_answer,omitempty"` // 正确答案(仅在错误时返回)
|
|
AIGrading *AIGrading `json:"ai_grading,omitempty"` // AI评分结果(仅简答题)
|
|
}
|
|
|
|
// AIGrading AI评分结果
|
|
type AIGrading struct {
|
|
Score float64 `json:"score"` // 得分 (0-100)
|
|
Feedback string `json:"feedback"` // 评语
|
|
Suggestion string `json:"suggestion"` // 改进建议
|
|
ReferenceAnswer string `json:"reference_answer,omitempty"` // 参考答案(论述题)
|
|
ScoringRationale string `json:"scoring_rationale,omitempty"` // 评分依据
|
|
}
|