优化代码。
This commit is contained in:
parent
560b7b30c7
commit
7e4e8df1f4
|
|
@ -59,7 +59,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.*;
|
||||
import static com.electromagnetic.industry.software.common.enums.DataOwnEnum.USER_FILE;
|
||||
import static com.electromagnetic.industry.software.common.enums.FileRepeatEnum.IGNORE;
|
||||
import static com.electromagnetic.industry.software.common.enums.FileRepeatEnum.*;
|
||||
|
||||
@Service
|
||||
public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo> implements EdFileInfoService {
|
||||
|
|
@ -1061,7 +1061,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
|
||||
if (strategy == IGNORE.code) {
|
||||
return srcFileInfo;
|
||||
} else if (strategy == FileRepeatEnum.REVERSION.code) {
|
||||
} else if (strategy == REVERSION.code) {
|
||||
// 做版本更新
|
||||
List<EdFileInfo> sameFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.select(EdFileInfo.class, file -> !StrUtil.equals(file.getColumn(), "file_content"))
|
||||
|
|
@ -1088,7 +1088,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
||||
.eq(EdFileInfo::getId, fileInfoTmp.getId()));
|
||||
return destSaveFileInfo;
|
||||
} else {
|
||||
} else if (strategy == NEW.code) {
|
||||
// 文件名加“_1”,版本号从100开始
|
||||
// 处理MySQL相关逻辑
|
||||
EdFileInfo newEdFileInfo = BeanUtil.copyProperties(srcFileInfo, EdFileInfo.class);
|
||||
|
|
@ -1104,6 +1104,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
this.baseMapper.insert(newEdFileInfo);
|
||||
this.baseMapper.deleteById(srcFileInfo.getId());
|
||||
return newEdFileInfo;
|
||||
} else {
|
||||
throw new BizException("参数错误");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1147,7 +1149,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
String destPath = commonService.getFileSysPath(destFileInfo.getId());
|
||||
fileSystemService.copyFile(srcPath, destPath);
|
||||
} else {
|
||||
destFileInfo = handCopyConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo, dataOwnCode);
|
||||
destFileInfo = handCopyConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo);
|
||||
}
|
||||
UserThreadLocal.setSuccessInfo(destFileInfo.getParentId(), destFileInfo.getFileId(), "文件 {} 复制到 {},成功,处理文件同名同后缀的方式为 {},最终文件名为 {}", destFileInfo.getFileName() + "." + destFileInfo.getFileName(),
|
||||
commonService.getDbPath(destFolderInfo.getFilePath()), FileRepeatEnum.getDesc(strategy), srcFileInfo.getFileName());
|
||||
|
|
@ -1217,7 +1219,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
return ElectromagneticResultUtil.success(fileInfoVO);
|
||||
}
|
||||
|
||||
private EdFileInfo handCopyConflict(String targetFolderId, Integer strategy, EdFileInfo srcFileInfo, EdFileInfo destFolderInfo, int dataOwnCode) {
|
||||
private EdFileInfo handCopyConflict(String targetFolderId, Integer strategy, EdFileInfo srcFileInfo, EdFileInfo destFolderInfo) {
|
||||
// 禁止同目录下移动和复制
|
||||
if (srcFileInfo.getParentId().equals(destFolderInfo.getId())) {
|
||||
String info = "禁止相同文件夹下复制文件";
|
||||
|
|
@ -1228,7 +1230,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
if (strategy == IGNORE.code) {
|
||||
return destFolderInfo;
|
||||
}
|
||||
if (strategy == FileRepeatEnum.REVERSION.code) {
|
||||
if (strategy == REVERSION.code) {
|
||||
// 做版本更新
|
||||
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.select(EdFileInfo.class, file -> !StrUtil.equals(file.getColumn(), "file_content"))
|
||||
|
|
@ -1257,7 +1259,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
String destPath = commonService.getFileSysPath(destSaveFileInfo.getId());
|
||||
fileSystemService.copyFile(srcPath, destPath);
|
||||
return destSaveFileInfo;
|
||||
} else {
|
||||
} else if (strategy == FileRepeatEnum.NEW.code) {
|
||||
// 文件名加“_1”,版本号从100开始
|
||||
// 处理MySQL相关逻辑
|
||||
EdFileInfo newEdFileInfo = BeanUtil.copyProperties(srcFileInfo, EdFileInfo.class);
|
||||
|
|
@ -1274,6 +1276,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
String destPath = commonService.getFileSysPath(newEdFileInfo.getId());
|
||||
fileSystemService.copyFile(srcPath, destPath);
|
||||
return newEdFileInfo;
|
||||
} else {
|
||||
throw new BizException("参数错误");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1282,7 +1286,20 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
String fileName = file.getOriginalFilename();
|
||||
String mainName = FileUtil.mainName(fileName);
|
||||
String suffix = FileUtil.getSuffix(fileName);
|
||||
if (strategy == FileRepeatEnum.REVERSION.code) {
|
||||
EdFileInfo newEdFileInfo = new EdFileInfo();
|
||||
newEdFileInfo.newInit();
|
||||
String timeStr = EleCommonUtil.getNowTimeStr();
|
||||
newEdFileInfo.setFileName(mainName)
|
||||
.setFileType(suffix)
|
||||
.setFileContent(EleCommonUtil.parse(file.getInputStream(), suffix))
|
||||
.setFileTime(timeStr)
|
||||
.setFileSize(file.getSize())
|
||||
.setDataType(EleDataTypeEnum.FILE.code)
|
||||
.setDataStatus(PublishEnum.PUBLISHED.getCode())
|
||||
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
||||
.setDataOwn(dataOwnCode)
|
||||
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||
if (strategy == REVERSION.code) {
|
||||
// 版本更新
|
||||
// step1:找到同名文件的MySQL对象
|
||||
List<EdFileInfo> parentFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
|
|
@ -1296,70 +1313,44 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
// 找到当前展示的版本
|
||||
EdFileInfo effectFileInfo = parentFileInfos.stream().filter(e -> e.getEffectFlag().equals(EffectFlagEnum.EFFECT.code)).toList().get(0);
|
||||
String codePathByDbPath = commonService.getCodePathByDbPath(effectFileInfo.getFilePath());
|
||||
String timeStr = EleCommonUtil.getNowTimeStr();
|
||||
String fileCode = commonService.createFileCode(codePathByDbPath, suffix, FILE_START_VERSION, timeStr);
|
||||
// 将原有效的版本置为false
|
||||
this.baseMapper.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class)
|
||||
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
||||
.eq(EdFileInfo::getId, effectFileInfo.getId()));
|
||||
// 新增文件
|
||||
EdFileInfo newEdFileInfo = new EdFileInfo();
|
||||
newEdFileInfo.newInit();
|
||||
newEdFileInfo.setFileId(effectFileInfo.getFileId())
|
||||
.setParentId(parentId)
|
||||
.setFileCode(fileCode)
|
||||
.setFileName(mainName)
|
||||
.setFileType(suffix)
|
||||
.setFileVersion(maxFileVersion + 1)
|
||||
.setPreVersion(maxFileVersion)
|
||||
.setFileContent(EleCommonUtil.parse(file.getInputStream(), suffix))
|
||||
.setFileTime(timeStr)
|
||||
.setFileSize(file.getSize())
|
||||
.setFilePath(parentFileInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId())
|
||||
.setDataType(EleDataTypeEnum.FILE.code)
|
||||
.setDataStatus(PublishEnum.PUBLISHED.getCode())
|
||||
.setFileCode(fileCode)
|
||||
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
||||
.setDataOwn(dataOwnCode)
|
||||
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||
this.baseMapper.insert(newEdFileInfo);
|
||||
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getId());
|
||||
fileSystemService.save(file.getInputStream(), fileDestPath);
|
||||
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||
return newEdFileInfo;
|
||||
} else if (strategy == FileRepeatEnum.NEW.code) {
|
||||
.setFileCode(fileCode);
|
||||
} else if (strategy == NEW.code) {
|
||||
// 文件名加”_1“,存为新文件
|
||||
EdFileInfo parentFileInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getId, parentId)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
||||
String codePathByDbPath = commonService.getCodePathByDbPath(parentFileInfo.getFilePath());
|
||||
EdFileInfo newEdFileInfo = new EdFileInfo();
|
||||
newEdFileInfo.newInit();
|
||||
String fileCode = commonService.createFileCode(codePathByDbPath, suffix, FILE_START_VERSION, newEdFileInfo.getFileTime());
|
||||
newEdFileInfo.setParentId(parentId)
|
||||
.setFileCode(fileCode)
|
||||
.setFileName(mainName)
|
||||
.setFileType(suffix)
|
||||
.setFileContent(EleCommonUtil.parse(file.getInputStream(), suffix))
|
||||
.setFileVersion(FILE_START_VERSION)
|
||||
.setFileTime(newEdFileInfo.getFileTime())
|
||||
.setFileSize(file.getSize())
|
||||
.setFilePath(parentFileInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId())
|
||||
.setDataType(EleDataTypeEnum.FILE.code)
|
||||
.setDataStatus(PublishEnum.PUBLISHED.getCode())
|
||||
.setFileCode(fileCode)
|
||||
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
||||
.setDataOwn(dataOwnCode)
|
||||
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||
.setFileCode(fileCode);
|
||||
resetFileInfoName(newEdFileInfo);
|
||||
} else if (strategy == IGNORE.code) {
|
||||
return null;
|
||||
} else {
|
||||
throw new BizException("参数错误");
|
||||
}
|
||||
this.baseMapper.insert(newEdFileInfo);
|
||||
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getId());
|
||||
fileSystemService.save(file.getInputStream(), fileDestPath);
|
||||
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||
return newEdFileInfo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String doSysFileMerge(String identifier, String fileName, Integer totalChunks, int dataOwnCode) {
|
||||
String currentUserId = UserThreadLocal.getUserId();
|
||||
|
|
|
|||
Loading…
Reference in New Issue