Explorar o código

feat: 记录学案的知识点,这样学案讲解知识点的时候用这个。并且禁止用最后用其他无关的知识点来补充题目的逻辑

gwd hai 1 semana
pai
achega
5637639596

+ 32 - 28
app/Http/Controllers/ExamPdfController.php

@@ -1007,36 +1007,40 @@ class ExamPdfController extends Controller
         // 生成时间(格式:2026年01月30日 15:04:05)
         // 生成时间(格式:2026年01月30日 15:04:05)
         $generateDateTime = now()->format('Y年m月d日 H:i:s');
         $generateDateTime = now()->format('Y年m月d日 H:i:s');
 
 
-        // 提取并去重知识点代码(优先 paper_questions.knowledge_point,缺失时回退到题库 kp_code)
-        $paperQuestions = \App\Models\PaperQuestion::where('paper_id', $paper_id)->get();
-        $kpCodes = [];
-        $seen = [];
-
-        $questionBankIds = $paperQuestions
-            ->pluck('question_bank_id')
-            ->filter()
-            ->unique()
-            ->values();
-        $questionKpMap = [];
-        if ($questionBankIds->isNotEmpty()) {
-            $questionKpMap = \App\Models\Question::whereIn('id', $questionBankIds)
-                ->pluck('kp_code', 'id')
-                ->toArray();
-        }
-
-        foreach ($paperQuestions as $pq) {
-            $kpCode = trim((string) ($pq->knowledge_point ?? ''));
-            if ($kpCode === '' && ! empty($pq->question_bank_id)) {
-                $kpCode = trim((string) ($questionKpMap[$pq->question_bank_id] ?? ''));
+        // 优先使用 paper 中保存的 explanation_kp_codes(组卷时指定的知识点,最多2个)
+        $kpCodes = $paper->explanation_kp_codes ?? [];
+
+        // 如果没有保存 explanation_kp_codes,回退到从题目中提取(兼容旧数据)
+        if (empty($kpCodes)) {
+            $paperQuestions = \App\Models\PaperQuestion::where('paper_id', $paper_id)->get();
+            $seen = [];
+
+            $questionBankIds = $paperQuestions
+                ->pluck('question_bank_id')
+                ->filter()
+                ->unique()
+                ->values();
+            $questionKpMap = [];
+            if ($questionBankIds->isNotEmpty()) {
+                $questionKpMap = \App\Models\Question::whereIn('id', $questionBankIds)
+                    ->pluck('kp_code', 'id')
+                    ->toArray();
             }
             }
-            if ($kpCode === '') {
-                continue;
-            }
-            if (isset($seen[$kpCode])) {
-                continue;
+
+            foreach ($paperQuestions as $pq) {
+                $kpCode = trim((string) ($pq->knowledge_point ?? ''));
+                if ($kpCode === '' && ! empty($pq->question_bank_id)) {
+                    $kpCode = trim((string) ($questionKpMap[$pq->question_bank_id] ?? ''));
+                }
+                if ($kpCode === '') {
+                    continue;
+                }
+                if (isset($seen[$kpCode])) {
+                    continue;
+                }
+                $seen[$kpCode] = true;
+                $kpCodes[] = $kpCode;
             }
             }
-            $seen[$kpCode] = true;
-            $kpCodes[] = $kpCode;
         }
         }
 
 
         // 使用 ExamPdfExportService 构建知识点数据
         // 使用 ExamPdfExportService 构建知识点数据

+ 2 - 0
app/Models/Paper.php

@@ -22,6 +22,7 @@ class Paper extends Model
         'paper_name',
         'paper_name',
         'paper_type',
         'paper_type',
         'diagnostic_chapter_id', // 摸底的章节ID(章节摸底时记录)
         'diagnostic_chapter_id', // 摸底的章节ID(章节摸底时记录)
+        'explanation_kp_codes', // 学案讲解的知识点列表(最多2个)
         'total_questions',
         'total_questions',
         'total_score',
         'total_score',
         'status',
         'status',
@@ -43,6 +44,7 @@ class Paper extends Model
         'difficulty_category' => 'string',
         'difficulty_category' => 'string',
         'paper_type' => 'integer',
         'paper_type' => 'integer',
         'diagnostic_chapter_id' => 'integer',
         'diagnostic_chapter_id' => 'integer',
+        'explanation_kp_codes' => 'array', // JSON 自动转数组
         'created_at' => 'datetime',
         'created_at' => 'datetime',
         'updated_at' => 'datetime',
         'updated_at' => 'datetime',
         'completed_at' => 'datetime',
         'completed_at' => 'datetime',

+ 6 - 3
app/Services/ExamTypeStrategy.php

