|
|
@@ -288,51 +288,27 @@ public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record> impleme
|
|
|
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public String saveFile(MultipartFile file, String type,int
|
|
|
- dirId) {
|
|
|
- DirForm dirForm = new DirForm();
|
|
|
- dirForm.setPageType(type);
|
|
|
- dirForm.setDirId(dirId);
|
|
|
-
|
|
|
- String path = folderNodeService.getPath(dirForm);
|
|
|
-
|
|
|
- String newFileName = renameFile(Objects.requireNonNull(file.getOriginalFilename()));
|
|
|
-
|
|
|
- File destFile = new File(path, newFileName);
|
|
|
-
|
|
|
- try (FileOutputStream fos = new FileOutputStream(destFile)) {
|
|
|
- log.info("写入文件 {}",file.getOriginalFilename());
|
|
|
- fos.write(file.getBytes());
|
|
|
- return destFile.getAbsolutePath();
|
|
|
- } catch (IOException e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
- return "";
|
|
|
- }
|
|
|
|
|
|
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public String saveFile(MultipartFile file,String pageType) {
|
|
|
log.info("接收到文件 {}",file.getName());
|
|
|
-
|
|
|
String demandFilePathPrefix = configService.getSystemConfig(pageType).toString();
|
|
|
-
|
|
|
String fileName = SystemUtil.renameFile(Objects.requireNonNull(file.getOriginalFilename()));
|
|
|
-
|
|
|
String absPath = demandFilePathPrefix + File.separator + fileName;
|
|
|
-
|
|
|
File destFile = new File(absPath);
|
|
|
-
|
|
|
+ // 核心修复:自动创建所有不存在的父级目录
|
|
|
+ File parentDir = destFile.getParentFile();
|
|
|
+ if (!parentDir.exists()) {
|
|
|
+ boolean mkdirs = parentDir.mkdirs();
|
|
|
+ log.info("目录创建结果:{},路径:{}", mkdirs, parentDir.getAbsolutePath());
|
|
|
+ }
|
|
|
try (FileOutputStream fos = new FileOutputStream(destFile)) {
|
|
|
log.info("写入文件 {}",file.getOriginalFilename());
|
|
|
fos.write(file.getBytes());
|
|
|
-
|
|
|
return absPath;
|
|
|
} catch (IOException e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
+ log.error("文件上传失败,路径:{}", absPath, e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|