Przeglądaj źródła

fix: provide structured exam_content for knowledge callbacks

Populate exam_content with paper_info, knowledge_points, and baseline statistics in assemble_type=22 callbacks so clients can parse a consistent status payload.

Co-authored-by: Cursor <cursoragent@cursor.com>
yemeishu 6 dni temu
rodzic
commit
5d8915e133
1 zmienionych plików z 42 dodań i 1 usunięć
  1. 42 1
      app/Jobs/GenerateKnowledgeExplanationPdfJob.php

+ 42 - 1
app/Jobs/GenerateKnowledgeExplanationPdfJob.php

@@ -65,7 +65,7 @@ class GenerateKnowledgeExplanationPdfJob implements ShouldQueue
                 'pdfs' => [
                     'all_pdf' => $pdfUrl,
                 ],
-                'exam_content' => [],
+                'exam_content' => $this->buildKnowledgeExamContent($record, $pdfUrl),
             ]);
             $taskManager->sendCallback($this->taskId);
         } catch (\Throwable $e) {
@@ -124,4 +124,45 @@ class GenerateKnowledgeExplanationPdfJob implements ShouldQueue
             ]
         );
     }
+
+    private function buildKnowledgeExamContent(KnowledgeExplanation $record, string $pdfUrl): array
+    {
+        $paperId = (string) ($record->knowledge_id ?? '');
+        $displayCode = (string) preg_replace('/^(paper_|knowledge_)/', '', $paperId);
+        if ($displayCode === '') {
+            $displayCode = $paperId;
+        }
+        $kpCodes = is_array($record->kp_codes) ? array_values($record->kp_codes) : [];
+
+        return [
+            'paper_info' => [
+                'paper_id' => $paperId,
+                'paper_name' => '知识点讲解_' . $displayCode,
+                'student_id' => (string) ($record->student_id ?? ''),
+                'teacher_id' => (string) ($record->teacher_id ?? ''),
+                'total_questions' => 0,
+                'total_score' => 0,
+                'difficulty_category' => null,
+                'exam_code' => $displayCode,
+                'grading_code' => null,
+                'paper_id_num' => $displayCode,
+            ],
+            'knowledge_points' => $kpCodes,
+            'statistics' => [
+                'type_distribution' => [
+                    'choice' => 0,
+                    'fill' => 0,
+                    'answer' => 0,
+                ],
+                'difficulty_distribution' => [],
+                'knowledge_point_distribution' => array_fill_keys($kpCodes, 0),
+                'average_difficulty' => null,
+                'total_estimated_time' => 0,
+            ],
+            'pdfs' => [
+                'all_pdf' => $pdfUrl,
+            ],
+            'source' => 'knowledge_explanation',
+        ];
+    }
 }