|
|
@@ -121,28 +121,76 @@ class ExamPdfExportService
|
|
|
$examPdfPath = $tempDir . "/{$paperId}_exam.pdf";
|
|
|
$gradingPdfPath = $tempDir . "/{$paperId}_grading.pdf";
|
|
|
|
|
|
- // 下载试卷PDF
|
|
|
- $examContent = Http::get($examPdfUrl)->body();
|
|
|
+ // 【修复】下载试卷PDF - 添加HTTP状态码检查
|
|
|
+ $examResponse = Http::get($examPdfUrl);
|
|
|
+ if (!$examResponse->successful()) {
|
|
|
+ Log::error('ExamPdfExportService: 下载试卷PDF失败', [
|
|
|
+ 'url' => $examPdfUrl,
|
|
|
+ 'status_code' => $examResponse->status()
|
|
|
+ ]);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ $examContent = $examResponse->body();
|
|
|
if (empty($examContent)) {
|
|
|
- Log::error('ExamPdfExportService: 下载试卷PDF失败', ['url' => $examPdfUrl]);
|
|
|
+ Log::error('ExamPdfExportService: 下载试卷PDF内容为空', ['url' => $examPdfUrl]);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 写入文件并验证
|
|
|
+ if (file_put_contents($examPdfPath, $examContent) === false) {
|
|
|
+ Log::error('ExamPdfExportService: 写入试卷PDF文件失败', ['path' => $examPdfPath]);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!file_exists($examPdfPath) || filesize($examPdfPath) === 0) {
|
|
|
+ Log::error('ExamPdfExportService: 试卷PDF文件无效', [
|
|
|
+ 'path' => $examPdfPath,
|
|
|
+ 'exists' => file_exists($examPdfPath),
|
|
|
+ 'size' => file_exists($examPdfPath) ? filesize($examPdfPath) : 'N/A'
|
|
|
+ ]);
|
|
|
return null;
|
|
|
}
|
|
|
- file_put_contents($examPdfPath, $examContent);
|
|
|
|
|
|
if ($progressCallback) {
|
|
|
$progressCallback(50, '下载判卷PDF...');
|
|
|
}
|
|
|
|
|
|
- // 下载判卷PDF
|
|
|
- $gradingContent = Http::get($gradingPdfUrl)->body();
|
|
|
+ // 【修复】下载判卷PDF - 添加HTTP状态码检查
|
|
|
+ $gradingResponse = Http::get($gradingPdfUrl);
|
|
|
+ if (!$gradingResponse->successful()) {
|
|
|
+ Log::error('ExamPdfExportService: 下载判卷PDF失败', [
|
|
|
+ 'url' => $gradingPdfUrl,
|
|
|
+ 'status_code' => $gradingResponse->status()
|
|
|
+ ]);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ $gradingContent = $gradingResponse->body();
|
|
|
if (empty($gradingContent)) {
|
|
|
- Log::error('ExamPdfExportService: 下载判卷PDF失败', ['url' => $gradingPdfUrl]);
|
|
|
+ Log::error('ExamPdfExportService: 下载判卷PDF内容为空', ['url' => $gradingPdfUrl]);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 写入文件并验证
|
|
|
+ if (file_put_contents($gradingPdfPath, $gradingContent) === false) {
|
|
|
+ Log::error('ExamPdfExportService: 写入判卷PDF文件失败', ['path' => $gradingPdfPath]);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!file_exists($gradingPdfPath) || filesize($gradingPdfPath) === 0) {
|
|
|
+ Log::error('ExamPdfExportService: 判卷PDF文件无效', [
|
|
|
+ 'path' => $gradingPdfPath,
|
|
|
+ 'exists' => file_exists($gradingPdfPath),
|
|
|
+ 'size' => file_exists($gradingPdfPath) ? filesize($gradingPdfPath) : 'N/A'
|
|
|
+ ]);
|
|
|
return null;
|
|
|
}
|
|
|
- file_put_contents($gradingPdfPath, $gradingContent);
|
|
|
|
|
|
Log::info('PDF文件下载完成', [
|
|
|
+ 'exam_path' => $examPdfPath,
|
|
|
'exam_size' => filesize($examPdfPath),
|
|
|
+ 'grading_path' => $gradingPdfPath,
|
|
|
'grading_size' => filesize($gradingPdfPath)
|
|
|
]);
|
|
|
|