|
|
@@ -296,14 +296,15 @@ class ExamTypeStrategy
|
|
|
$textbookId = $params['textbook_id'] ?? null;
|
|
|
$grade = $params['grade'] ?? null;
|
|
|
$totalQuestions = $params['total_questions'] ?? 20;
|
|
|
+ $endCatalogId = $params['end_catalog_id'] ?? null; // 截止章节ID
|
|
|
|
|
|
if (!$textbookId) {
|
|
|
Log::warning('ExamTypeStrategy: 摸底测试需要 textbook_id 参数');
|
|
|
return $this->buildGeneralParams($params);
|
|
|
}
|
|
|
|
|
|
- // 第一步:根据 textbook_id 查询章节
|
|
|
- $catalogChapterIds = $this->getTextbookChapterIds($textbookId);
|
|
|
+ // 第一步:根据 textbook_id 查询章节(支持截止章节过滤)
|
|
|
+ $catalogChapterIds = $this->getTextbookChapterIds($textbookId, $endCatalogId);
|
|
|
|
|
|
if (empty($catalogChapterIds)) {
|
|
|
Log::warning('ExamTypeStrategy: 未找到课本章节', ['textbook_id' => $textbookId]);
|
|
|
@@ -312,6 +313,7 @@ class ExamTypeStrategy
|
|
|
|
|
|
Log::info('ExamTypeStrategy: 获取到课本章节(摸底测试)', [
|
|
|
'textbook_id' => $textbookId,
|
|
|
+ 'end_catalog_id' => $endCatalogId,
|
|
|
'chapter_count' => count($catalogChapterIds)
|
|
|
]);
|
|
|
|
|
|
@@ -1053,20 +1055,41 @@ class ExamTypeStrategy
|
|
|
|
|
|
/**
|
|
|
* 根据课本ID获取章节ID列表
|
|
|
+ * @param int $textbookId 教材ID
|
|
|
+ * @param int|null $endCatalogId 截止章节ID(仅摸底使用),只返回该章节及之前的章节
|
|
|
*/
|
|
|
- private function getTextbookChapterIds(int $textbookId): array
|
|
|
+ private function getTextbookChapterIds(int $textbookId, ?int $endCatalogId = null): array
|
|
|
{
|
|
|
try {
|
|
|
- // 查询 text_book_catalog_nodes 表
|
|
|
- $chapterIds = DB::table('textbook_catalog_nodes')
|
|
|
+ $query = DB::table('textbook_catalog_nodes')
|
|
|
->where('textbook_id', $textbookId)
|
|
|
->where('node_type', 'section') // nodeType='section'
|
|
|
- ->orderBy('sort_order')
|
|
|
- ->pluck('id')
|
|
|
- ->toArray();
|
|
|
+ ->orderBy('sort_order');
|
|
|
+
|
|
|
+ // 如果指定了截止章节,只获取该章节及之前的章节
|
|
|
+ if ($endCatalogId) {
|
|
|
+ $endSortOrder = DB::table('textbook_catalog_nodes')
|
|
|
+ ->where('id', $endCatalogId)
|
|
|
+ ->value('sort_order');
|
|
|
+
|
|
|
+ if ($endSortOrder !== null) {
|
|
|
+ $query->where('sort_order', '<=', $endSortOrder);
|
|
|
+ Log::debug('ExamTypeStrategy: 应用截止章节过滤', [
|
|
|
+ 'end_catalog_id' => $endCatalogId,
|
|
|
+ 'end_sort_order' => $endSortOrder
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ Log::warning('ExamTypeStrategy: 截止章节ID无效', [
|
|
|
+ 'end_catalog_id' => $endCatalogId
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $chapterIds = $query->pluck('id')->toArray();
|
|
|
|
|
|
Log::debug('ExamTypeStrategy: 查询课本章节ID', [
|
|
|
'textbook_id' => $textbookId,
|
|
|
+ 'end_catalog_id' => $endCatalogId,
|
|
|
'found_count' => count($chapterIds)
|
|
|
]);
|
|
|
|