@@ -1746,7 +1746,8 @@ class ExamTypeStrategy
             'chapter_id_list' => $chapterInfo['section_ids'],
             'chapter_id_list' => $chapterInfo['section_ids'],
             'diagnostic_chapter_id' => $chapterInfo['chapter_id'], // 记录摸底的章节ID
             'diagnostic_chapter_id' => $chapterInfo['chapter_id'], // 记录摸底的章节ID
             'textbook_id' => $textbookId,
             'textbook_id' => $textbookId,
-            'grade' => $grade,
+            // 注意:不传 grade 参数,禁用"从其他知识点补充"的逻辑
+            // 用户需求:题目不够就不够,不从其他知识点补充
             'paper_name' => $params['paper_name'] ?? ('章节摸底_' . ($chapterInfo['chapter_name'] ?? '') . '_' . now()->format('Ymd_His')),
             'paper_name' => $params['paper_name'] ?? ('章节摸底_' . ($chapterInfo['chapter_name'] ?? '') . '_' . now()->format('Ymd_His')),
             'assembleType' => 0, // 确保 paper_type 记录为摸底
             'assembleType' => 0, // 确保 paper_type 记录为摸底
         ]);
         ]);
@@ -1828,7 +1829,7 @@ class ExamTypeStrategy
                         'chapter_id_list' => $nextChapter['section_ids'],
                         'chapter_id_list' => $nextChapter['section_ids'],
                         'diagnostic_chapter_id' => $nextChapter['chapter_id'],
                         'diagnostic_chapter_id' => $nextChapter['chapter_id'],
                         'textbook_id' => $textbookId,
                         'textbook_id' => $textbookId,
-                        'grade' => $grade,
+                        // 注意:不传 grade 参数,禁用"从其他知识点补充"的逻辑
                         'paper_name' => $params['paper_name'] ?? ('章节摸底_' . ($nextChapter['chapter_name'] ?? '') . '_' . now()->format('Ymd_His')),
                         'paper_name' => $params['paper_name'] ?? ('章节摸底_' . ($nextChapter['chapter_name'] ?? '') . '_' . now()->format('Ymd_His')),
                         'assembleType' => 0,
                         'assembleType' => 0,
                     ]);
                     ]);
@@ -1867,8 +1868,10 @@ class ExamTypeStrategy
 
 
         $enhanced = array_merge($params, [
         $enhanced = array_merge($params, [
             'kp_code_list' => $unmasteredKpCodes,
             'kp_code_list' => $unmasteredKpCodes,
+            'explanation_kp_codes' => $unmasteredKpCodes, // 学案讲解只显示这些知识点(最多2个)
             'textbook_id' => $textbookId,
             'textbook_id' => $textbookId,
-            'grade' => $grade,
+            // 注意:不传 grade 参数,禁用"从其他知识点补充"的逻辑
+            // 用户需求:题目不够就不够,不从其他知识点补充
             'paper_name' => $params['paper_name'] ?? ('智能学习_' . now()->format('Ymd_His')),
             'paper_name' => $params['paper_name'] ?? ('智能学习_' . now()->format('Ymd_His')),
             'assembleType' => 1, // paper_type 记录为智能组卷
             'assembleType' => 1, // paper_type 记录为智能组卷
         ]);
         ]);

+ 1 - 0
app/Services/QuestionBankService.php

@@ -567,6 +567,7 @@ class QuestionBankService
                     'paper_name' => $examData['paper_name'] ?? '未命名试卷',
                     'paper_name' => $examData['paper_name'] ?? '未命名试卷',
                     'paper_type' => $examData['assembleType'] ?? 'auto_generated', // 组卷类型: 0 摸底; 1 智能组卷,2. 知识点组卷,3 教材组卷
                     'paper_type' => $examData['assembleType'] ?? 'auto_generated', // 组卷类型: 0 摸底; 1 智能组卷,2. 知识点组卷,3 教材组卷
                     'diagnostic_chapter_id' => $examData['diagnostic_chapter_id'] ?? null, // 摸底的章节ID(章节摸底时记录)
                     'diagnostic_chapter_id' => $examData['diagnostic_chapter_id'] ?? null, // 摸底的章节ID(章节摸底时记录)
+                    'explanation_kp_codes' => $examData['explanation_kp_codes'] ?? null, // 学案讲解的知识点列表(最多2个)
                     'total_questions' => 0, // 临时设为0,处理完题目后再更新
                     'total_questions' => 0, // 临时设为0,处理完题目后再更新
                     'total_score' => $examData['total_score'] ?? 0,
                     'total_score' => $examData['total_score'] ?? 0,
                     'status' => 'draft',
                     'status' => 'draft',