解决部分问题
This commit is contained in:
parent
d0187511bc
commit
ccb61bfa40
|
|
@ -247,8 +247,6 @@ public class CommonService {
|
|||
}));
|
||||
String jsonStr = JSONUtil.toJsonStr(trees);
|
||||
projectVOS.add(jsonStr);
|
||||
// ProjectVO projectVO = JSONUtil.toList(jsonStr, ProjectVO.class).get(0);
|
||||
// projectVOS.add(projectVO);
|
||||
} else {
|
||||
TreeNodeConfig config = new TreeNodeConfig();
|
||||
config.setIdKey(FileProjectVO.Fields.categoryId);
|
||||
|
|
@ -263,8 +261,6 @@ public class CommonService {
|
|||
}));
|
||||
String jsonStr = JSONUtil.toJsonStr(trees);
|
||||
projectVOS.add(jsonStr);
|
||||
// FileProjectVO fileProjectVO = JSONUtil.toList(jsonStr, FileProjectVO.class).get(0);
|
||||
// projectVOS.add(fileProjectVO);
|
||||
}
|
||||
}
|
||||
return projectVOS;
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ import javax.annotation.PostConstruct;
|
|||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
|
|
@ -421,16 +422,21 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
|
||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
|
||||
public void update2Database(String prjDirPath) {
|
||||
List<EdFileInfo> importAllFiles = JSONUtil.toList(prjDirPath + File.separator + "mysql.info", EdFileInfo.class);
|
||||
// 首先处理导入的文件夹及其下属文件
|
||||
// 找出文件夹
|
||||
List<EdFileInfo> importDirs = importAllFiles.stream()
|
||||
.filter(e -> e.getDataType().equals(EleDataTypeEnum.FOLDER.code))
|
||||
String info = FileUtil.readString(prjDirPath + File.separator + "mysql.info", Charset.defaultCharset());
|
||||
List<EdFileInfo> importAllFiles = JSONUtil.toList(info, EdFileInfo.class);
|
||||
// 找出层级文件夹
|
||||
List<EdFileInfo> prjFolders = importAllFiles.stream().filter(e -> ObjUtil.equals(e.getPrjDir(), true))
|
||||
.collect(Collectors.toList());
|
||||
List<EdFileInfo> allObjs = new ArrayList<>();
|
||||
List<EdFileInfo> prjFolders = importDirs.stream().filter(EdFileInfo::getPrjDir).collect(Collectors.toList());
|
||||
allObjs.addAll(prjFolders);
|
||||
for (EdFileInfo edFileInfo : importDirs) {
|
||||
// 找出用户创建的文件夹
|
||||
List<EdFileInfo> userFolders = importAllFiles.stream().filter(e -> ObjUtil.equals(e.getDataType(), EleDataTypeEnum.FOLDER.code))
|
||||
.filter(e -> ObjUtil.notEqual(e.getPrjDir(), false))
|
||||
.collect(Collectors.toList());
|
||||
// 找出所有文件
|
||||
List<EdFileInfo> allFiles = importAllFiles.stream().filter(e -> ObjUtil.equals(e.getDataType(), EleDataTypeEnum.FILE.code)).collect(Collectors.toList());
|
||||
|
||||
List<EdFileInfo> allObjs = new ArrayList<>(prjFolders);
|
||||
// 处理用户创建的文件夹
|
||||
for (EdFileInfo edFileInfo : userFolders) {
|
||||
String fileName = edFileInfo.getFileName();
|
||||
String parentId = edFileInfo.getParentId();
|
||||
List<EdFileInfo> folders = queryChildFolders(parentId);
|
||||
|
|
@ -441,7 +447,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
if (foldersMap.get(fileName).getId().equals(edFileInfo.getId())) { // id相同,不做处理
|
||||
log.info("id相同,不做处理");
|
||||
} else { // 文件名重复,导入的文件名需要添加“_1”
|
||||
edFileInfo.setFileNote(fileName + "_1");
|
||||
resetFileInfoName(edFileInfo);
|
||||
allObjs.add(edFileInfo);
|
||||
}
|
||||
} else { // 没有同名文件夹
|
||||
|
|
@ -449,12 +455,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
}
|
||||
}
|
||||
// 处理文件
|
||||
List<EdFileInfo> importFiles = importAllFiles.stream()
|
||||
.filter(e -> e.getDataType().equals(EleDataTypeEnum.FILE.code))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Map<String, List<EdFileInfo>> fileInfoMap = new HashMap<>();
|
||||
for (EdFileInfo edFileInfo : importFiles) {
|
||||
for (EdFileInfo edFileInfo : allFiles) {
|
||||
List<EdFileInfo> list = fileInfoMap.getOrDefault(edFileInfo.getFileId(), new ArrayList<>());
|
||||
list.add(edFileInfo);
|
||||
fileInfoMap.put(edFileInfo.getFileId(), list);
|
||||
|
|
@ -462,24 +464,32 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
for (Map.Entry<String, List<EdFileInfo>> entry : fileInfoMap.entrySet()) {
|
||||
String k = entry.getKey();
|
||||
List<EdFileInfo> v = entry.getValue();
|
||||
|
||||
v.sort(Comparator.comparing(EdFileInfo::getCreatedTime));
|
||||
List<EdFileInfo> dbFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getFileId, k).orderByAsc(EdFileInfo::getFileVersion));
|
||||
if (CollUtil.isEmpty(dbFileInfos)) { // 在线上没有找到,则该批文件是从线下上传的
|
||||
EdFileInfo fileInfo = v.stream().filter(e -> e.getEffectFlag().equals(EffectFlagEnum.EFFECT.code)).findFirst().get();
|
||||
resetFileInfoName(fileInfo);
|
||||
allObjs.addAll(v);
|
||||
allObjs.add(fileInfo);
|
||||
} else {
|
||||
Map<String, EdFileInfo> dbIdMap = dbFileInfos.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
||||
Map<String, EdFileInfo> importIdMap = v.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
||||
|
||||
importIdMap.putAll(dbIdMap);
|
||||
|
||||
List<EdFileInfo> deepCopyV = JSONUtil.toList(JSONUtil.toJsonStr(v), EdFileInfo.class);
|
||||
List<EdFileInfo> deepCopyDb = JSONUtil.toList(JSONUtil.toJsonStr(dbFileInfos), EdFileInfo.class);
|
||||
|
||||
EdFileInfo importEffectFile = deepCopyV.stream().filter(e -> e.getEffectFlag().equals(EffectFlagEnum.EFFECT.code)).findFirst().get();
|
||||
EdFileInfo dbEffectFile = deepCopyDb.stream().filter(e -> e.getEffectFlag().equals(EffectFlagEnum.EFFECT.code)).findFirst().get();
|
||||
// 如果导入的时间比数据库的时间新,则将导入的置为effect
|
||||
String effectId = importEffectFile.getUpdatedTime().after(dbEffectFile.getUpdatedTime()) ? importEffectFile.getId() : dbEffectFile.getId();
|
||||
|
||||
Map<String, String> importVersionRelation = getVersionRelation(deepCopyV);
|
||||
Map<String, String> dbVersionRelation = getVersionRelation(deepCopyDb);
|
||||
|
||||
dbVersionRelation.putAll(importVersionRelation);
|
||||
//**************************
|
||||
int start = FILE_START_VERSION;
|
||||
List<EdFileInfo> saveObjs = new ArrayList<>();
|
||||
for (EdFileInfo importFileInfo : v) {
|
||||
|
|
@ -488,16 +498,25 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
if (dbFileInfo.getUpdatedTime().before(importFileInfo.getUpdatedTime())) { // 线下版本的修改时间比线上的新,用线下的版本
|
||||
importFileInfo.setFileVersion(start);
|
||||
saveObjs.add(importFileInfo);
|
||||
dbIdMap.remove(importFileInfo.getId());
|
||||
} else { // 线上版本的修改时间比线下新,用线上的版本。
|
||||
dbFileInfo.setFileVersion(start);
|
||||
saveObjs.add(dbFileInfo);
|
||||
dbIdMap.remove(dbFileInfo.getId());
|
||||
}
|
||||
} else { // 该文件是线下上传的。
|
||||
importFileInfo.setFileVersion(start);
|
||||
saveObjs.add(importFileInfo);
|
||||
dbIdMap.remove(importFileInfo.getId());
|
||||
}
|
||||
++start;
|
||||
}
|
||||
// 添加数据库中剩余的
|
||||
for (EdFileInfo edFileInfo : dbIdMap.values()) {
|
||||
edFileInfo.setFileVersion(++start);
|
||||
saveObjs.add(edFileInfo);
|
||||
}
|
||||
//*************************
|
||||
for (EdFileInfo saveObj : saveObjs) {
|
||||
String id = saveObj.getId();
|
||||
String preVersionId = dbVersionRelation.get(id);
|
||||
|
|
@ -510,7 +529,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
}
|
||||
}
|
||||
this.saveOrUpdateBatch(allObjs);
|
||||
update2FileSystem(importAllFiles, prjDirPath);
|
||||
update2FileSystem(allFiles, prjDirPath);
|
||||
}
|
||||
|
||||
private void resetFileInfoName(EdFileInfo fileInfo) {
|
||||
|
|
@ -582,8 +601,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
Map<String, EdFileInfo> maps = new HashMap<>();
|
||||
for (String id : ids) {
|
||||
Map<String, EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.like(EdFileInfo::getFilePath, MYSQL_FILE_PATH_SPLIT + id + MYSQL_FILE_PATH_SPLIT)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)).stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
||||
.like(EdFileInfo::getFilePath, MYSQL_FILE_PATH_SPLIT + id + MYSQL_FILE_PATH_SPLIT))
|
||||
.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
||||
maps.putAll(edFileInfos);
|
||||
}
|
||||
List<EdFileInfo> resFiles = new ArrayList<>(maps.values());
|
||||
|
|
|
|||
Loading…
Reference in New Issue