|
|
@@ -25,6 +25,7 @@ import java.io.FileInputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.nio.file.Files;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.Executor;
|
|
|
@@ -152,9 +153,10 @@ public class ReportCollectService {
|
|
|
if (STATUS_COMPLETED.equals(draft.getParseStatus())) {
|
|
|
return;
|
|
|
}
|
|
|
+ String pdfPath = null;
|
|
|
try {
|
|
|
healthReportDraftService.markParseStarted(draftId);
|
|
|
- String pdfPath = resolvePdfPath(draft);
|
|
|
+ pdfPath = resolvePdfPath(draft);
|
|
|
if (pdfPath == null) {
|
|
|
healthReportDraftService.markCollectFailed(draftId, "无法获取报告文件路径");
|
|
|
return;
|
|
|
@@ -275,6 +277,8 @@ public class ReportCollectService {
|
|
|
} catch (Exception e) {
|
|
|
log.error("异步采集失败 draftId={}", draftId, e);
|
|
|
healthReportDraftService.markCollectFailed(draftId, e.getMessage());
|
|
|
+ } finally {
|
|
|
+ cleanupPdfCache(pdfPath);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -433,6 +437,25 @@ public class ReportCollectService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 解析完成后清理 OSS 下载中转缓存。OSS 为持久存储,本地缓存仅为解析中转,用后即删。
|
|
|
+ * 仅清理 .jdcloud-cache 缓存文件,本地磁盘存储(uploadBaseDir 直存)的原文件不动。
|
|
|
+ */
|
|
|
+ private void cleanupPdfCache(String pdfPath) {
|
|
|
+ if (pdfPath == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ File f = new File(pdfPath);
|
|
|
+ if (f.exists() && f.getAbsolutePath().contains(".jdcloud-cache")) {
|
|
|
+ try {
|
|
|
+ Files.deleteIfExists(f.toPath());
|
|
|
+ log.info("已清理OSS下载中转缓存 {}", pdfPath);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("清理OSS下载中转缓存失败 {}", pdfPath, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 检查文件是否为 PDF(通过魔数 %PDF- 判断)。
|
|
|
* 指纹引擎、LangGraph 解析、opencode 均要求 PDF 输入。
|