Browse Source

feat: 智能组卷(type 1/8)默认10题,非20题使用固定题型分值

- assembleType 1/8 默认 total_questions 从 20 改为 10,其余不变
- 20题沿用动态凑整算法(总分100),非20题使用固定分值(选择5/填空5/解答10)
- 新增 applyFixedScores 方法,前端可传 total_questions 覆盖默认值

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gwd 1 day ago
parent
commit
9413e8680f
1 changed files with 33 additions and 4 deletions
  1. 33 4
      app/Http/Controllers/Api/IntelligentExamController.php

+ 33 - 4
app/Http/Controllers/Api/IntelligentExamController.php

@@ -125,7 +125,9 @@ class IntelligentExamController extends Controller
         }
 
         $data = $validator->validated();
-        $data['total_questions'] = $data['total_questions'] ?? 20;
+        $assembleType = (int) ($data['assemble_type'] ?? 4);
+        $defaultQuestions = in_array($assembleType, [1, 8]) ? 10 : 20;
+        $data['total_questions'] = $data['total_questions'] ?? $defaultQuestions;
         $this->ensureStudentTeacherRelation($data);
 
         // 【修改】使用series_id、semester_code和grade获取textbook_id
@@ -257,9 +259,16 @@ class IntelligentExamController extends Controller
                 $questions = array_slice($questions, 0, $totalQuestions);
             }
 
-            // 调整题目分值,确保符合目标总分
-            $targetTotalScore = $data['total_score'] ?? 100.0;
-            $questions = $this->adjustQuestionScores($questions, $targetTotalScore);
+            // 调整题目分值
+            if (($data['total_questions'] ?? 20) == 20) {
+                // 20题:沿用动态凑整算法,目标总分100
+                $targetTotalScore = $data['total_score'] ?? 100.0;
+                $questions = $this->adjustQuestionScores($questions, $targetTotalScore);
+            } else {
+                // 非20题:固定题型分值(选择5、填空5、解答10)
+                $questions = $this->applyFixedScores($questions);
+                $targetTotalScore = array_sum(array_column($questions, 'score'));
+            }
 
             // 计算总分
             $totalScore = array_sum(array_column($questions, 'score'));
@@ -869,6 +878,26 @@ class IntelligentExamController extends Controller
         };
     }
 
+    /**
+     * 非20题时使用固定题型分值
+     * 选择题:5分,填空题:5分,解答题:10分
+     */
+    private function applyFixedScores(array $questions): array
+    {
+        foreach ($questions as &$question) {
+            $type = $this->normalizeQuestionType($question['question_type'] ?? 'answer');
+            $question['score'] = match ($type) {
+                'choice' => 5,
+                'fill' => 5,
+                'answer' => 10,
+                default => 5,
+            };
+        }
+        unset($question);
+
+        return $questions;
+    }
+
     /**
      * 计算试卷总分并调整各题目分值,确保总分接近目标分数
      * 符合中国中学卷子标准: