Просмотр исходного кода

fix: paper_type = 0摸底,需要排除知识点讲解部分页面

yemeishu 1 неделя назад
Родитель
Сommit
c5376fb566
3 измененных файлов с 32 добавлено и 9 удалено
  1. 19 4
      app/Http/Controllers/ExamPdfController.php
  2. 8 1
      app/Jobs/GenerateExamPdfJob.php
  3. 5 4
      app/Models/Paper.php

+ 19 - 4
app/Http/Controllers/ExamPdfController.php

@@ -2,6 +2,7 @@
 
 
 namespace App\Http\Controllers;
 namespace App\Http\Controllers;
 
 
+use App\Models\Paper;
 use App\Services\QuestionBankService;
 use App\Services\QuestionBankService;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Cache;
@@ -1042,7 +1043,6 @@ class ExamPdfController extends Controller
 
 
         // 批量获取知识点讲解
         // 批量获取知识点讲解
         $knowledgePoints = $pdfService->buildExplanations($kpCodes);
         $knowledgePoints = $pdfService->buildExplanations($kpCodes);
-info('knowledgePoints'.json_encode($knowledgePoints));
         return view('pdf.exam-knowledge-explanation', [
         return view('pdf.exam-knowledge-explanation', [
             'paperId' => $paper_id,
             'paperId' => $paper_id,
             'examCode' => $examCode ?: $paper_id,
             'examCode' => $examCode ?: $paper_id,
@@ -1071,19 +1071,34 @@ info('knowledgePoints'.json_encode($knowledgePoints));
         }
         }
 
 
         try {
         try {
-            // 调用 PDF 生成服务
-            $pdfService = app(\App\Services\ExamPdfExportService::class);
+            // 【修复】首先检查试卷是否存在
+            $paperModel = Paper::with('questions')->find($paper_id);
+            if (! $paperModel || $paperModel->questions->isEmpty()) {
+                return response()->json([
+                    'success' => false,
+                    'message' => '无效的试卷',
+                    'paper_id' => $paper_id,
+                ], 400);
+            }
 
 
-            // 是否包含知识点讲解(可选):未传参则使用 config/pdf.php 默认值
+            // 根据 config 或 env 配置决定是否包含知识点讲解
+            // 还需要判断如果摸底(paper_type =0)的时候也是不需要插入知识点讲解内容
             $includeKpExplain = null;
             $includeKpExplain = null;
+
             if ($request->has('include_kp_explain')) {
             if ($request->has('include_kp_explain')) {
                 $includeKpExplain = filter_var(
                 $includeKpExplain = filter_var(
                     $request->input('include_kp_explain'),
                     $request->input('include_kp_explain'),
                     FILTER_VALIDATE_BOOLEAN,
                     FILTER_VALIDATE_BOOLEAN,
                     FILTER_NULL_ON_FAILURE
                     FILTER_NULL_ON_FAILURE
                 );
                 );
+            } elseif ($paperModel->paper_type === 0) {
+                $includeKpExplain = false;
             }
             }
 
 
+            info("includekpexplain", [$includeKpExplain]);
+            // 调用 PDF 生成服务
+            $pdfService = app(\App\Services\ExamPdfExportService::class);
+
             // 生成统一 PDF(卷子 + 判卷)
             // 生成统一 PDF(卷子 + 判卷)
             $pdfUrl = $pdfService->generateUnifiedPdf($paper_id, $includeKpExplain);
             $pdfUrl = $pdfService->generateUnifiedPdf($paper_id, $includeKpExplain);
 
 

+ 8 - 1
app/Jobs/GenerateExamPdfJob.php

@@ -107,7 +107,14 @@ class GenerateExamPdfJob implements ShouldQueue
             $taskManager->updateTaskProgress($this->taskId, 10, '开始生成统一PDF(直接合并两个页面,效率最高)...');
             $taskManager->updateTaskProgress($this->taskId, 10, '开始生成统一PDF(直接合并两个页面,效率最高)...');
 
 
             // 根据 config 或 env 配置决定是否包含知识点讲解
             // 根据 config 或 env 配置决定是否包含知识点讲解
-            $unifiedPdfUrl = $pdfExportService->generateUnifiedPdf($this->paperId);
+            // 还需要判断如果摸底(paper_type =0)的时候也是不需要插入知识点讲解内容
+            $includeKpExplain = null;
+
+            if($paperModel->paper_type === 0) {
+                $includeKpExplain = false;
+            }
+            info("includekpexplain", [$includeKpExplain, $paperModel->paper_type]);
+            $unifiedPdfUrl = $pdfExportService->generateUnifiedPdf($this->paperId, $includeKpExplain);
 
 
             $taskManager->updateTaskProgress($this->taskId, 90, 'PDF生成完成,准备返回结果...');
             $taskManager->updateTaskProgress($this->taskId, 90, 'PDF生成完成,准备返回结果...');
             $examContent = $paperPayloadService->buildExamContent($paperModel);
             $examContent = $paperPayloadService->buildExamContent($paperModel);

+ 5 - 4
app/Models/Paper.php

@@ -11,10 +11,10 @@ class Paper extends Model
     public $incrementing = false;
     public $incrementing = false;
     protected $keyType = 'string';
     protected $keyType = 'string';
     public $timestamps = true;
     public $timestamps = true;
-    
+
     const CREATED_AT = 'created_at';
     const CREATED_AT = 'created_at';
     const UPDATED_AT = 'updated_at';
     const UPDATED_AT = 'updated_at';
-    
+
     protected $fillable = [
     protected $fillable = [
         'paper_id',
         'paper_id',
         'student_id',
         'student_id',
@@ -31,7 +31,7 @@ class Paper extends Model
         'grading_pdf_url', // 判卷PDF URL
         'grading_pdf_url', // 判卷PDF URL
         'all_pdf_url', // 【新增】统一PDF URL(包含试卷和判卷)
         'all_pdf_url', // 【新增】统一PDF URL(包含试卷和判卷)
     ];
     ];
-    
+
     protected $casts = [
     protected $casts = [
         'paper_id' => 'string',
         'paper_id' => 'string',
         'student_id' => 'string',
         'student_id' => 'string',
@@ -40,13 +40,14 @@ class Paper extends Model
         'total_score' => 'float',
         'total_score' => 'float',
         'status' => 'string',
         'status' => 'string',
         'difficulty_category' => 'string',
         'difficulty_category' => 'string',
+        'paper_type' => 'integer',
         'created_at' => 'datetime',
         'created_at' => 'datetime',
         'updated_at' => 'datetime',
         'updated_at' => 'datetime',
         'completed_at' => 'datetime',
         'completed_at' => 'datetime',
         'exam_pdf_url' => 'string',
         'exam_pdf_url' => 'string',
         'grading_pdf_url' => 'string',
         'grading_pdf_url' => 'string',
     ];
     ];
-    
+
     /**
     /**
      * 获取试卷的题目列表
      * 获取试卷的题目列表
      */
      */