From a22761151222bbe61677087fa90ff7e40914aacf Mon Sep 17 00:00:00 2001 From: wanghu Date: Mon, 21 Sep 2026 16:55:18 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/FileService.java | 22 ++++++------------- src/main/resources/application.yml | 6 +++-- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/yunhai/campusnotice/service/impl/FileService.java b/src/main/java/com/yunhai/campusnotice/service/impl/FileService.java index c855460..0c5e9eb 100644 --- a/src/main/java/com/yunhai/campusnotice/service/impl/FileService.java +++ b/src/main/java/com/yunhai/campusnotice/service/impl/FileService.java @@ -53,11 +53,9 @@ public class FileService implements IFileService { @Autowired private UpFileRepository upFileRepository; - @Value("${file.upload-path}") + @Value("${FILE_PATH}") private String uploadPath; - private static final String DEFAULT_APP_TYPE = "notice"; - // ============================ 上传 ============================ @Override @@ -77,13 +75,10 @@ public class FileService implements IFileService { ext = originalName.substring(dotIdx + 1).toLowerCase(); } - // 构造存储子路径:{appType}/{yyyyMMdd}/{uuid}.{ext} - String dateDir = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); String savedName = UUID.randomUUID().toString().replace("-", "") + (ext.isEmpty() ? "" : "." + ext); - String relativePath = (appType == null ? DEFAULT_APP_TYPE : appType) + "/" + dateDir + "/" + savedName; // 物理写入 - Path fullPath = Paths.get(uploadPath, relativePath); + Path fullPath = Paths.get(uploadPath, savedName); try { Files.createDirectories(fullPath.getParent()); file.transferTo(fullPath.toFile()); @@ -94,10 +89,10 @@ public class FileService implements IFileService { // 入库 UpFile entity = new UpFile(); - entity.setTopicType(appType == null ? DEFAULT_APP_TYPE : appType); + entity.setTopicType(appType); entity.setTopicId(topicId); entity.setFileTrueName(originalName); - entity.setFileName(relativePath); + entity.setFileName(savedName); entity.setFileSize((int) file.getSize()); entity.setFileType(ext); upFileRepository.save(entity); @@ -125,8 +120,7 @@ public class FileService implements IFileService { @Override public List listByTopic(String appType, Integer topicId) { - String type = appType == null ? DEFAULT_APP_TYPE : appType; - return upFileRepository.findByTopicTypeAndTopicId(type, topicId).stream() + return upFileRepository.findByTopicTypeAndTopicId(appType, topicId).stream() .map(this::toVo) .collect(Collectors.toList()); } @@ -279,8 +273,7 @@ public class FileService implements IFileService { @Override public void downloadZipByTopic(String topicType, Integer topicId, String zipName, HttpServletResponse response) { - String type = topicType == null ? DEFAULT_APP_TYPE : topicType; - List files = upFileRepository.findByTopicTypeAndTopicId(type, topicId); + List files = upFileRepository.findByTopicTypeAndTopicId(topicType, topicId); downloadZip(files, zipName, response); } @@ -293,9 +286,8 @@ public class FileService implements IFileService { if (files == null || files.length == 0) { return results; } - String type = appType != null ? appType : DEFAULT_APP_TYPE; for (MultipartFile file : files) { - results.add(upload(file, type, null)); + results.add(upload(file, appType, null)); } return results; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index ec4380e..103d5df 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -42,8 +42,8 @@ spring: auto-startup: false # 文件上传存储路径(Docker 部署时与 volume 挂载一致) -file: - upload-path: D:/data/upload +#file: +# upload-path: D:/data/upload # 短信模块配置 sms: @@ -76,3 +76,5 @@ yh: # 审批人资格组ID(用户中心组):>0 时 Submit 逐个校验被选人属于该组; # 0 = 仅校验用户存在(审批资格数据源待产品确认,改造方案 5.1-#5) approver-group-id: 0 + +FILE_PATH: D:/data/upload