Bläddra i källkod

fix(exam): 全教材摸底完成后统一重启第一章

指定章节摸底在同教材全部已摸底时改为返回第一章并标记 is_restart,和默认摸底流程保持一致。

Made-with: Cursor
yemeishu 1 månad sedan
förälder
incheckning
58d40dd56f
1 ändrade filer med 23 tillägg och 1 borttagningar
  1. 23 1
      app/Services/DiagnosticChapterService.php

+ 23 - 1
app/Services/DiagnosticChapterService.php

@@ -421,7 +421,29 @@ class DiagnosticChapterService
                 ];
             }
 
-            Log::warning('DiagnosticChapterService: 指定章节及同教材章节均无可用未摸底章节', [
+            // 与普通摸底逻辑保持一致:全教材都摸底后重启,返回第一章
+            $firstChapter = $chaptersInTextbook->first();
+            if ($firstChapter) {
+                $chapterData = $this->getChapterKnowledgePointsSimple((int) $firstChapter->id);
+                $kpCodesWithQuestions = $this->filterKpCodesWithQuestions($chapterData['kp_codes']);
+
+                Log::info('DiagnosticChapterService: 指定章节及同教材已摸底完成,重启到第一章', [
+                    'textbook_id' => $anchorTextbookId,
+                    'student_id' => $studentId,
+                    'target_chapter_ids' => $targetChapterIds,
+                    'chapter_id' => $firstChapter->id,
+                ]);
+
+                return [
+                    'chapter_id' => $firstChapter->id,
+                    'chapter_name' => $firstChapter->name ?? $firstChapter->title ?? '',
+                    'section_ids' => $chapterData['section_ids'],
+                    'kp_codes' => $kpCodesWithQuestions,
+                    'is_restart' => true,
+                ];
+            }
+
+            Log::warning('DiagnosticChapterService: 指定章节所属教材无章节可用于重启', [
                 'textbook_id' => $anchorTextbookId,
                 'student_id' => $studentId,
                 'target_chapter_ids' => $targetChapterIds,