Ver código fonte

fix: restore difficulty data for analysis pdf

yemeishu 1 semana atrás
pai
commit
88ccf92404
1 arquivos alterados com 30 adições e 1 exclusões
  1. 30 1
      app/Services/ExamPdfExportService.php

+ 30 - 1
app/Services/ExamPdfExportService.php

@@ -1869,7 +1869,7 @@ class ExamPdfExportService
     private function compactQuestionsForV3(array $questions): array
     {
         $compact = [];
-        foreach ($questions as $question) {
+        foreach ($this->flattenQuestionPayloadRows($questions) as $question) {
             if (! is_array($question)) {
                 continue;
             }
@@ -1877,6 +1877,9 @@ class ExamPdfExportService
                 'question_id' => $question['question_id'] ?? null,
                 'question_bank_id' => $question['question_bank_id'] ?? null,
                 'is_correct' => $question['is_correct'] ?? null,
+                'difficulty' => $question['difficulty'] ?? null,
+                'score' => $question['score'] ?? null,
+                'score_obtained' => $question['score_obtained'] ?? null,
                 'student_answer' => $question['student_answer'] ?? null,
                 'answer' => $question['answer'] ?? null,
                 'correct_answer' => $question['correct_answer'] ?? null,
@@ -1888,6 +1891,32 @@ class ExamPdfExportService
         return $compact;
     }
 
+    /**
+     * V3 构建阶段只需要题目摘要;这里把 choice/fill/answer 分组结构拍平成题目列表。
+     *
+     * @return array<int, array<string, mixed>>
+     */
+    private function flattenQuestionPayloadRows(array $questions): array
+    {
+        $rows = [];
+        foreach ($questions as $key => $value) {
+            if (is_array($value) && in_array($key, ['choice', 'fill', 'answer'], true)) {
+                foreach ($value as $item) {
+                    if (is_array($item)) {
+                        $rows[] = $item;
+                    }
+                }
+                continue;
+            }
+
+            if (is_array($value)) {
+                $rows[] = $value;
+            }
+        }
+
+        return $rows;
+    }
+
     private function mapKpToStageModule(string $kpCode, array $kpMeta, string $rootCode): ?string
     {
         $code = trim($kpCode);