소스 검색

fix(diagnostic): widen chapter-diagnostic fallbacks for prod null cases

- After specified-chapter flow exhausts single-chapter picks, merge full-textbook KPs
- Expand child knowledge points before filtering questions in textbook-wide payload
- Query papers.student_id as string to match Paper model casting

Made-with: Cursor
yemeishu 1 개월 전
부모
커밋
ebe08acf45
1개의 변경된 파일24개의 추가작업 그리고 2개의 파일을 삭제
  1. 24 2
      app/Services/DiagnosticChapterService.php

+ 24 - 2
app/Services/DiagnosticChapterService.php

@@ -300,7 +300,7 @@ class DiagnosticChapterService
     public function hasChapterDiagnostic(int $studentId, int $chapterId): bool
     {
         return \App\Models\Paper::query()
-            ->where('student_id', $studentId)
+            ->where('student_id', (string) $studentId)
             ->where('paper_type', 0) // 摸底类型
             ->where('diagnostic_chapter_id', $chapterId)
             ->exists();
@@ -501,6 +501,20 @@ class DiagnosticChapterService
                 return $anchorPayload;
             }
 
+            // 未全摸底但锚点无题且后续未摸底章也无题:仍尝试全教材合并(含子知识点扩展)
+            $widePayload = $this->buildTextbookWideChapterPayload($chaptersInTextbook);
+            if ($widePayload !== null) {
+                Log::info('DiagnosticChapterService: 指定章节流程未全摸底但单章无有效题,合并全教材知识点', [
+                    'textbook_id' => $anchorTextbookId,
+                    'student_id' => $studentId,
+                    'anchor_chapter_id' => $anchorChapter->id,
+                    'kp_count' => count($widePayload['kp_codes']),
+                    'section_count' => count($widePayload['section_ids']),
+                ]);
+
+                return $widePayload;
+            }
+
             return null;
         }
 
@@ -672,6 +686,11 @@ class DiagnosticChapterService
             return null;
         }
 
+        // 节上多为父知识点编码,题目可能挂在子知识点上;合并兜底时扩展子 KP 再筛有题
+        if (!empty($orderedKp)) {
+            $orderedKp = $this->expandWithChildKnowledgePoints($orderedKp);
+        }
+
         $kpCodesWithQuestions = $this->filterKpCodesWithQuestions($orderedKp);
         if (empty($kpCodesWithQuestions)) {
             return null;
@@ -743,8 +762,11 @@ class DiagnosticChapterService
             return [];
         }
 
+        // papers.student_id 在模型中为 string,与整型混用可能导致部分环境匹配失败
+        $studentKey = (string) $studentId;
+
         $ids = \App\Models\Paper::query()
-            ->where('student_id', $studentId)
+            ->where('student_id', $studentKey)
             ->where('paper_type', 0)
             ->whereIn('diagnostic_chapter_id', $chapterIds)
             ->pluck('diagnostic_chapter_id')