重大改进: - 练习进度模型优化:从"每题一条记录"改为"每用户每类型一条记录",提升性能和数据管理 - 完全基于后端数据库恢复答题进度,移除 localStorage 依赖,提高可靠性 - AI评分结果持久化:在答题记录中保存AI评分、评语和建议,支持历史查看 后端改进: - 新增 /api/practice/progress 接口获取练习进度(支持按类型筛选) - 新增 /api/practice/progress 接口清除练习进度(支持按类型清除) - PracticeProgress 模型重构:添加 current_question_id 和 user_answer_records 字段 - UserAnswerRecord 模型增强:添加 ai_score、ai_feedback、ai_suggestion 字段 - 提交答案时自动保存AI评分到数据库 前端优化: - 答题进度完全从后端加载,移除 localStorage 备份逻辑 - 修复判断题答案格式转换问题(boolean -> string) - 优化随机模式:首次答题时随机选择起始题目 - 改进答题历史显示:显示答题序号和历史答案标识 - 已答题目切换时保持答案和结果显示状态 - 清除进度时支持按类型清除(而非清空所有) 技术优化: - 统一索引策略:从 idx_user_question 改为 idx_user_type - JSON 字段类型从 jsonp 改为 jsonb(PostgreSQL 性能优化) - 增加详细的日志记录,便于调试和追踪 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
36 lines
1.4 KiB
Go
36 lines
1.4 KiB
Go
package models
|
|
|
|
import (
|
|
"gorm.io/datatypes"
|
|
"time"
|
|
)
|
|
|
|
// UserAnswerRecord 用户答题记录
|
|
type UserAnswerRecord struct {
|
|
ID int64 `gorm:"primarykey"`
|
|
UserID int64 `gorm:"index;not null" json:"user_id"` // 用户ID
|
|
QuestionID int64 `gorm:"index;not null" json:"question_id"` // 题目ID
|
|
IsCorrect bool `gorm:"not null" json:"is_correct"` // 是否答对
|
|
AnsweredAt time.Time `gorm:"not null" json:"answered_at"` // 答题时间
|
|
UserAnswer datatypes.JSON `gorm:"json" json:"user_answer"`
|
|
|
|
// AI 评分相关字段(仅简答题有值)
|
|
AIScore *float64 `gorm:"type:decimal(5,2)" json:"ai_score,omitempty"` // AI 评分 (0-100)
|
|
AIFeedback *string `gorm:"type:text" json:"ai_feedback,omitempty"` // AI 评语
|
|
AISuggestion *string `gorm:"type:text" json:"ai_suggestion,omitempty"` // AI 改进建议
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (UserAnswerRecord) TableName() string {
|
|
return "user_answer_records"
|
|
}
|
|
|
|
// UserStatistics 用户统计数据
|
|
type UserStatistics struct {
|
|
TotalQuestions int `json:"total_questions"` // 题库总数
|
|
AnsweredQuestions int `json:"answered_questions"` // 已答题数
|
|
CorrectAnswers int `json:"correct_answers"` // 答对题数
|
|
WrongQuestions int `json:"wrong_questions"` // 错题数量
|
|
Accuracy float64 `json:"accuracy"` // 正确率
|
|
}
|