优化代码
This commit is contained in:
parent
7e4e8df1f4
commit
2f1d15240e
|
|
@ -64,7 +64,6 @@ 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 {
|
||||||
|
|
||||||
private static final Map<String, List<String>> FILE_DB_ID_NAME = new ConcurrentHashMap<>();
|
|
||||||
private final EleLog log = new EleLog(EdFileInfoServiceImpl.class);
|
private final EleLog log = new EleLog(EdFileInfoServiceImpl.class);
|
||||||
@Resource
|
@Resource
|
||||||
private CommonService commonService;
|
private CommonService commonService;
|
||||||
|
|
@ -533,10 +532,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
if (foldersMap.get(fileName).getId().equals(edFileInfo.getId())) { // id相同,不做处理
|
if (foldersMap.get(fileName).getId().equals(edFileInfo.getId())) { // id相同,不做处理
|
||||||
log.info("id相同,不做处理");
|
log.info("id相同,不做处理");
|
||||||
} else { // 文件名重复,导入的文件名需要添加“_1”
|
} else { // 文件名重复,导入的文件名需要添加“_1”
|
||||||
String previousName = edFileInfo.getFileName();
|
|
||||||
resetFolderInfo(edFileInfo);
|
resetFolderInfo(edFileInfo);
|
||||||
String afterName = edFileInfo.getFileName();
|
|
||||||
FILE_DB_ID_NAME.put(edFileInfo.getId(), List.of(previousName, afterName));
|
|
||||||
allObjs.add(edFileInfo);
|
allObjs.add(edFileInfo);
|
||||||
}
|
}
|
||||||
} else { // 没有同名文件夹
|
} else { // 没有同名文件夹
|
||||||
|
|
@ -558,10 +554,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
// 在线上没有找到,则该批文件是从线下上传的
|
// 在线上没有找到,则该批文件是从线下上传的
|
||||||
if (CollUtil.isEmpty(dbFileInfos)) {
|
if (CollUtil.isEmpty(dbFileInfos)) {
|
||||||
EdFileInfo fileInfo = importFiles.stream().filter(e -> e.getEffectFlag().equals(EffectFlagEnum.EFFECT.code)).findFirst().get();
|
EdFileInfo fileInfo = importFiles.stream().filter(e -> e.getEffectFlag().equals(EffectFlagEnum.EFFECT.code)).findFirst().get();
|
||||||
String previousName = fileInfo.getFileName();
|
|
||||||
resetFileInfoName(fileInfo);
|
resetFileInfoName(fileInfo);
|
||||||
String afterName = fileInfo.getFileName();
|
|
||||||
FILE_DB_ID_NAME.put(fileInfo.getId(), List.of(previousName, afterName));
|
|
||||||
allObjs.addAll(importFiles);
|
allObjs.addAll(importFiles);
|
||||||
allObjs.add(fileInfo);
|
allObjs.add(fileInfo);
|
||||||
// 线下和线上都存在
|
// 线下和线上都存在
|
||||||
|
|
@ -694,46 +687,14 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
|
|
||||||
private void update2FileSystem(Set<EdFileInfo> needMove2FileSystemFiles, String prjDirPath, int dataOwnCode) {
|
private void update2FileSystem(Set<EdFileInfo> needMove2FileSystemFiles, String prjDirPath, int dataOwnCode) {
|
||||||
List<EdFileInfo> files = needMove2FileSystemFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FILE.code)).toList();
|
List<EdFileInfo> files = needMove2FileSystemFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FILE.code)).toList();
|
||||||
|
List<File> files1 = FileUtil.loopFiles(new File(prjDirPath), file -> file.isDirectory() && file.getName().startsWith(EXPORT_PRJ_NAME));
|
||||||
|
String prjFilePath = files1.get(0).getAbsolutePath();
|
||||||
for (EdFileInfo edFileInfo : files) {
|
for (EdFileInfo edFileInfo : files) {
|
||||||
String filePath = edFileInfo.getFilePath();
|
String id = edFileInfo.getId();
|
||||||
String previousFileName = FILE_DB_ID_NAME.containsKey(edFileInfo.getId()) ?
|
String sourcePath = prjFilePath + File.separator + id;
|
||||||
FILE_DB_ID_NAME.get(edFileInfo.getId()).get(0) :
|
String destPath = commonService.getPrjRootPath1(dataOwnCode) + File.separator + id;
|
||||||
edFileInfo.getFileName();
|
fileSystemService.moveFile(sourcePath, destPath);
|
||||||
String afterFileName = FILE_DB_ID_NAME.containsKey(edFileInfo.getId()) ?
|
log.info("file import to file system source path is ----> {}, dest path is --->{}", sourcePath, destPath);
|
||||||
FILE_DB_ID_NAME.get(edFileInfo.getId()).get(1) :
|
|
||||||
edFileInfo.getFileName();
|
|
||||||
|
|
||||||
StringBuilder sysFileDirPath = new StringBuilder();
|
|
||||||
StringBuilder destDirPath = new StringBuilder();
|
|
||||||
|
|
||||||
for (String id : filePath.split(MYSQL_FILE_PATH_SPLIT)) {
|
|
||||||
EdFileInfo fileInfo = this.baseMapper.selectById(id);
|
|
||||||
if (fileInfo.getDataType().equals(EleDataTypeEnum.FOLDER.code)) {
|
|
||||||
String previousDirName = FILE_DB_ID_NAME.containsKey(id) ?
|
|
||||||
FILE_DB_ID_NAME.get(id).get(0) : fileInfo.getFileName();
|
|
||||||
sysFileDirPath.append(previousDirName).append(File.separator);
|
|
||||||
String afterDirName = FILE_DB_ID_NAME.containsKey(id) ?
|
|
||||||
FILE_DB_ID_NAME.get(id).get(1) : fileInfo.getFileName();
|
|
||||||
destDirPath.append(afterDirName).append(File.separator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String sourcePath = prjDirPath + File.separator + sysFileDirPath + previousFileName + "." + edFileInfo.getFileType() + "." + edFileInfo.getFileCode();
|
|
||||||
String destPath;
|
|
||||||
if (DataOwnEnum.isUserCode(dataOwnCode)) {
|
|
||||||
destPath = commonService.getPrjRootPath1(dataOwnCode) +
|
|
||||||
UserThreadLocal.getUserId() + File.separator +
|
|
||||||
destDirPath + File.separator + sysFileDirPath +
|
|
||||||
afterFileName +
|
|
||||||
"." + edFileInfo.getFileType() +
|
|
||||||
"." + edFileInfo.getFileCode();
|
|
||||||
} else {
|
|
||||||
destPath = commonService.getPrjRootPath1(dataOwnCode) + File.separator +
|
|
||||||
destDirPath + File.separator +
|
|
||||||
afterFileName +
|
|
||||||
"." + edFileInfo.getFileType() +
|
|
||||||
"." + edFileInfo.getFileCode();
|
|
||||||
}
|
|
||||||
log.info("source path is ----> {}, dest path is --->{}", sourcePath, destPath);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,11 @@ public class FileSystemServiceImpl implements FileSystemService {
|
||||||
FileUtil.copy(source, destination, true);
|
FileUtil.copy(source, destination, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param source /user/aaa/bbb.txt
|
||||||
|
* @param destination /user/bbb/aaa.txt
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void moveFile(String source, String destination) {
|
public void moveFile(String source, String destination) {
|
||||||
String destParentDir = FileUtil.getParent(destination, 1);
|
String destParentDir = FileUtil.getParent(destination, 1);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue