Преглед на файлове

fix: 题型类型问题修复

yemeishu преди 1 седмица
родител
ревизия
af62451607
променени са 2 файла, в които са добавени 4 реда и са изтрити 42 реда
  1. 2 9
      app/Services/LearningAnalyticsService.php
  2. 2 33
      app/Services/QuestionBankService.php

+ 2 - 9
app/Services/LearningAnalyticsService.php

@@ -3013,19 +3013,12 @@ class LearningAnalyticsService
             // 格式化题目
             $formatted = [];
             foreach ($supplementaryQuestions as $question) {
-                // 手动判断题目类型,避免类型问题
+                // 优先使用题库原始题型
                 $stem = $question->stem ?? '';
                 $options = is_array($question->options) ? $question->options : (json_decode($question->options ?? '[]', true) ?: []);
                 $correctAnswer = $question->correct_answer ?? '';
 
-                // 简单判断逻辑
-                if (!empty($options) && is_array($options) && count($options) >= 2) {
-                    $questionType = 'choice';
-                } elseif (!empty($correctAnswer) && (strlen($correctAnswer) <= 10 || strpos($correctAnswer, '|') !== false)) {
-                    $questionType = 'fill';
-                } else {
-                    $questionType = 'answer';
-                }
+                $questionType = $question->question_type ?? 'answer';
 
                 $formatted[] = [
                     'id' => $question->id,

+ 2 - 33
app/Services/QuestionBankService.php

@@ -653,39 +653,8 @@ class QuestionBankService
                         $knowledgePoint = $question['kp_code'];
                     }
 
-                    // 获取题目类型
-                    $questionType = $this->normalizeQuestionTypeValue($question['question_type'] ?? $question['type'] ?? 'answer');
-                    if (! $questionType) {
-                        // 如果没有类型,根据内容推断
-                        $content = $question['stem'] ?? $question['content'] ?? '';
-                        if (is_string($content)) {
-                            // 1. 优先检查填空题(下划线)
-                            if (strpos($content, '____') !== false || strpos($content, '______') !== false) {
-                                $questionType = 'fill';
-                            }
-                            // 2. 检查选择题(必须有选项 A. B. C. D.)
-                            elseif (preg_match('/[A-D]\s*\./', $content) || preg_match('/\([A-D]\)/', $content)) {
-                                if (preg_match('/A\./', $content) && preg_match('/B\./', $content)) {
-                                    $questionType = 'choice';
-                                } else {
-                                    // 只有括号没有选项,可能是填空
-                                    if (strpos($content, '()') !== false || strpos($content, '()') !== false) {
-                                        $questionType = 'fill';
-                                    } else {
-                                        $questionType = 'answer';
-                                    }
-                                }
-                            }
-                            // 3. 检查纯括号填空
-                            elseif (strpos($content, '()') !== false || strpos($content, '()') !== false) {
-                                $questionType = 'fill';
-                            } else {
-                                $questionType = 'answer';
-                            }
-                        } else {
-                            $questionType = 'answer';
-                        }
-                    }
+                    // 获取题目类型(以题库原始类型为准,不再二次推断/归一化)
+                    $questionType = $question['question_type'] ?? $question['type'] ?? 'answer';
 
                     // 获取正确答案
                     $questionBankId = $question['id'] ?? $question['question_id'] ?? null;