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"` // 各分类错题数 }