From cda6223dada56ea9e3bda16503a18f3d9bb630c4 Mon Sep 17 00:00:00 2001
From: 6c <420680616@qq.com>
Date: 星期日, 04 一月 2026 15:38:18 +0800
Subject: [PATCH] 根据附件uuid判断文件是否存在方法bug——文件存放到数据库
---
src/main/java/com/product/file/service/FileManagerService.java | 37 +++++++++++++++++++++++++++++--------
1 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/src/main/java/com/product/file/service/FileManagerService.java b/src/main/java/com/product/file/service/FileManagerService.java
index db4ae7e..3e8aa1f 100644
--- a/src/main/java/com/product/file/service/FileManagerService.java
+++ b/src/main/java/com/product/file/service/FileManagerService.java
@@ -266,6 +266,11 @@
return false;
}
+ // 瀛樻斁鍦ㄦ暟鎹簱涓殑鏂囦欢锛岀洿鎺ュ垽瀹氭槸鍚︽湁鍊�
+ if (attachmentFse.getValue(CmnConst.FILE_CONTENT) != null) {
+ return true;
+ }
+
//鍒ゆ柇鏂囦欢瀛樻斁鍦ㄦ湇鍔″櫒杩樻槸鏈湴
boolean needDownloadFromServerFlag = "1".equals(attachmentFse.getString(CmnConst.UPLOAD_SIGN));
String dir = attachmentFse.getString(CmnConst.ATTACHMENT_URL);
@@ -886,6 +891,7 @@
if (saveInDb) {
File localFile = new File(Global.getSystemConfig("local.dir", "") + File.separator + attachmentFse.getString(CmnConst.ATTACHMENT_URL) + File.separator + fileName);
if (!localFile.exists()) {
+ localFile.getParentFile().mkdirs();
Files.copy(is, localFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
@@ -1024,13 +1030,22 @@
ftpService.downloadFile(path, os);
}
} else {
- // 鐩存帴鍦ㄦ湰鍦扮殑鐩綍涓壘鏂囦欢
- String localBasePath = Global.getSystemConfig("local.dir", "");
- path = localBasePath + File.separator + path;
- File file = new File(path);
- int len;
- byte[] b = new byte[1024];
- try (InputStream is = new FileInputStream(file)) {
+ InputStream is = null;
+ try {
+ Object fileContent = attachmentFse.getValue("file_content");
+ boolean saveInDb = fileContent != null;
+ if (saveInDb) {
+ // 瀛樺偍鍒版暟鎹簱
+ is = (InputStream) fileContent;
+ } else {
+ // 鐩存帴鍦ㄦ湰鍦扮殑鐩綍涓壘鏂囦欢
+ String localBasePath = Global.getSystemConfig("local.dir", "");
+ path = localBasePath + File.separator + path;
+ File file = new File(path);
+ is = Files.newInputStream(file.toPath());
+ }
+ int len;
+ byte[] b = new byte[1024];
while ((len = is.read(b)) > 0) {
if (Global.getPropertyToBoolean("file.encrypt", "true")) {
// 闇�瑕佽В瀵�
@@ -1040,7 +1055,13 @@
os.write(b, 0, len);
}
}
- }
+ } catch (Exception e) {
+ throw new BaseException(FileCode.GET_FILE_BYTES_FAIL);
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ }
}
return os.toByteArray();
--
Gitblit v1.9.2