Kaynağa Gözat

fix: 知识点讲解功能添加完成,但是知识点表(包括知识点讲解)使用的是knowledge_points_copy1;正式环境的时候需要切换。

yemeishu 2 hafta önce
ebeveyn
işleme
c61ad3bd66

+ 2 - 20
app/Http/Controllers/ExamPdfController.php

@@ -1039,28 +1039,10 @@ class ExamPdfController extends Controller
 
         // 使用 ExamPdfExportService 构建知识点数据
         $pdfService = app(\App\Services\ExamPdfExportService::class);
-        // 获取知识点名称映射
-        $kpNameMap = [];
-        try {
-            $kpNameMap = app(\App\Services\QuestionServiceApi::class)->getKnowledgePointOptions();
-        } catch (\Throwable $e) {
-            // 静默失败,使用 code 作为名称
-        }
 
         // 批量获取知识点讲解
-        $explanations = $pdfService->buildExplanations($kpCodes);
-
-        $knowledgePoints = [];
-        foreach ($kpCodes as $kpCode) {
-            $kpData = [
-                'kp_code' => $kpCode,
-                'kp_name' => $kpNameMap[$kpCode] ?? $kpCode,
-                'explanation' => $explanations[$kpCode] ?? '',
-            ];
-
-            $knowledgePoints[] = $kpData;
-        }
-
+        $knowledgePoints = $pdfService->buildExplanations($kpCodes);
+info('knowledgePoints'.json_encode($knowledgePoints));
         return view('pdf.exam-knowledge-explanation', [
             'paperId' => $paper_id,
             'examCode' => $examCode ?: $paper_id,

+ 6 - 8
app/Services/ExamPdfExportService.php

@@ -2435,22 +2435,20 @@ class ExamPdfExportService
             return $result;
         }
 
-//        if ($this->shouldUseDefaultExplanations()) {
-//            foreach ($kpCodes as $kpCode) {
-//                $result[$kpCode] = $this->getDefaultExplanation($kpCode, $kpCode);
-//            }
-//            return $result;
-//        }
-
         try {
             // 批量获取知识点讲解
             $kps = \App\Models\KnowledgePoint::whereIn('kp_code', $kpCodes)->get()->keyBy('kp_code');
 
+            info('dd', $kps->toArray());
             // 有多少算多少
             foreach ($kpCodes as $kpCode) {
                 $kp = $kps->get($kpCode);
                 if ($kp && ! empty($kp->explanation)) {
-                    $result[$kpCode] = $kp->explanation;
+                    $result[] = [
+                        'kp_code' => $kpCode,
+                        'kp_name' => $kp->name ?? $kpCode,
+                        'explanation' => $kp->explanation,
+                    ];
                 }
             }
         } catch (\Throwable $e) {