Forráskód Böngészése

fix: log task status and score knowledge cases to 100

Add status endpoint request/response logging and callback_url in assemble.request; set knowledge exam total score to 100 and distribute per-question scores in exam_content.

Co-authored-by: Cursor <cursoragent@cursor.com>
yemeishu 5 napja
szülő
commit
cc9a5b7c75

+ 26 - 0
app/Http/Controllers/Api/IntelligentExamController.php

@@ -218,6 +218,7 @@ class IntelligentExamController extends Controller
             'kp_code_list' => $taskPayload['kp_code_list'] ?? [],
             'kp_codes' => $taskPayload['kp_codes'] ?? [],
             'total_questions' => $taskPayload['total_questions'] ?? null,
+            'callback_url' => $taskPayload['callback_url'] ?? null,
         ]);
 
         try {
@@ -304,15 +305,40 @@ class IntelligentExamController extends Controller
     public function status(string $taskId): JsonResponse
     {
         try {
+            Log::info('assemble.status.request', [
+                'task_id' => $taskId,
+                'query' => request()->query(),
+                'input' => request()->except([]),
+                'ip' => request()->ip(),
+                'user_agent' => request()->userAgent(),
+            ]);
+
             $task = $this->taskManager->getTaskStatus($taskId);
 
             if (! $task) {
+                Log::warning('assemble.status.response', [
+                    'task_id' => $taskId,
+                    'found' => false,
+                ]);
                 return response()->json([
                     'success' => false,
                     'message' => '任务不存在',
                 ], 404);
             }
 
+            Log::info('assemble.status.response', [
+                'task_id' => $taskId,
+                'found' => true,
+                'status' => $task['status'] ?? null,
+                'progress' => $task['progress'] ?? null,
+                'paper_id' => $task['paper_id'] ?? ($task['data']['paper_id'] ?? null),
+                'knowledge_id' => $task['knowledge_id'] ?? ($task['data']['knowledge_id'] ?? null),
+                'callback_url' => $task['callback_url'] ?? null,
+                'has_pdfs' => ! empty($task['pdfs'] ?? null),
+                'pdfs' => $task['pdfs'] ?? null,
+                'has_exam_content' => ! empty($task['exam_content'] ?? null),
+            ]);
+
             return response()->json([
                 'success' => true,
                 'data' => $task,

+ 22 - 4
app/Jobs/GenerateKnowledgeExplanationPdfJob.php

@@ -114,7 +114,7 @@ class GenerateKnowledgeExplanationPdfJob implements ShouldQueue
                 'paper_name' => '知识点讲解_' . $displayCode,
                 'paper_type' => 22,
                 'total_questions' => 0,
-                'total_score' => 0,
+                'total_score' => 100,
                 'status' => 'completed',
                 'difficulty_category' => null,
                 'exam_pdf_url' => $pdfUrl,
@@ -133,7 +133,7 @@ class GenerateKnowledgeExplanationPdfJob implements ShouldQueue
             $displayCode = $paperId;
         }
         $kpCodes = is_array($record->kp_codes) ? array_values($record->kp_codes) : [];
-        $questions = $this->buildKnowledgeQuestions();
+        $questions = $this->buildKnowledgeQuestions(100);
         $knowledgeDistribution = [];
         foreach ($kpCodes as $kpCode) {
             $knowledgeDistribution[(string) $kpCode] = 0;
@@ -153,7 +153,7 @@ class GenerateKnowledgeExplanationPdfJob implements ShouldQueue
                 'student_id' => (string) ($record->student_id ?? ''),
                 'teacher_id' => (string) ($record->teacher_id ?? ''),
                 'total_questions' => count($questions),
-                'total_score' => 0,
+                'total_score' => 100,
                 'difficulty_category' => null,
                 'created_at' => optional($record->created_at)->toISOString(),
                 'updated_at' => optional($record->updated_at)->toISOString(),
@@ -181,7 +181,7 @@ class GenerateKnowledgeExplanationPdfJob implements ShouldQueue
         ];
     }
 
-    private function buildKnowledgeQuestions(): array
+    private function buildKnowledgeQuestions(int $totalScore = 100): array
     {
         $questions = [];
         $seq = 1;
@@ -216,6 +216,24 @@ class GenerateKnowledgeExplanationPdfJob implements ShouldQueue
             }
         }
 
+        $count = count($questions);
+        if ($count > 0) {
+            $baseScore = intdiv($totalScore, $count);
+            $remainder = $totalScore - ($baseScore * $count);
+            foreach ($questions as &$q) {
+                $q['score'] = $baseScore;
+            }
+            unset($q);
+            if ($remainder > 0) {
+                // 余数分散到末尾若干题,保证总分精确为 totalScore
+                for ($i = $count - $remainder; $i < $count; $i++) {
+                    if ($i >= 0 && isset($questions[$i])) {
+                        $questions[$i]['score'] += 1;
+                    }
+                }
+            }
+        }
+
         return $questions;
     }
 }