|
|
@@ -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'] ?? '';
|