附件
build / build-push (push) Successful in 59s

This commit is contained in:
wanghu
2026-09-21 16:55:18 +08:00
parent cfe0b0c4f0
commit a227611512
2 changed files with 11 additions and 17 deletions
@@ -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<UpFileVo> 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<UpFile> files = upFileRepository.findByTopicTypeAndTopicId(type, topicId);
List<UpFile> 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;
}
+4 -2
View File
@@ -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