|
|
|
@ -151,7 +151,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
public ElectromagneticResult<?> delete(String id) {
|
|
|
|
public ElectromagneticResult<?> delete(String id) {
|
|
|
|
EdFileInfo fileInfo = this.baseMapper.selectById(id);
|
|
|
|
EdFileInfo fileInfo = this.baseMapper.selectById(id);
|
|
|
|
String parentId = fileInfo.getParentId();
|
|
|
|
String parentId = fileInfo.getParentId();
|
|
|
|
if (fileInfo.getDataType() == 0) {
|
|
|
|
if (fileInfo.getDataType() == EleDataTypeEnum.FOLDER.code) {
|
|
|
|
return commonService.deleteFolder(id, parentId);
|
|
|
|
return commonService.deleteFolder(id, parentId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -171,7 +171,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
EdFileInfo fileInfo = this.baseMapper.selectOne(Wrappers.<EdFileInfo>lambdaQuery().eq(EdFileInfo::getId, id));
|
|
|
|
EdFileInfo fileInfo = this.baseMapper.selectOne(Wrappers.<EdFileInfo>lambdaQuery().eq(EdFileInfo::getId, id));
|
|
|
|
String fileSysPath = commonService.getFileSysPath(fileInfo.getFilePath()) + "." + fileInfo.getFileCode();
|
|
|
|
String fileSysPath = commonService.getFileSysPath(fileInfo.getFilePath());
|
|
|
|
Assert.isTrue(FileUtil.exist(fileSysPath), "下载文件不存在。");
|
|
|
|
Assert.isTrue(FileUtil.exist(fileSysPath), "下载文件不存在。");
|
|
|
|
FileSystemResource fileSystemResource = new FileSystemResource(fileSysPath);
|
|
|
|
FileSystemResource fileSystemResource = new FileSystemResource(fileSysPath);
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
@ -207,7 +207,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
.eq(EdFileInfo::getId, updateFileInfoDTO.getId())
|
|
|
|
.eq(EdFileInfo::getId, updateFileInfoDTO.getId())
|
|
|
|
.set(EdFileInfo::getFileName, updateFileInfoDTO.getFileName())
|
|
|
|
.set(EdFileInfo::getFileName, updateFileInfoDTO.getFileName())
|
|
|
|
.set(EdFileInfo::getFileNote, updateFileInfoDTO.getFileNote()));
|
|
|
|
.set(EdFileInfo::getFileNote, updateFileInfoDTO.getFileNote()));
|
|
|
|
String sysFilePath = commonService.getFileSysPath(fileInfo.getFilePath());
|
|
|
|
String sysFilePath = commonService.getFileSysPath(fileInfo.getFilePath()); // file or folder
|
|
|
|
fileSystemService.renameFile(sysFilePath, updateFileInfoDTO.getFileName());
|
|
|
|
fileSystemService.renameFile(sysFilePath, updateFileInfoDTO.getFileName());
|
|
|
|
return ElectromagneticResultUtil.success(true);
|
|
|
|
return ElectromagneticResultUtil.success(true);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
@ -458,7 +458,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String destPath = commonService.getEleDataPath() + File.separator + sysFilePath;
|
|
|
|
String destPath = commonService.getEleDataPath() + File.separator + sysFilePath;
|
|
|
|
String sourcePath = prjDirPath + File.separator + sysFilePath;
|
|
|
|
String sourcePath = prjDirPath + File.separator + sysFilePath;
|
|
|
|
fileSystemService.moveFile(sourcePath, destPath, true);
|
|
|
|
fileSystemService.moveFile(sourcePath, destPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -506,11 +506,11 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
List<EdFileInfo> folders = resFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FOLDER.code)).collect(Collectors.toList());
|
|
|
|
List<EdFileInfo> folders = resFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FOLDER.code)).collect(Collectors.toList());
|
|
|
|
List<EdFileInfo> files = resFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FILE.code)).collect(Collectors.toList());
|
|
|
|
List<EdFileInfo> files = resFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FILE.code)).collect(Collectors.toList());
|
|
|
|
for (EdFileInfo edFileInfo : folders) {
|
|
|
|
for (EdFileInfo edFileInfo : folders) {
|
|
|
|
String destFolderPath = downloadDataDir + File.separator + prjName + File.separator + commonService.getFileSysPath(edFileInfo.getFileId());
|
|
|
|
String destFolderPath = downloadDataDir + File.separator + prjName + File.separator + commonService.getFileSysPath(edFileInfo.getFileId()); // file
|
|
|
|
fileSystemService.createDirectory(destFolderPath);
|
|
|
|
fileSystemService.createDirectory(destFolderPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (EdFileInfo edFileInfo : files) {
|
|
|
|
for (EdFileInfo edFileInfo : files) {
|
|
|
|
String filePath = commonService.getFileSysPath(edFileInfo.getFileId()) + edFileInfo.getFileCode() + "." + edFileInfo.getFileCode();
|
|
|
|
String filePath = commonService.getFileSysPath(edFileInfo.getFileId()); // file
|
|
|
|
String destPath = downloadDataDir + File.separator + prjName + File.separator + commonService.getDbPath(edFileInfo.getFileId());
|
|
|
|
String destPath = downloadDataDir + File.separator + prjName + File.separator + commonService.getDbPath(edFileInfo.getFileId());
|
|
|
|
fileSystemService.copyFile(filePath, destPath);
|
|
|
|
fileSystemService.copyFile(filePath, destPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -597,7 +597,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
|
|
|
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
|
|
|
.setPrjDir(false);
|
|
|
|
.setPrjDir(false);
|
|
|
|
this.baseMapper.insert(newEdFileInfo);
|
|
|
|
this.baseMapper.insert(newEdFileInfo);
|
|
|
|
String fileDestPath = commonService.getFileSysPath(parentFolderInfo.getFilePath()) + File.separator + mainName + "." + suffix + "." + fileCode;
|
|
|
|
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath());
|
|
|
|
fileSystemService.save(file.getInputStream(), fileDestPath);
|
|
|
|
fileSystemService.save(file.getInputStream(), fileDestPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
@ -633,10 +633,50 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public ElectromagneticResult<?> moveFile(String id, String targetFolderId, Integer strategy) {
|
|
|
|
public ElectromagneticResult<?> moveFile(String id, String targetFolderId, Integer strategy) {
|
|
|
|
return moveFile(id, targetFolderId, strategy, true);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取原文件mysql模型
|
|
|
|
|
|
|
|
EdFileInfo srcFileInfo = this.baseMapper.selectById(id);
|
|
|
|
|
|
|
|
String srcFileDbPath = srcFileInfo.getFilePath();
|
|
|
|
|
|
|
|
String fileCode = srcFileInfo.getFileCode();
|
|
|
|
|
|
|
|
// 判断目标路径下是否有同名文件,如果所有的同名文件:1)如果所有文件都已经被作废,则该文件为新文件,版本号从100开始。2)如果有没有被作废的文件,则冲突处理方式按---1-跳过冲突文件 2-做版本更新 3-重命名,文件名加"_1"
|
|
|
|
|
|
|
|
long count = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getParentId, targetFolderId)
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getFileName, srcFileInfo.getFileName())
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getFileType, srcFileInfo.getFileType())
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
|
|
|
|
|
|
|
EdFileInfo destFolderInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getId, targetFolderId));
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
|
|
|
|
// 没有同名文件
|
|
|
|
|
|
|
|
// 首先将信息保存到MySQL
|
|
|
|
|
|
|
|
String fileTime = EleCommonUtil.getNowTimeStr();
|
|
|
|
|
|
|
|
String codePathByDbPath = commonService.getCodePathByDbPath(destFolderInfo.getFilePath());
|
|
|
|
|
|
|
|
String newFileCode = commonService.createFileCode(codePathByDbPath, srcFileInfo.getFileType(), FILE_START_VERSION, fileTime);
|
|
|
|
|
|
|
|
srcFileInfo.setParentId(targetFolderId)
|
|
|
|
|
|
|
|
.setFileVersion(FILE_START_VERSION)
|
|
|
|
|
|
|
|
.setFileTime(fileTime)
|
|
|
|
|
|
|
|
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + srcFileInfo.getId())
|
|
|
|
|
|
|
|
.setFileCode(newFileCode);
|
|
|
|
|
|
|
|
this.baseMapper.updateById(srcFileInfo);
|
|
|
|
|
|
|
|
// 文件系统移动文件
|
|
|
|
|
|
|
|
String srcFilePath = commonService.getFileSysPath(srcFileDbPath);
|
|
|
|
|
|
|
|
String destFilePath = commonService.getFileSysPath(destFolderInfo.getFilePath());
|
|
|
|
|
|
|
|
fileSystemService.moveFile(srcFilePath, destFilePath);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return handMoveConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ElectromagneticResultUtil.success(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ElectromagneticResult<?> handMoveConflict(String targetFolderId, Integer strategy, EdFileInfo srcFileInfo, EdFileInfo destFolderInfo) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 禁止同目录下移动和复制
|
|
|
|
|
|
|
|
if (srcFileInfo.getParentId().equals(destFolderInfo.getId())) {
|
|
|
|
|
|
|
|
String info = "禁止相同文件夹下移动文件";
|
|
|
|
|
|
|
|
log.info(info);
|
|
|
|
|
|
|
|
return ElectromagneticResultUtil.fail("-1", info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void handMoveConflict(String targetFolderId, Integer strategy, EdFileInfo srcFileInfo, EdFileInfo destFolderInfo, boolean deleteSrc) {
|
|
|
|
|
|
|
|
if (strategy == 2) {
|
|
|
|
if (strategy == 2) {
|
|
|
|
// 做版本更新
|
|
|
|
// 做版本更新
|
|
|
|
List<EdFileInfo> sameFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
List<EdFileInfo> sameFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
@ -646,69 +686,44 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
Integer maxFileVersion = Collections.max(sameFileInfos, Comparator.comparing(EdFileInfo::getFileVersion)).getFileVersion();
|
|
|
|
Integer maxFileVersion = Collections.max(sameFileInfos, Comparator.comparing(EdFileInfo::getFileVersion)).getFileVersion();
|
|
|
|
String newFileDbId = IdWorker.getSnowFlakeIdString();
|
|
|
|
String newFileDbId = IdWorker.getSnowFlakeIdString();
|
|
|
|
String fileTime = EleCommonUtil.getNowTimeStr();
|
|
|
|
String fileTime = EleCommonUtil.getNowTimeStr();
|
|
|
|
String fileCode = commonService.createFileCode(targetFolderId, srcFileInfo.getFileType(), maxFileVersion + 1, fileTime);
|
|
|
|
String codePathByDbPath = commonService.getCodePathByDbPath(destFolderInfo.getFilePath());
|
|
|
|
EdFileInfo destSaveFileInfo = BeanUtil.copyProperties(sameFileInfos.get(0), EdFileInfo.class);
|
|
|
|
String fileCode = commonService.createFileCode(codePathByDbPath, srcFileInfo.getFileType(), maxFileVersion + 1, fileTime);
|
|
|
|
destSaveFileInfo.newInit();
|
|
|
|
EdFileInfo fileInfoTmp = sameFileInfos.stream().filter(e -> e.getEffectFlag().equals(EffectFlagEnum.EFFECT.code)).findFirst().orElseThrow(RuntimeException::new);
|
|
|
|
|
|
|
|
EdFileInfo destSaveFileInfo = BeanUtil.copyProperties(fileInfoTmp, EdFileInfo.class);
|
|
|
|
|
|
|
|
destSaveFileInfo.setId(newFileDbId);
|
|
|
|
destSaveFileInfo.setFileVersion(maxFileVersion + 1)
|
|
|
|
destSaveFileInfo.setFileVersion(maxFileVersion + 1)
|
|
|
|
.setFilePath(destSaveFileInfo + MYSQL_FILE_PATH_SPLIT + newFileDbId)
|
|
|
|
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newFileDbId)
|
|
|
|
.setPreVersion(maxFileVersion)
|
|
|
|
.setPreVersion(maxFileVersion)
|
|
|
|
.setEffectFlag(EffectFlagEnum.EFFECT.code)
|
|
|
|
.setEffectFlag(EffectFlagEnum.EFFECT.code)
|
|
|
|
.setFileCode(fileCode);
|
|
|
|
.setFileCode(fileCode);
|
|
|
|
this.baseMapper.insert(destSaveFileInfo);
|
|
|
|
this.baseMapper.insert(destSaveFileInfo);
|
|
|
|
|
|
|
|
String srcFilePath = commonService.getFileSysPath(srcFileInfo.getFilePath());
|
|
|
|
|
|
|
|
String destFilePath = commonService.getFileSysPath(destSaveFileInfo.getFilePath());
|
|
|
|
|
|
|
|
fileSystemService.copyFile(srcFilePath, destFilePath);
|
|
|
|
|
|
|
|
this.baseMapper.deleteById(srcFileInfo.getId());
|
|
|
|
|
|
|
|
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
|
|
|
|
|
|
|
|
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getId, fileInfoTmp.getId()));
|
|
|
|
} else if (strategy == 3) {
|
|
|
|
} else if (strategy == 3) {
|
|
|
|
// 文件名加“_1”,版本号从100开始
|
|
|
|
// 文件名加“_1”,版本号从100开始
|
|
|
|
// 处理MySQL相关逻辑
|
|
|
|
// 处理MySQL相关逻辑
|
|
|
|
EdFileInfo newEdFileInfo = BeanUtil.copyProperties(srcFileInfo, EdFileInfo.class);
|
|
|
|
EdFileInfo newEdFileInfo = BeanUtil.copyProperties(srcFileInfo, EdFileInfo.class);
|
|
|
|
newEdFileInfo.newInit();
|
|
|
|
newEdFileInfo.newInit();
|
|
|
|
|
|
|
|
String dbPathByDbPath = commonService.getCodePathByDbPath(destFolderInfo.getFilePath());
|
|
|
|
newEdFileInfo.setParentId(targetFolderId)
|
|
|
|
newEdFileInfo.setParentId(targetFolderId)
|
|
|
|
.setFileVersion(FILE_START_VERSION)
|
|
|
|
.setFileVersion(FILE_START_VERSION)
|
|
|
|
.setFileName(srcFileInfo.getFileName() + "_1")
|
|
|
|
.setFileName(srcFileInfo.getFileName() + "_1")
|
|
|
|
.setFileCode(commonService.createFileCode(targetFolderId, srcFileInfo.getFileType(), FILE_START_VERSION, newEdFileInfo.getFileTime()))
|
|
|
|
.setFileCode(commonService.createFileCode(dbPathByDbPath, srcFileInfo.getFileType(), FILE_START_VERSION, newEdFileInfo.getFileTime()))
|
|
|
|
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId());
|
|
|
|
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId());
|
|
|
|
|
|
|
|
resetFileInfoName(newEdFileInfo);
|
|
|
|
this.baseMapper.insert(newEdFileInfo);
|
|
|
|
this.baseMapper.insert(newEdFileInfo);
|
|
|
|
// 移动文件
|
|
|
|
// 移动文件
|
|
|
|
String srcFileSysPath = commonService.getFileSysPath(srcFileInfo.getFilePath());
|
|
|
|
String srcFileSysPath = commonService.getFileSysPath(srcFileInfo.getFilePath());
|
|
|
|
String destFileSysPath = commonService.getFileSysPath(destFolderInfo.getFilePath());
|
|
|
|
String destFileSysPath = commonService.getFileSysPath(newEdFileInfo.getFilePath());
|
|
|
|
fileSystemService.moveFile(srcFileSysPath, destFileSysPath, deleteSrc);
|
|
|
|
fileSystemService.moveFile(srcFileSysPath, destFileSysPath);
|
|
|
|
|
|
|
|
this.baseMapper.deleteById(srcFileInfo.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ElectromagneticResultUtil.success(true);
|
|
|
|
|
|
|
|
|
|
|
|
private ElectromagneticResult<?> moveFile(String id, String targetFolderId, Integer strategy, boolean deleteSrc) {
|
|
|
|
|
|
|
|
// 获取原文件mysql模型
|
|
|
|
|
|
|
|
EdFileInfo srcFileInfo = this.baseMapper.selectById(id);
|
|
|
|
|
|
|
|
// 判断目标路径下是否有同名文件,如果所有的同名文件:1)如果所有文件都已经被作废,则该文件为新文件,版本号从100开始。2)如果有没有被作废的文件,则冲突处理方式按---1-跳过冲突文件 2-做版本更新 3-重命名,文件名加"_1"
|
|
|
|
|
|
|
|
List<EdFileInfo> destFolderFiles = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getParentId, targetFolderId));
|
|
|
|
|
|
|
|
EdFileInfo destFolderInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getId, targetFolderId));
|
|
|
|
|
|
|
|
List<EdFileInfo> effectFileInfos = destFolderFiles.stream().filter(e -> Objects.equals(e.getEffectFlag(), EffectFlagEnum.EFFECT.code)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(effectFileInfos) || CollUtil.isEmpty(destFolderFiles)) {
|
|
|
|
|
|
|
|
// 没有同名文件
|
|
|
|
|
|
|
|
// 首先将信息保存到MySQL
|
|
|
|
|
|
|
|
EdFileInfo destSaveFileInfo = BeanUtil.copyProperties(srcFileInfo, EdFileInfo.class);
|
|
|
|
|
|
|
|
destSaveFileInfo.newInit();
|
|
|
|
|
|
|
|
String fileTime = EleCommonUtil.getNowTimeStr();
|
|
|
|
|
|
|
|
String newFileCode = commonService.createFileCode(targetFolderId, srcFileInfo.getFileType(), FILE_START_VERSION, fileTime);
|
|
|
|
|
|
|
|
destSaveFileInfo.setParentId(targetFolderId)
|
|
|
|
|
|
|
|
.setFileVersion(FILE_START_VERSION)
|
|
|
|
|
|
|
|
.setFileTime(fileTime)
|
|
|
|
|
|
|
|
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + destSaveFileInfo.getId())
|
|
|
|
|
|
|
|
.setFileCode(newFileCode);
|
|
|
|
|
|
|
|
this.baseMapper.insert(destSaveFileInfo);
|
|
|
|
|
|
|
|
// 文件系统移动文件
|
|
|
|
|
|
|
|
String srcFilePath = commonService.getFileSysPath(srcFileInfo.getFileId()) + File.separator + srcFileInfo.getFileCode();
|
|
|
|
|
|
|
|
String destFilePath = commonService.getFileSysPath(destFolderInfo.getFileId()) + File.separator + destFolderInfo.getFileCode();
|
|
|
|
|
|
|
|
fileSystemService.moveFile(srcFilePath, destFilePath, deleteSrc);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
handMoveConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo, deleteSrc);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 将以前的版本effect全部置为false,删除原目录下的同名文件
|
|
|
|
|
|
|
|
if (deleteSrc) {
|
|
|
|
|
|
|
|
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
|
|
|
|
|
|
|
|
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getParentId, srcFileInfo.getParentId())
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getFileName, srcFileInfo.getFileName())
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getFileType, srcFileInfo.getFileType()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -719,7 +734,91 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ElectromagneticResult<?> copyFile(String id, String targetFolderId, Integer strategy) {
|
|
|
|
public ElectromagneticResult<?> copyFile(String id, String targetFolderId, Integer strategy) {
|
|
|
|
return moveFile(id, targetFolderId, strategy, false);
|
|
|
|
// 获取原文件mysql模型
|
|
|
|
|
|
|
|
EdFileInfo srcFileInfo = this.baseMapper.selectById(id);
|
|
|
|
|
|
|
|
String srcFileDbPath = srcFileInfo.getFilePath();
|
|
|
|
|
|
|
|
// 判断目标路径下是否有同名文件,如果所有的同名文件:1)如果所有文件都已经被作废,则该文件为新文件,版本号从100开始。2)如果有没有被作废的文件,则冲突处理方式按---1-跳过冲突文件 2-做版本更新 3-重命名,文件名加"_1"
|
|
|
|
|
|
|
|
long count = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getParentId, targetFolderId)
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getFileName, srcFileInfo.getFileName())
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getFileType, srcFileInfo.getFileType())
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
|
|
|
|
|
|
|
EdFileInfo destFolderInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getId, targetFolderId));
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
|
|
|
|
// 没有同名文件
|
|
|
|
|
|
|
|
// 首先将信息保存到MySQL
|
|
|
|
|
|
|
|
String fileTime = EleCommonUtil.getNowTimeStr();
|
|
|
|
|
|
|
|
String codePathByDbPath = commonService.getCodePathByDbPath(destFolderInfo.getFilePath());
|
|
|
|
|
|
|
|
String newFileCode = commonService.createFileCode(codePathByDbPath, srcFileInfo.getFileType(), FILE_START_VERSION, fileTime);
|
|
|
|
|
|
|
|
EdFileInfo destFileInfo = BeanUtil.copyProperties(srcFileInfo, EdFileInfo.class);
|
|
|
|
|
|
|
|
destFileInfo.newInit();
|
|
|
|
|
|
|
|
destFileInfo.setParentId(targetFolderId)
|
|
|
|
|
|
|
|
.setFileVersion(FILE_START_VERSION)
|
|
|
|
|
|
|
|
.setFileTime(fileTime)
|
|
|
|
|
|
|
|
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + destFileInfo.getId())
|
|
|
|
|
|
|
|
.setFileCode(newFileCode);
|
|
|
|
|
|
|
|
this.baseMapper.insert(destFileInfo);
|
|
|
|
|
|
|
|
// 文件系统移动文件
|
|
|
|
|
|
|
|
String srcFilePath = commonService.getFileSysPath(srcFileDbPath);
|
|
|
|
|
|
|
|
String destFilePath = commonService.getFileSysPath(destFileInfo.getFilePath());
|
|
|
|
|
|
|
|
fileSystemService.copyFile(srcFilePath, destFilePath);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return handCopyConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ElectromagneticResultUtil.success(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ElectromagneticResult<?> handCopyConflict(String targetFolderId, Integer strategy, EdFileInfo srcFileInfo, EdFileInfo destFolderInfo) {
|
|
|
|
|
|
|
|
// 禁止同目录下移动和复制
|
|
|
|
|
|
|
|
if (srcFileInfo.getParentId().equals(destFolderInfo.getId())) {
|
|
|
|
|
|
|
|
String info = "禁止相同文件夹下移动文件";
|
|
|
|
|
|
|
|
log.info(info);
|
|
|
|
|
|
|
|
return ElectromagneticResultUtil.fail("-1", info);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (strategy == 2) {
|
|
|
|
|
|
|
|
// 做版本更新
|
|
|
|
|
|
|
|
List<EdFileInfo> sameFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getParentId, targetFolderId)
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getFileName, srcFileInfo.getFileName())
|
|
|
|
|
|
|
|
.eq(EdFileInfo::getFileType, srcFileInfo.getFileType()));
|
|
|
|
|
|
|
|
Integer maxFileVersion = Collections.max(sameFileInfos, Comparator.comparing(EdFileInfo::getFileVersion)).getFileVersion();
|
|
|
|
|
|
|
|
String newFileDbId = IdWorker.getSnowFlakeIdString();
|
|
|
|
|
|
|
|
String fileTime = EleCommonUtil.getNowTimeStr();
|
|
|
|
|
|
|
|
String codePathByDbPath = commonService.getCodePathByDbPath(destFolderInfo.getFilePath());
|
|
|
|
|
|
|
|
String fileCode = commonService.createFileCode(codePathByDbPath, srcFileInfo.getFileType(), maxFileVersion + 1, fileTime);
|
|
|
|
|
|
|
|
EdFileInfo fileInfoTmp = sameFileInfos.stream().filter(e -> e.getEffectFlag().equals(EffectFlagEnum.EFFECT.code)).findFirst().orElseThrow(RuntimeException::new);
|
|
|
|
|
|
|
|
EdFileInfo destSaveFileInfo = BeanUtil.copyProperties(fileInfoTmp, EdFileInfo.class);
|
|
|
|
|
|
|
|
destSaveFileInfo.setId(newFileDbId);
|
|
|
|
|
|
|
|
destSaveFileInfo.setFileVersion(maxFileVersion + 1)
|
|
|
|
|
|
|
|
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newFileDbId)
|
|
|
|
|
|
|
|
.setPreVersion(maxFileVersion)
|
|
|
|
|
|
|
|
.setEffectFlag(EffectFlagEnum.EFFECT.code)
|
|
|
|
|
|
|
|
.setFileCode(fileCode);
|
|
|
|
|
|
|
|
this.baseMapper.insert(destSaveFileInfo);
|
|
|
|
|
|
|
|
String srcFilePath = commonService.getFileSysPath(srcFileInfo.getFilePath());
|
|
|
|
|
|
|
|
String destFilePath = commonService.getFileSysPath(destSaveFileInfo.getFilePath());
|
|
|
|
|
|
|
|
fileSystemService.copyFile(srcFilePath, destFilePath);
|
|
|
|
|
|
|
|
} else if (strategy == 3) {
|
|
|
|
|
|
|
|
// 文件名加“_1”,版本号从100开始
|
|
|
|
|
|
|
|
// 处理MySQL相关逻辑
|
|
|
|
|
|
|
|
EdFileInfo newEdFileInfo = BeanUtil.copyProperties(srcFileInfo, EdFileInfo.class);
|
|
|
|
|
|
|
|
newEdFileInfo.newInit();
|
|
|
|
|
|
|
|
String dbPathByDbPath = commonService.getCodePathByDbPath(destFolderInfo.getFilePath());
|
|
|
|
|
|
|
|
newEdFileInfo.setParentId(targetFolderId)
|
|
|
|
|
|
|
|
.setFileVersion(FILE_START_VERSION)
|
|
|
|
|
|
|
|
.setFileName(srcFileInfo.getFileName() + "_1")
|
|
|
|
|
|
|
|
.setFileCode(commonService.createFileCode(dbPathByDbPath, srcFileInfo.getFileType(), FILE_START_VERSION, newEdFileInfo.getFileTime()))
|
|
|
|
|
|
|
|
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId());
|
|
|
|
|
|
|
|
resetFileInfoName(newEdFileInfo);
|
|
|
|
|
|
|
|
this.baseMapper.insert(newEdFileInfo);
|
|
|
|
|
|
|
|
// 移动文件
|
|
|
|
|
|
|
|
String srcFileSysPath = commonService.getFileSysPath(srcFileInfo.getFilePath());
|
|
|
|
|
|
|
|
String destFileSysPath = commonService.getFileSysPath(newEdFileInfo.getFilePath());
|
|
|
|
|
|
|
|
fileSystemService.copyFile(srcFileSysPath, destFileSysPath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ElectromagneticResultUtil.success(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@ -770,7 +869,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
|
|
|
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
|
|
|
.setPrjDir(false);
|
|
|
|
.setPrjDir(false);
|
|
|
|
this.baseMapper.insert(newEdFileInfo);
|
|
|
|
this.baseMapper.insert(newEdFileInfo);
|
|
|
|
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath()) + File.separator + mainName + "." + suffix + "." + fileCode;
|
|
|
|
String fileDestPath = commonService.getFileSysPath(parentFileInfo.getFilePath());
|
|
|
|
fileSystemService.save(file.getInputStream(), fileDestPath);
|
|
|
|
fileSystemService.save(file.getInputStream(), fileDestPath);
|
|
|
|
} else if (strategy == 3) {
|
|
|
|
} else if (strategy == 3) {
|
|
|
|
// 文件名加”_1“,存为新文件
|
|
|
|
// 文件名加”_1“,存为新文件
|
|
|
|
@ -797,13 +896,12 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
.setPrjDir(false);
|
|
|
|
.setPrjDir(false);
|
|
|
|
resetFileInfoName(newEdFileInfo);
|
|
|
|
resetFileInfoName(newEdFileInfo);
|
|
|
|
this.baseMapper.insert(newEdFileInfo);
|
|
|
|
this.baseMapper.insert(newEdFileInfo);
|
|
|
|
String fileDestPath = commonService.getFileSysPath(parentFileInfo.getFilePath()) + File.separator + newEdFileInfo.getFileName() + "." + suffix + "." + fileCode;
|
|
|
|
String fileDestPath = commonService.getFileSysPath(parentFileInfo.getFilePath());
|
|
|
|
fileSystemService.save(file.getInputStream(), fileDestPath);
|
|
|
|
fileSystemService.save(file.getInputStream(), fileDestPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String doSysFileMerge(String identifier, String fileName, Integer totalChunks) {
|
|
|
|
private String doSysFileMerge(String identifier, String fileName, Integer totalChunks) {
|
|
|
|
String currentUserId = UserThreadLocal.getUserId();
|
|
|
|
String currentUserId = UserThreadLocal.getUserId();
|
|
|
|
for (int i = 1; i <= totalChunks; i++) {
|
|
|
|
for (int i = 1; i <= totalChunks; i++) {
|
|
|
|
|