From f9a5e06df2c18aca0fcf76041a63f324c6dc62c2 Mon Sep 17 00:00:00 2001 From: yanlongqi Date: Tue, 2 Dec 2025 01:08:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=AF=8F=E6=97=A5=E4=B8=80?= =?UTF-8?q?=E7=BB=83=E7=BB=A7=E7=BB=AD=E7=AD=94=E9=A2=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:点击首页的每日一练快捷入口时,无法检测到未完成的考试记录 原因:GetExamRecordList 接口在指定 exam_id 参数时,仅返回 status='graded' 的记录, 过滤掉了 status='in_progress' 的未完成记录 修改: - 移除 status='graded' 过滤条件 - 添加 user_id 过滤,确保用户只能查看自己的记录 - 修改排序为按创建时间倒序(最新的在前) - 支持继续未完成的考试答题 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- internal/handlers/exam_handler.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/handlers/exam_handler.go b/internal/handlers/exam_handler.go index d005d12..dcdc74b 100644 --- a/internal/handlers/exam_handler.go +++ b/internal/handlers/exam_handler.go @@ -672,14 +672,15 @@ func GetExamRecordList(c *gin.Context) { return } - // 查询该试卷的所有已完成考试记录(包含用户信息) + // 查询该试卷的所有考试记录(包含用户信息) + // 注意:包含 in_progress 状态的记录,以支持继续答题功能 var records []models.ExamRecord - if err := db.Where("exam_id = ? AND status = ?", examID, "graded"). + if err := db.Where("exam_id = ? AND user_id = ?", examID, userID). Preload("Exam"). Preload("User", func(db *gorm.DB) *gorm.DB { return db.Select("id", "username", "nickname", "avatar") }). - Order("score DESC, created_at DESC"). + Order("created_at DESC"). Find(&records).Error; err != nil { log.Printf("查询考试记录失败: %v", err) c.JSON(http.StatusInternalServerError, gin.H{"success": false, "message": "查询考试记录失败"})