解决已知问题。
This commit is contained in:
parent
5fa31e6a0f
commit
eac95e140f
|
|
@ -749,7 +749,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ElectromagneticResult<?> upload(String parentId, MultipartFile file, Integer strategy, int dataOwnCode) {
|
||||
|
||||
Assert.isTrue(FileRepeatEnum.contains(strategy), "解决重名文件参数错误");
|
||||
String destPath = commonService.getDbPathById(parentId);
|
||||
String fileName = file.getOriginalFilename();
|
||||
String strategyStr = FileRepeatEnum.getDesc(strategy);
|
||||
|
|
@ -828,7 +828,13 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
log.error(info, e);
|
||||
throw new BizException(info);
|
||||
}
|
||||
UserThreadLocal.setSuccessInfo(finalEdFileInfo.getParentId(), finalEdFileInfo.getFileId(), "文件 {} 为上传到 {} 成功,同名同后缀的处理方式为 {},存入的文件名为 {}", fileName, destPath, strategyStr, finalEdFileInfo.getFileName() + "." + finalEdFileInfo.getFileType());
|
||||
UserThreadLocal.setSuccessInfo(Optional.ofNullable(finalEdFileInfo).map(EdFileInfo::getParentId).orElse(""),
|
||||
Optional.ofNullable(finalEdFileInfo).map(EdFileInfo::getFileId).orElse(""),
|
||||
"文件 {} 为上传到 {} 成功,同名同后缀的处理方式为 {},存入的文件名为 {}",
|
||||
fileName,
|
||||
destPath,
|
||||
strategyStr,
|
||||
Optional.ofNullable(finalEdFileInfo).map(EdFileInfo::getFileName).orElse(fileName) + "." + Optional.ofNullable(finalEdFileInfo).map(EdFileInfo::getFileType).orElse(suffix));
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
|
||||
|
|
@ -859,6 +865,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public ElectromagneticResult<?> moveFile(String id, String targetFolderId, Integer strategy, int dataOwnCode) {
|
||||
|
||||
Assert.isTrue(FileRepeatEnum.contains(strategy), "解决重名文件参数错误");
|
||||
// 获取原文件mysql模型
|
||||
EdFileInfo srcFileInfo = this.baseMapper.selectById(id);
|
||||
String srcFilePath = commonService.getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
|
||||
|
|
@ -903,9 +910,9 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
throw new BizException(info);
|
||||
}
|
||||
|
||||
if (strategy == 1) {
|
||||
if (strategy == FileRepeatEnum.IGNORE.code) {
|
||||
return srcFileInfo;
|
||||
} else if (strategy == 2) {
|
||||
} else if (strategy == FileRepeatEnum.REVERSION.code) {
|
||||
// 做版本更新
|
||||
List<EdFileInfo> sameFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getParentId, targetFolderId)
|
||||
|
|
@ -966,6 +973,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
*/
|
||||
@Override
|
||||
public ElectromagneticResult<?> copyFile(String id, String targetFolderId, Integer strategy, int dataOwnCode) {
|
||||
Assert.isTrue(FileRepeatEnum.contains(strategy), "解决重名文件参数错误");
|
||||
// 获取原文件mysql模型
|
||||
EdFileInfo srcFileInfo = this.baseMapper.selectById(id);
|
||||
String srcFileDbPath = srcFileInfo.getFilePath();
|
||||
|
|
@ -1070,10 +1078,10 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
log.info(info);
|
||||
throw new BizException(info);
|
||||
}
|
||||
if (strategy == 1) {
|
||||
if (strategy == FileRepeatEnum.IGNORE.code) {
|
||||
return destFolderInfo;
|
||||
}
|
||||
if (strategy == 2) {
|
||||
if (strategy == FileRepeatEnum.REVERSION.code) {
|
||||
// 做版本更新
|
||||
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getParentId, targetFolderId)
|
||||
|
|
@ -1101,7 +1109,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
String destFilePath = commonService.getFileSysPath(destSaveFileInfo.getFilePath(), dataOwnCode);
|
||||
fileSystemService.copyFile(srcFilePath, destFilePath);
|
||||
return destSaveFileInfo;
|
||||
} else if (strategy == 3) {
|
||||
} else if (strategy == FileRepeatEnum.NEW.code) {
|
||||
// 文件名加“_1”,版本号从100开始
|
||||
// 处理MySQL相关逻辑
|
||||
EdFileInfo newEdFileInfo = BeanUtil.copyProperties(srcFileInfo, EdFileInfo.class);
|
||||
|
|
@ -1125,11 +1133,10 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public EdFileInfo handUploadRepeatFile(String parentId, MultipartFile file, Integer strategy, int dataOwnCode) throws IOException {
|
||||
Assert.isTrue(Arrays.asList(1, 2, 3).contains(strategy), "解决同名文件参数错误");
|
||||
String fileName = file.getOriginalFilename();
|
||||
String mainName = FileUtil.mainName(fileName);
|
||||
String suffix = FileUtil.getSuffix(fileName);
|
||||
if (strategy == 2) {
|
||||
if (strategy == FileRepeatEnum.REVERSION.code) {
|
||||
// 版本更新
|
||||
// step1:找到同名文件的MySQL对象
|
||||
List<EdFileInfo> parentFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
|
|
@ -1173,7 +1180,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
|
||||
fileSystemService.save(file.getInputStream(), fileDestPath);
|
||||
return newEdFileInfo;
|
||||
} else if (strategy == 3) {
|
||||
} else if (strategy == FileRepeatEnum.NEW.code) {
|
||||
// 文件名加”_1“,存为新文件
|
||||
EdFileInfo parentFileInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getId, parentId)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import lombok.AllArgsConstructor;
|
|||
public enum FileRepeatEnum {
|
||||
|
||||
IGNORE(1, "跳过所有冲突文件"),
|
||||
VERSION(2, "所有冲突文件版本更新"),
|
||||
REVERSION(2, "所有冲突文件版本更新"),
|
||||
NEW(3, "重命名所有冲突文件, 文件后加“_1”");
|
||||
public int code;
|
||||
public String desc;
|
||||
|
|
@ -20,4 +20,13 @@ public enum FileRepeatEnum {
|
|||
return "";
|
||||
}
|
||||
|
||||
public static boolean contains(int code) {
|
||||
for (FileRepeatEnum e : FileRepeatEnum.values()) {
|
||||
if (e.code == code) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue