Quellcode durchsuchen

fix:学情分析快照knowledge_points填入完整的知识点掌握度数据 修复 bug

yemeishu vor 1 Woche
Ursprung
Commit
3e5d97f982
2 geänderte Dateien mit 4 neuen und 38 gelöschten Zeilen
  1. 3 37
      app/Services/ExamAnswerAnalysisService.php
  2. 1 1
      app/Services/MistakeBookService.php

+ 3 - 37
app/Services/ExamAnswerAnalysisService.php

@@ -1960,6 +1960,9 @@ class ExamAnswerAnalysisService
                     if (empty($questionId)) {
                         continue;
                     }
+                    if (isset($pq->score)) {
+                        $scoreMap[$questionId] = (float) $pq->score;
+                    }
 
                     // 如果该题目未提交,补充进去
                     if (! isset($submittedQuestionIds[$questionId])) {
@@ -1988,43 +1991,6 @@ class ExamAnswerAnalysisService
             }
         }
 
-        // 批量获取缺失分数的题目默认分值,避免N+1查询
-        $missingScoreIds = [];
-        foreach ($questions as $question) {
-            if (! isset($question['score'])) {
-                $qid = $question['question_id'] ?? $question['question_bank_id'] ?? null;
-                if ($qid) {
-                    $missingScoreIds[$qid] = true;
-                }
-            }
-        }
-
-        $scoreMap = [];
-        if (! empty($missingScoreIds)) {
-            try {
-                $questionScoreRows = DB::connection('mysql')
-                    ->table('questions')
-                    ->whereIn('id', array_keys($missingScoreIds))
-                    ->orWhereIn('question_code', array_keys($missingScoreIds))
-                    ->get(['id', 'question_code', 'score']);
-
-                foreach ($questionScoreRows as $row) {
-                    $score = isset($row->score) ? (float) $row->score : null;
-                    if ($score !== null) {
-                        $scoreMap[$row->id] = $score;
-                        if (! empty($row->question_code)) {
-                            $scoreMap[$row->question_code] = $score;
-                        }
-                    }
-                }
-            } catch (\Exception $e) {
-                Log::warning('批量获取题目默认分数失败,使用默认值', [
-                    'paper_id' => $paperId,
-                    'error' => $e->getMessage(),
-                ]);
-            }
-        }
-
         // 为已提交的题目计算分数
         foreach ($questions as &$question) {
             $questionId = $question['question_id'] ?? $question['question_bank_id'] ?? '';

+ 1 - 1
app/Services/MistakeBookService.php

@@ -246,7 +246,7 @@ class MistakeBookService
                     'question_text' => $payload['question_text'] ?? null,
                     'knowledge_point' => $payload['knowledge_point'] ?? null,
                     'explanation' => $payload['explanation'] ?? null,
-                    'kp_ids' => $kpIds,
+                    'kp_ids' => $kpIds ? json_encode($kpIds, JSON_UNESCAPED_UNICODE) : null,
                     'source' => $payload['source'] ?? MistakeRecord::SOURCE_PRACTICE,
                     'created_at' => $payload['happened_at'] ?? now(),
                     'review_status' => MistakeRecord::REVIEW_STATUS_PENDING,