| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748 |
- <?php
- namespace App\Services;
- use App\DTO\ExamAnalysisDataDto;
- use App\DTO\ReportPayloadDto;
- use App\Models\Paper;
- use App\Models\PaperQuestion;
- use App\Models\Student;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\File;
- use Illuminate\Support\Facades\Http;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Storage;
- use Illuminate\Support\Facades\URL;
- use Symfony\Component\Process\Exception\ProcessSignaledException;
- use Symfony\Component\Process\Exception\ProcessTimedOutException;
- use Symfony\Component\Process\Process;
- /**
- * PDF导出服务(重构版)
- * 负责生成试卷PDF、判卷PDF和学情报告PDF
- */
- class ExamPdfExportService
- {
- public function __construct(
- private readonly LearningAnalyticsService $learningAnalyticsService,
- private readonly QuestionBankService $questionBankService,
- private readonly QuestionServiceApi $questionServiceApi,
- private readonly PdfStorageService $pdfStorageService
- ) {}
- /**
- * 生成试卷 PDF(不含答案)
- */
- public function generateExamPdf(string $paperId): ?string
- {
- $url = $this->renderAndStoreExamPdf($paperId, includeAnswer: false, suffix: 'exam');
- // 如果生成成功,将 URL 写入数据库
- if ($url) {
- $this->savePdfUrlToDatabase($paperId, 'exam_pdf_url', $url);
- }
- return $url;
- }
- /**
- * 生成判卷 PDF(含答案与解析)
- */
- public function generateGradingPdf(string $paperId): ?string
- {
- $url = $this->renderAndStoreExamPdf($paperId, includeAnswer: true, suffix: 'grading', useGradingView: true);
- // 如果生成成功,将 URL 写入数据库
- if ($url) {
- $this->savePdfUrlToDatabase($paperId, 'grading_pdf_url', $url);
- }
- return $url;
- }
- /**
- * 生成学情分析 PDF
- */
- public function generateAnalysisReportPdf(string $paperId, string $studentId, ?string $recordId = null): ?string
- {
- if (function_exists('set_time_limit')) {
- @set_time_limit(240);
- }
- try {
- // 构建分析数据
- $analysisData = $this->buildAnalysisData($paperId, $studentId);
- if (!$analysisData) {
- return null;
- }
- // 创建DTO
- $dto = ExamAnalysisDataDto::fromArray($analysisData);
- $payloadDto = ReportPayloadDto::fromExamAnalysisDataDto($dto);
- // 渲染HTML
- $html = view('exam-analysis.pdf-report', $payloadDto->toArray())->render();
- if (!$html) {
- Log::error('ExamPdfExportService: 渲染HTML为空', ['paper_id' => $paperId]);
- return null;
- }
- // 生成PDF
- $pdfBinary = $this->buildPdf($html);
- if (!$pdfBinary) {
- return null;
- }
- // 保存PDF
- $version = time();
- $path = "analysis_reports/{$paperId}_{$studentId}_{$version}.pdf";
- $url = $this->pdfStorageService->put($path, $pdfBinary);
- if (!$url) {
- Log::error('ExamPdfExportService: 保存学情PDF失败', ['path' => $path]);
- return null;
- }
- // 保存URL到数据库
- $this->saveAnalysisPdfUrl($paperId, $studentId, $recordId, $url);
- return $url;
- } catch (\Throwable $e) {
- Log::error('ExamPdfExportService: 生成学情分析PDF失败', [
- 'paper_id' => $paperId,
- 'student_id' => $studentId,
- 'record_id' => $recordId,
- 'error' => $e->getMessage(),
- 'exception' => get_class($e),
- 'trace' => $e->getTraceAsString(),
- ]);
- return null;
- }
- }
- /**
- * 渲染并存储试卷PDF
- */
- private function renderAndStoreExamPdf(
- string $paperId,
- bool $includeAnswer,
- string $suffix,
- bool $useGradingView = false
- ): ?string {
- // 放宽脚本执行时间
- if (function_exists('set_time_limit')) {
- @set_time_limit(240);
- }
- try {
- $html = $this->renderExamHtml($paperId, $includeAnswer, $useGradingView);
- if (!$html) {
- Log::error('ExamPdfExportService: 渲染HTML为空', [
- 'paper_id' => $paperId,
- 'include_answer' => $includeAnswer,
- 'use_grading_view' => $useGradingView,
- ]);
- return null;
- }
- $pdfBinary = $this->buildPdf($html);
- if (!$pdfBinary) {
- return null;
- }
- $path = "exams/{$paperId}_{$suffix}.pdf";
- $url = $this->pdfStorageService->put($path, $pdfBinary);
- if (!$url) {
- Log::error('ExamPdfExportService: 保存PDF失败', ['path' => $path]);
- return null;
- }
- return $url;
- } catch (\Throwable $e) {
- Log::error('ExamPdfExportService: 生成PDF失败', [
- 'paper_id' => $paperId,
- 'suffix' => $suffix,
- 'error' => $e->getMessage(),
- 'exception' => get_class($e),
- 'trace' => $e->getTraceAsString(),
- ]);
- return null;
- }
- }
- /**
- * 渲染试卷HTML(重构版)
- */
- private function renderExamHtml(string $paperId, bool $includeAnswer, bool $useGradingView): ?string
- {
- // 直接构造请求URL,使用路由生成HTML
- $routeName = $useGradingView
- ? 'filament.admin.auth.intelligent-exam.grading'
- : 'filament.admin.auth.intelligent-exam.pdf';
- $url = route($routeName, ['paper_id' => $paperId, 'answer' => $includeAnswer ? 'true' : 'false']);
- // 使用HTTP客户端获取渲染后的HTML
- try {
- $response = Http::get($url);
- if ($response->successful()) {
- return $this->ensureUtf8Html($response->body());
- }
- } catch (\Exception $e) {
- Log::warning('ExamPdfExportService: 通过HTTP获取HTML失败,使用备用方案', [
- 'paper_id' => $paperId,
- 'error' => $e->getMessage(),
- ]);
- }
- // 备用方案:直接渲染视图(如果路由不可用)
- try {
- $paper = Paper::with('questions')->find($paperId);
- if (!$paper) {
- return null;
- }
- $viewName = $useGradingView ? 'exam-pdf.grading' : 'exam-pdf.student';
- $html = view($viewName, compact('paper'))->render();
- return $this->ensureUtf8Html($html);
- } catch (\Exception $e) {
- Log::error('ExamPdfExportService: 备用方案渲染失败', [
- 'paper_id' => $paperId,
- 'error' => $e->getMessage(),
- ]);
- return null;
- }
- }
- /**
- * 构建分析数据(重构版)
- * 优先使用本地MySQL数据,减少API依赖
- */
- private function buildAnalysisData(string $paperId, string $studentId): ?array
- {
- $paper = Paper::with(['questions' => function ($query) {
- $query->orderBy('question_number')->orderBy('id');
- }])->find($paperId);
- if (!$paper) {
- Log::error('ExamPdfExportService: 未找到试卷', [
- 'paper_id' => $paperId,
- 'student_id' => $studentId,
- ]);
- return null;
- }
- $student = Student::find($studentId);
- $studentInfo = [
- 'id' => $student?->student_id ?? $studentId,
- 'name' => $student?->name ?? $studentId,
- 'grade' => $student?->grade ?? '未知年级',
- 'class' => $student?->class_name ?? '未知班级',
- ];
- // 【修改】直接从本地数据库获取分析数据(不再调用API)
- $analysisData = [];
- if (!empty($paper->analysis_id)) {
- Log::info('ExamPdfExportService: 从本地数据库获取试卷分析数据', [
- 'paper_id' => $paperId,
- 'student_id' => $studentId,
- 'analysis_id' => $paper->analysis_id
- ]);
- $analysisRecord = \DB::table('exam_analysis_results')
- ->where('id', $paper->analysis_id)
- ->where('student_id', $studentId)
- ->first();
- if ($analysisRecord && !empty($analysisRecord->analysis_data)) {
- $analysisData = json_decode($analysisRecord->analysis_data, true);
- Log::info('ExamPdfExportService: 成功获取本地分析数据', [
- 'data_size' => strlen($analysisRecord->analysis_data)
- ]);
- } else {
- Log::warning('ExamPdfExportService: 未找到本地分析数据,将使用空数据', [
- 'paper_id' => $paperId,
- 'student_id' => $studentId,
- 'analysis_id' => $paper->analysis_id
- ]);
- }
- } else {
- Log::warning('ExamPdfExportService: 试卷无analysis_id,将使用空分析数据', [
- 'paper_id' => $paperId,
- 'student_id' => $studentId
- ]);
- }
- // 【修改】使用本地方法获取掌握度概览(替代API调用)
- $masteryData = [];
- try {
- Log::info('ExamPdfExportService: 获取学生掌握度概览', [
- 'student_id' => $studentId
- ]);
- $masteryOverview = $this->learningAnalyticsService->getStudentMasteryOverview($studentId);
- $masteryData = $masteryOverview['details'] ?? [];
- Log::info('ExamPdfExportService: 成功获取掌握度数据', [
- 'count' => count($masteryData)
- ]);
- } catch (\Exception $e) {
- Log::error('ExamPdfExportService: 获取掌握度数据失败', [
- 'student_id' => $studentId,
- 'error' => $e->getMessage()
- ]);
- }
- // 【修改】使用本地方法获取学习路径推荐(替代API调用)
- $recommendations = [];
- try {
- Log::info('ExamPdfExportService: 获取学习路径推荐', [
- 'student_id' => $studentId
- ]);
- $learningPaths = $this->learningAnalyticsService->recommendLearningPaths($studentId, 3);
- $recommendations = $learningPaths['recommendations'] ?? [];
- Log::info('ExamPdfExportService: 成功获取学习路径推荐', [
- 'count' => count($recommendations)
- ]);
- } catch (\Exception $e) {
- Log::error('ExamPdfExportService: 获取学习路径推荐失败', [
- 'student_id' => $studentId,
- 'error' => $e->getMessage()
- ]);
- }
- // 获取知识点名称映射
- $kpNameMap = $this->buildKnowledgePointNameMap();
- // 获取题目详情
- $questionDetails = $this->getQuestionDetailsFromPaper($paper);
- // 处理题目数据
- $questions = $this->processQuestionsForReport($paper, $questionDetails, $kpNameMap);
- return [
- 'paper' => [
- 'id' => $paper->paper_id,
- 'name' => $paper->paper_name,
- 'total_questions' => $paper->question_count,
- 'total_score' => $paper->total_score,
- 'created_at' => $paper->created_at,
- ],
- 'student' => $studentInfo,
- 'questions' => $questions,
- 'mastery' => $this->buildMasterySummary($masteryData, $kpNameMap),
- 'insights' => $analysisData['question_analysis'] ?? [], // 使用question_analysis替代question_results
- 'recommendations' => $recommendations,
- 'analysis_data' => $analysisData,
- ];
- }
- /**
- * 获取题目详情
- */
- private function getQuestionDetailsFromPaper(Paper $paper): array
- {
- $details = [];
- $questionIds = $paper->questions->pluck('question_id')->filter()->unique()->values();
- foreach ($questionIds as $qid) {
- try {
- $detail = $this->questionBankService->getQuestion((string) $qid);
- if (!empty($detail)) {
- $details[(string) $qid] = $detail;
- }
- } catch (\Throwable $e) {
- Log::warning('ExamPdfExportService: 获取题目详情失败', [
- 'question_id' => $qid,
- 'error' => $e->getMessage(),
- ]);
- }
- }
- return $details;
- }
- /**
- * 处理题目数据(用于报告)
- */
- private function processQuestionsForReport(Paper $paper, array $questionDetails, array $kpNameMap): array
- {
- $grouped = [
- 'choice' => [],
- 'fill' => [],
- 'answer' => [],
- ];
- $sortedQuestions = $paper->questions
- ->sortBy(function (PaperQuestion $q, int $idx) {
- $number = $q->question_number ?? $idx + 1;
- return is_numeric($number) ? (float) $number : ($q->id ?? $idx);
- });
- foreach ($sortedQuestions as $idx => $question) {
- $kpCode = $question->knowledge_point ?? '';
- $kpName = $kpNameMap[$kpCode] ?? $kpCode ?: '未标注';
- $detail = $questionDetails[(string) ($question->question_id ?? '')] ?? [];
- $solution = $detail['solution'] ?? $detail['解析'] ?? $detail['analysis'] ?? null;
- $typeRaw = $question->question_type ?? ($detail['question_type'] ?? $detail['type'] ?? '');
- $normalizedType = $this->normalizeQuestionType($typeRaw);
- $number = $question->question_number ?? ($idx + 1);
- $payload = [
- 'question_number' => $number,
- 'question_text' => is_array($question->question_text)
- ? json_encode($question->question_text, JSON_UNESCAPED_UNICODE)
- : ($question->question_text ?? ''),
- 'question_type' => $normalizedType,
- 'knowledge_point' => $kpCode,
- 'knowledge_point_name' => $kpName,
- 'score' => $question->score,
- 'solution' => $solution,
- ];
- $grouped[$normalizedType][] = $payload;
- }
- $ordered = array_merge($grouped['choice'], $grouped['fill'], $grouped['answer']);
- // 按卷面顺序重新编号
- foreach ($ordered as $i => &$q) {
- $q['display_number'] = $i + 1;
- }
- unset($q);
- return $ordered;
- }
- /**
- * 构建PDF
- */
- private function buildPdf(string $html): ?string
- {
- $tmpHtml = tempnam(sys_get_temp_dir(), 'exam_html_') . '.html';
- $utf8Html = $this->ensureUtf8Html($html);
- file_put_contents($tmpHtml, $utf8Html);
- // 仅使用Chrome渲染
- $chromePdf = $this->renderWithChrome($tmpHtml);
- @unlink($tmpHtml);
- return $chromePdf;
- }
- /**
- * 使用Chrome渲染PDF
- */
- private function renderWithChrome(string $htmlPath): ?string
- {
- $tmpPdf = tempnam(sys_get_temp_dir(), 'exam_pdf_') . '.pdf';
- $userDataDir = sys_get_temp_dir() . '/chrome-profile-' . uniqid();
- $chromeBinary = $this->findChromeBinary();
- if (!$chromeBinary) {
- Log::error('ExamPdfExportService: 未找到可用的Chrome/Chromium');
- return null;
- }
- // 设置运行时目录
- $runtimeHome = sys_get_temp_dir() . '/chrome-home';
- $runtimeXdg = sys_get_temp_dir() . '/chrome-xdg';
- if (!File::exists($runtimeHome)) {
- @File::makeDirectory($runtimeHome, 0755, true);
- }
- if (!File::exists($runtimeXdg)) {
- @File::makeDirectory($runtimeXdg, 0755, true);
- }
- $process = new Process([
- $chromeBinary,
- '--headless',
- '--disable-gpu',
- '--no-sandbox',
- '--disable-setuid-sandbox',
- '--disable-dev-shm-usage',
- '--no-zygote',
- '--disable-features=VizDisplayCompositor',
- '--disable-software-rasterizer',
- '--disable-extensions',
- '--disable-background-networking',
- '--disable-component-update',
- '--disable-client-side-phishing-detection',
- '--disable-default-apps',
- '--disable-domain-reliability',
- '--disable-sync',
- '--safebrowsing-disable-auto-update',
- '--no-first-run',
- '--no-default-browser-check',
- '--disable-crash-reporter',
- '--disable-print-preview',
- '--disable-features=PrintHeaderFooter',
- '--disable-features=TranslateUI',
- '--disable-features=OptimizationHints',
- '--disable-ipc-flooding-protection',
- '--disable-background-networking',
- '--disable-background-timer-throttling',
- '--disable-backgrounding-occluded-windows',
- '--disable-renderer-backgrounding',
- '--disable-features=AudioServiceOutOfProcess',
- '--user-data-dir=' . $userDataDir,
- '--print-to-pdf=' . $tmpPdf,
- '--print-to-pdf-no-header',
- '--allow-file-access-from-files',
- 'file://' . $htmlPath,
- ], null, [
- 'HOME' => $runtimeHome,
- 'XDG_RUNTIME_DIR' => $runtimeXdg,
- ]);
- $process->setTimeout(60);
- $killSignal = \defined('SIGKILL') ? \SIGKILL : 9;
- try {
- $startedAt = microtime(true);
- $process->start();
- $pdfGenerated = false;
- // 轮询检测PDF是否生成
- $pollStart = microtime(true);
- $maxPollSeconds = 30;
- while ($process->isRunning() && (microtime(true) - $pollStart) < $maxPollSeconds) {
- if (file_exists($tmpPdf) && filesize($tmpPdf) > 0) {
- $pdfGenerated = true;
- $process->stop(5, $killSignal);
- break;
- }
- usleep(200_000);
- }
- if ($process->isRunning()) {
- $process->stop(5, $killSignal);
- }
- $process->wait();
- } catch (ProcessTimedOutException|ProcessSignaledException $e) {
- if ($process->isRunning()) {
- $process->stop(5, $killSignal);
- }
- return $this->handleChromeProcessResult($tmpPdf, $userDataDir, $process, $startedAt);
- } catch (\Throwable $e) {
- if ($process->isRunning()) {
- $process->stop(5, $killSignal);
- }
- return $this->handleChromeProcessResult($tmpPdf, $userDataDir, $process, null);
- }
- return $this->handleChromeProcessResult($tmpPdf, $userDataDir, $process, null);
- }
- /**
- * 处理Chrome进程结果
- */
- private function handleChromeProcessResult(string $tmpPdf, string $userDataDir, Process $process, ?float $startedAt): ?string
- {
- $pdfExists = file_exists($tmpPdf);
- $pdfSize = $pdfExists ? filesize($tmpPdf) : null;
- if (!$process->isSuccessful()) {
- if ($pdfExists && $pdfSize > 0) {
- Log::warning('ExamPdfExportService: Chrome进程异常但生成了PDF', [
- 'exit_code' => $process->getExitCode(),
- 'tmp_pdf_size' => $pdfSize,
- ]);
- } else {
- Log::error('ExamPdfExportService: Chrome渲染失败', [
- 'exit_code' => $process->getExitCode(),
- 'error' => $process->getErrorOutput(),
- ]);
- @unlink($tmpPdf);
- File::deleteDirectory($userDataDir);
- return null;
- }
- }
- $pdfBinary = $pdfExists ? file_get_contents($tmpPdf) : null;
- @unlink($tmpPdf);
- File::deleteDirectory($userDataDir);
- return $pdfBinary ?: null;
- }
- /**
- * 查找Chrome二进制文件
- */
- private function findChromeBinary(): ?string
- {
- $candidates = [
- env('PDF_CHROME_BINARY'),
- '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
- '/usr/bin/google-chrome-stable',
- '/usr/bin/google-chrome',
- '/usr/bin/chromium-browser',
- '/usr/bin/chromium',
- ];
- foreach ($candidates as $path) {
- if ($path && is_file($path) && is_executable($path)) {
- return $path;
- }
- }
- return null;
- }
- /**
- * 确保HTML为UTF-8编码
- */
- private function ensureUtf8Html(string $html): string
- {
- $meta = '<meta charset="UTF-8">';
- if (stripos($html, '<head>') !== false) {
- return preg_replace('/<head>/i', "<head>{$meta}", $html, 1);
- }
- return $meta . $html;
- }
- /**
- * 构建知识点名称映射
- */
- private function buildKnowledgePointNameMap(): array
- {
- try {
- $options = $this->questionServiceApi->getKnowledgePointOptions();
- return $options ?: [];
- } catch (\Throwable $e) {
- Log::warning('ExamPdfExportService: 获取知识点名称失败', [
- 'error' => $e->getMessage(),
- ]);
- return [];
- }
- }
- /**
- * 构建掌握度摘要
- */
- private function buildMasterySummary(array $masteryData, array $kpNameMap): array
- {
- $items = [];
- $total = 0;
- $count = 0;
- $hasMap = !empty($kpNameMap);
- foreach ($masteryData as $row) {
- $code = $row['kp_code'] ?? null;
- if ($hasMap && $code && !isset($kpNameMap[$code])) {
- continue;
- }
- $name = $row['kp_name'] ?? ($code ? ($kpNameMap[$code] ?? $code) : '未知知识点');
- $level = (float) ($row['mastery_level'] ?? 0);
- $delta = $row['mastery_change'] ?? null;
- $items[] = [
- 'kp_code' => $code,
- 'kp_name' => $name,
- 'mastery_level' => $level,
- 'mastery_change' => $delta,
- ];
- $total += $level;
- $count++;
- }
- $average = $count > 0 ? round($total / $count, 2) : null;
- // 按掌握度从低到高排序
- usort($items, fn($a, $b) => ($a['mastery_level'] <=> $b['mastery_level']));
- return [
- 'items' => $items,
- 'average' => $average,
- 'weak_list' => array_slice($items, 0, 5),
- ];
- }
- /**
- * 标准化题型
- */
- private function normalizeQuestionType(string $type): string
- {
- $t = strtolower(trim($type));
- return match (true) {
- str_contains($t, 'choice') || str_contains($t, '选择') => 'choice',
- str_contains($t, 'fill') || str_contains($t, 'blank') || str_contains($t, '填空') => 'fill',
- default => 'answer',
- };
- }
- /**
- * 保存PDF URL到数据库
- */
- private function savePdfUrlToDatabase(string $paperId, string $field, string $url): void
- {
- try {
- $paper = Paper::where('paper_id', $paperId)->first();
- if ($paper) {
- $paper->update([$field => $url]);
- Log::info('ExamPdfExportService: PDF URL已写入数据库', [
- 'paper_id' => $paperId,
- 'field' => $field,
- 'url' => $url,
- ]);
- }
- } catch (\Throwable $e) {
- Log::error('ExamPdfExportService: 写入PDF URL失败', [
- 'paper_id' => $paperId,
- 'field' => $field,
- 'error' => $e->getMessage(),
- ]);
- }
- }
- /**
- * 保存学情分析PDF URL
- */
- private function saveAnalysisPdfUrl(string $paperId, string $studentId, ?string $recordId, string $url): void
- {
- try {
- if ($recordId) {
- // OCR记录
- $ocrRecord = \App\Models\OCRRecord::find($recordId);
- if ($ocrRecord) {
- $ocrRecord->update(['analysis_pdf_url' => $url]);
- Log::info('ExamPdfExportService: OCR记录学情分析PDF URL已写入数据库', [
- 'record_id' => $recordId,
- 'paper_id' => $paperId,
- 'student_id' => $studentId,
- 'url' => $url,
- ]);
- }
- } else {
- // 学生记录 - 使用新的 student_reports 表
- \App\Models\StudentReport::updateOrCreate(
- [
- 'student_id' => $studentId,
- 'report_type' => 'exam_analysis',
- 'exam_id' => $paperId,
- ],
- [
- 'pdf_url' => $url,
- 'generation_status' => 'completed',
- 'generated_at' => now(),
- 'updated_at' => now(),
- ]
- );
- Log::info('ExamPdfExportService: 学生学情报告PDF URL已保存到student_reports表', [
- 'student_id' => $studentId,
- 'paper_id' => $paperId,
- 'url' => $url,
- ]);
- }
- } catch (\Throwable $e) {
- Log::error('ExamPdfExportService: 写入学情分析PDF URL失败', [
- 'paper_id' => $paperId,
- 'student_id' => $studentId,
- 'record_id' => $recordId,
- 'error' => $e->getMessage(),
- ]);
- }
- }
- }
|