优化代码
This commit is contained in:
parent
a6b809e051
commit
55bc397f9e
|
|
@ -736,6 +736,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
String mainName = FileUtil.mainName(fileName);
|
String mainName = FileUtil.mainName(fileName);
|
||||||
String suffix = FileUtil.getSuffix(fileName);
|
String suffix = FileUtil.getSuffix(fileName);
|
||||||
EdFileInfo newEdFileInfo = new EdFileInfo();
|
EdFileInfo newEdFileInfo = new EdFileInfo();
|
||||||
|
EdFileInfo finalEdFileInfo = null;
|
||||||
newEdFileInfo.newInit();
|
newEdFileInfo.newInit();
|
||||||
// 首先检查是否是同名文件
|
// 首先检查是否是同名文件
|
||||||
try {
|
try {
|
||||||
|
|
@ -746,7 +747,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||||
.eq(EdFileInfo::getFileType, suffix));
|
.eq(EdFileInfo::getFileType, suffix));
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
handUploadRepeatFile(parentId, file, strategy, dataOwnCode);
|
finalEdFileInfo = handUploadRepeatFile(parentId, file, strategy, dataOwnCode);
|
||||||
} else {
|
} else {
|
||||||
EdFileInfo parentFolderInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
EdFileInfo parentFolderInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
.eq(EdFileInfo::getId, parentId)
|
.eq(EdFileInfo::getId, parentId)
|
||||||
|
|
@ -772,6 +773,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
|
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
|
||||||
FileUtil.writeFromStream(file.getInputStream(), fileDestPath);
|
FileUtil.writeFromStream(file.getInputStream(), fileDestPath);
|
||||||
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||||
|
finalEdFileInfo = newEdFileInfo;
|
||||||
// fileSystemService.save(FileUtil.getInputStream(fileDestPath), fileDestPath); // 这里会导致文件大小为0,考虑到当前的系统为OS文件系统,暂不处理
|
// fileSystemService.save(FileUtil.getInputStream(fileDestPath), fileDestPath); // 这里会导致文件大小为0,考虑到当前的系统为OS文件系统,暂不处理
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -789,7 +791,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
log.error(info, e);
|
log.error(info, e);
|
||||||
throw new BizException(info);
|
throw new BizException(info);
|
||||||
}
|
}
|
||||||
UserThreadLocal.setSuccessMsg(StrFormatter.format("文件 {} 为上传到 {} 成功,同名同后缀的处理方式为 {}", fileName, destPath, strategyStr));
|
UserThreadLocal.setSuccessMsg(StrFormatter.format("文件 {} 为上传到 {} 成功,同名同后缀的处理方式为 {},存入的文件名为 {}", fileName, destPath, strategyStr, finalEdFileInfo.getFileName()+ "." + finalEdFileInfo.getFileType()));
|
||||||
return ElectromagneticResultUtil.success(true);
|
return ElectromagneticResultUtil.success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1063,7 +1065,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void handUploadRepeatFile(String parentId, MultipartFile file, Integer strategy, int dataOwnCode) throws IOException {
|
public EdFileInfo handUploadRepeatFile(String parentId, MultipartFile file, Integer strategy, int dataOwnCode) throws IOException {
|
||||||
Assert.isTrue(Arrays.asList(1, 2, 3).contains(strategy), "解决同名文件参数错误");
|
Assert.isTrue(Arrays.asList(1, 2, 3).contains(strategy), "解决同名文件参数错误");
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
String mainName = FileUtil.mainName(fileName);
|
String mainName = FileUtil.mainName(fileName);
|
||||||
|
|
@ -1111,6 +1113,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
this.baseMapper.insert(newEdFileInfo);
|
this.baseMapper.insert(newEdFileInfo);
|
||||||
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
|
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
|
||||||
fileSystemService.save(file.getInputStream(), fileDestPath);
|
fileSystemService.save(file.getInputStream(), fileDestPath);
|
||||||
|
return newEdFileInfo;
|
||||||
} else if (strategy == 3) {
|
} else if (strategy == 3) {
|
||||||
// 文件名加”_1“,存为新文件
|
// 文件名加”_1“,存为新文件
|
||||||
EdFileInfo parentFileInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
EdFileInfo parentFileInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
|
@ -1139,8 +1142,9 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
this.baseMapper.insert(newEdFileInfo);
|
this.baseMapper.insert(newEdFileInfo);
|
||||||
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
|
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
|
||||||
fileSystemService.save(file.getInputStream(), fileDestPath);
|
fileSystemService.save(file.getInputStream(), fileDestPath);
|
||||||
|
return newEdFileInfo;
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String doSysFileMerge(String identifier, String fileName, Integer totalChunks) {
|
private String doSysFileMerge(String identifier, String fileName, Integer totalChunks) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue