后端实现: - 创建错题数据模型和数据库表结构 - 实现错题记录、查询、统计、标记和清空API - 答题错误时自动记录到错题本 - 支持重复错误累计次数和更新时间 前端实现: - 创建错题本页面,支持查看、筛选和管理错题 - 实现错题统计展示(总数、已掌握、待掌握) - 支持标记已掌握、清空错题本和重做题目 - 在首页和个人中心添加错题本入口 - 完整的响应式设计适配移动端和PC端 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
52 lines
2.4 KiB
Go
52 lines
2.4 KiB
Go
package models
|
||
|
||
import (
|
||
"time"
|
||
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// WrongQuestion 错题记录模型
|
||
type WrongQuestion struct {
|
||
ID uint `gorm:"primarykey" json:"id"`
|
||
UserID uint `gorm:"index;not null" json:"user_id"` // 用户ID
|
||
QuestionID uint `gorm:"index;not null" json:"question_id"` // 题目ID(关联practice_questions表)
|
||
WrongAnswer string `gorm:"type:text;not null" json:"wrong_answer"` // 错误答案(JSON格式)
|
||
CorrectAnswer string `gorm:"type:text;not null" json:"correct_answer"` // 正确答案(JSON格式)
|
||
WrongCount int `gorm:"default:1" json:"wrong_count"` // 错误次数
|
||
LastWrongTime time.Time `gorm:"not null" json:"last_wrong_time"` // 最后一次错误时间
|
||
IsMastered bool `gorm:"default:false" json:"is_mastered"` // 是否已掌握
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||
|
||
// 关联 - 明确指定外键和引用
|
||
PracticeQuestion PracticeQuestion `gorm:"foreignKey:QuestionID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL" json:"-"`
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (WrongQuestion) TableName() string {
|
||
return "wrong_questions"
|
||
}
|
||
|
||
// WrongQuestionDTO 错题数据传输对象
|
||
type WrongQuestionDTO struct {
|
||
ID uint `json:"id"`
|
||
QuestionID uint `json:"question_id"`
|
||
Question PracticeQuestionDTO `json:"question"` // 题目详情
|
||
WrongAnswer interface{} `json:"wrong_answer"` // 错误答案
|
||
CorrectAnswer interface{} `json:"correct_answer"` // 正确答案
|
||
WrongCount int `json:"wrong_count"` // 错误次数
|
||
LastWrongTime time.Time `json:"last_wrong_time"` // 最后错误时间
|
||
IsMastered bool `json:"is_mastered"` // 是否已掌握
|
||
}
|
||
|
||
// WrongQuestionStats 错题统计
|
||
type WrongQuestionStats struct {
|
||
TotalWrong int `json:"total_wrong"` // 总错题数
|
||
Mastered int `json:"mastered"` // 已掌握数
|
||
NotMastered int `json:"not_mastered"` // 未掌握数
|
||
TypeStats map[string]int `json:"type_stats"` // 各题型错题数
|
||
CategoryStats map[string]int `json:"category_stats"` // 各分类错题数
|
||
}
|