|
|
@@ -924,8 +924,45 @@ class ExamTypeStrategy
|
|
|
$studentId = $params['student_id'] ?? null;
|
|
|
$totalQuestions = $params['total_questions'] ?? 20;
|
|
|
|
|
|
+ // 【优化】如果用户没有指定章节,自动从教材所有有题目的章节中选择
|
|
|
+ if (empty($chapterIdList) && !empty($params['textbook_id'])) {
|
|
|
+ Log::info('ExamTypeStrategy: 用户未指定章节,自动从教材选择', [
|
|
|
+ 'textbook_id' => $params['textbook_id']
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 【修复】先查询教材下的所有章节,再筛选有题目的章节
|
|
|
+ // 步骤1:根据textbook_id获取该教材下的所有章节ID
|
|
|
+ $allChapterIds = DB::table('textbook_catalog_nodes')
|
|
|
+ ->where('textbook_id', $params['textbook_id'])
|
|
|
+ ->where('node_type', 'section')
|
|
|
+ ->pluck('id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ if (empty($allChapterIds)) {
|
|
|
+ Log::warning('ExamTypeStrategy: 教材下未找到章节', [
|
|
|
+ 'textbook_id' => $params['textbook_id']
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ // 步骤2:从这些章节中筛选出有题目的章节
|
|
|
+ $chapterIdList = DB::table('questions')
|
|
|
+ ->whereIn('textbook_catalog_nodes_id', $allChapterIds)
|
|
|
+ ->whereNotNull('textbook_catalog_nodes_id')
|
|
|
+ ->where('textbook_catalog_nodes_id', '!=', '')
|
|
|
+ ->distinct()
|
|
|
+ ->pluck('textbook_catalog_nodes_id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ Log::info('ExamTypeStrategy: 自动选择的章节列表', [
|
|
|
+ 'textbook_id' => $params['textbook_id'],
|
|
|
+ 'total_chapters' => count($allChapterIds),
|
|
|
+ 'chapters_with_questions' => count($chapterIdList),
|
|
|
+ 'chapter_ids' => $chapterIdList
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (empty($chapterIdList)) {
|
|
|
- Log::warning('ExamTypeStrategy: 教材组卷需要 chapter_id_list 参数');
|
|
|
+ Log::warning('ExamTypeStrategy: 教材组卷需要 chapter_id_list 参数或有效的textbook_id');
|
|
|
return $this->buildGeneralParams($params);
|
|
|
}
|
|
|
|