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