重大改进: - 练习进度模型优化:从"每题一条记录"改为"每用户每类型一条记录",提升性能和数据管理 - 完全基于后端数据库恢复答题进度,移除 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>
20 lines
678 B
Go
20 lines
678 B
Go
package models
|
|
|
|
import (
|
|
"gorm.io/datatypes"
|
|
)
|
|
|
|
// PracticeProgress 练习进度记录(每个用户每种题型一条记录)
|
|
type PracticeProgress struct {
|
|
ID int64 `gorm:"primarykey" json:"id"`
|
|
CurrentQuestionID int64 `gorm:"not null" json:"current_question_id"`
|
|
UserID int64 `gorm:"not null;uniqueIndex:idx_user_type" json:"user_id"`
|
|
Type string `gorm:"type:varchar(255);not null;uniqueIndex:idx_user_type" json:"type"`
|
|
UserAnswerRecords datatypes.JSON `gorm:"type:jsonb" json:"answers"`
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (PracticeProgress) TableName() string {
|
|
return "practice_progress"
|
|
}
|