|
|
@@ -262,6 +262,9 @@ class IntelligentExamController extends Controller
|
|
|
$questions = array_slice($questions, 0, $totalQuestions);
|
|
|
}
|
|
|
|
|
|
+ // 每个题型内按难度升序排序(由易到难),并重排题号
|
|
|
+ $questions = $this->sortQuestionsWithinTypeByDifficulty($questions);
|
|
|
+
|
|
|
// 调整题目分值
|
|
|
if (($data['total_questions'] ?? 20) == 20) {
|
|
|
// 20题:沿用动态凑整算法,目标总分100
|
|
|
@@ -1208,6 +1211,60 @@ class IntelligentExamController extends Controller
|
|
|
return $questions;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 每个题型内按难度升序排序,并统一重排题号
|
|
|
+ * 题型顺序固定:选择题 -> 填空题 -> 解答题
|
|
|
+ */
|
|
|
+ private function sortQuestionsWithinTypeByDifficulty(array $questions): array
|
|
|
+ {
|
|
|
+ if (empty($questions)) {
|
|
|
+ return $questions;
|
|
|
+ }
|
|
|
+
|
|
|
+ $grouped = [
|
|
|
+ 'choice' => [],
|
|
|
+ 'fill' => [],
|
|
|
+ 'answer' => [],
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach ($questions as $question) {
|
|
|
+ $type = $this->normalizeQuestionType((string) ($question['question_type'] ?? 'answer'));
|
|
|
+ $grouped[$type][] = $question;
|
|
|
+ }
|
|
|
+
|
|
|
+ $sortFn = function (array $a, array $b): int {
|
|
|
+ $aDifficulty = (float) ($a['difficulty'] ?? 0.5);
|
|
|
+ $bDifficulty = (float) ($b['difficulty'] ?? 0.5);
|
|
|
+
|
|
|
+ if ($aDifficulty !== $bDifficulty) {
|
|
|
+ return $aDifficulty <=> $bDifficulty;
|
|
|
+ }
|
|
|
+
|
|
|
+ $aId = (int) ($a['id'] ?? $a['question_id'] ?? 0);
|
|
|
+ $bId = (int) ($b['id'] ?? $b['question_id'] ?? 0);
|
|
|
+
|
|
|
+ return $aId <=> $bId;
|
|
|
+ };
|
|
|
+
|
|
|
+ usort($grouped['choice'], $sortFn);
|
|
|
+ usort($grouped['fill'], $sortFn);
|
|
|
+ usort($grouped['answer'], $sortFn);
|
|
|
+
|
|
|
+ $sorted = array_merge($grouped['choice'], $grouped['fill'], $grouped['answer']);
|
|
|
+ foreach ($sorted as $idx => &$question) {
|
|
|
+ $question['question_number'] = $idx + 1;
|
|
|
+ }
|
|
|
+ unset($question);
|
|
|
+
|
|
|
+ Log::info('题目已按题型内难度排序', [
|
|
|
+ 'choice_difficulty' => array_map(fn ($q) => $q['difficulty'] ?? null, $grouped['choice']),
|
|
|
+ 'fill_difficulty' => array_map(fn ($q) => $q['difficulty'] ?? null, $grouped['fill']),
|
|
|
+ 'answer_difficulty' => array_map(fn ($q) => $q['difficulty'] ?? null, $grouped['answer']),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return $sorted;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 【新增】根据series_id、semester_code和grade获取textbook_id
|
|
|
* 替代原来直接传入textbook_id的方式
|