提交代码
This commit is contained in:
parent
1849b97650
commit
3122c18550
@ -137,8 +137,9 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
|
||||
QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
|
||||
// 固定条件过滤
|
||||
if (StringUtils.isNotBlank(taskId)) queryWrapper.eq("task_id", taskId);
|
||||
if (StringUtils.isNotBlank(nodeId)) queryWrapper.eq("node_id", nodeId);
|
||||
if (StringUtils.isNotBlank(taskId)) queryWrapper.eq("task_id", taskId);
|
||||
|
||||
|
||||
// 模糊搜索
|
||||
if (StringUtils.isNotBlank(fileName)) queryWrapper.like("file_name", fileName);
|
||||
@ -2460,20 +2461,16 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
* 参数说明 id 文件id
|
||||
* 返回值说明: com.yfd.platform.config.ResponseResult 返回成功或者失败
|
||||
***********************************/
|
||||
|
||||
|
||||
@Override
|
||||
public Page<TsFiles> compareLocal(List<String> dataset, String nodeId, String taskId, Page<TsFiles> page) {
|
||||
|
||||
|
||||
// ==================== 1. 构建查询条件 ====================
|
||||
QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.select("id", "node_id", "task_id", "is_file", "parent_id", "file_name",
|
||||
"file_size", "work_path", "backup_path", "upload_time"); // 移除无用字段
|
||||
|
||||
if (StringUtils.isNoneEmpty(nodeId, taskId)) {
|
||||
queryWrapper.eq("task_id", taskId)
|
||||
.eq("node_id", nodeId)
|
||||
queryWrapper.eq("node_id", nodeId)
|
||||
.eq("task_id", taskId)
|
||||
.isNotNull("work_path")
|
||||
.ne("work_path", "")
|
||||
.and(wq -> wq.isNull("backup_path").or().eq("backup_path", ""));
|
||||
@ -2481,104 +2478,65 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
if (CollectionUtils.isEmpty(dataset)) {
|
||||
throw new IllegalArgumentException("dataset参数不可为空"); // 优化点9:提前校验参数
|
||||
}
|
||||
queryWrapper.in("id", dataset)
|
||||
.isNotNull("work_path")
|
||||
.ne("work_path", "")
|
||||
.and(wq -> wq.isNull("backup_path").or().eq("backup_path", ""));
|
||||
queryWrapper.in("id", dataset);
|
||||
|
||||
// .isNotNull("work_path")
|
||||
// .ne("work_path", "")
|
||||
// .and(wq -> wq.isNull("backup_path").or().eq("backup_path", ""));
|
||||
}
|
||||
Page<TsFiles> tsFilesPage = tsFilesMapper.selectPage(page, queryWrapper);
|
||||
if (tsFilesPage == null) {
|
||||
tsFilesPage = new Page<>();
|
||||
tsFilesPage.setRecords(new ArrayList<>()); // 确保 records 被初始化
|
||||
}
|
||||
|
||||
List<TsFiles> records = tsFilesPage.getRecords();
|
||||
// 递归查询每个记录的子节点,并添加到 records 中
|
||||
List<TsFiles> allFiles = new ArrayList<>();
|
||||
for (TsFiles tsFiles : records) {
|
||||
tsFiles.setWorkPath(processingPath(tsFiles.getWorkPath(), tsFiles.getNodeId())); // 优化点11:路径处理内聚
|
||||
// 如果备份路径为空 增加 将当前节点加入结果列表
|
||||
if (StringUtils.isEmpty(tsFiles.getBackupPath())) {
|
||||
allFiles.add(tsFiles);
|
||||
|
||||
}
|
||||
// 查询该节点的所有子节点并递归添加
|
||||
if ("FOLDER".equals(tsFiles.getIsFile())) {
|
||||
List<TsFiles> childFiles = getChildFilesRecursiveLocal(tsFiles.getId(), allFiles);
|
||||
}
|
||||
}
|
||||
tsFilesPage.setRecords(records); // 同步到 tsFilesPage
|
||||
System.out.println("Updated records: " + records);
|
||||
|
||||
tsFilesPage.setTotal(allFiles.size());
|
||||
tsFilesPage.setRecords(allFiles); // 更新 tsFilesPage 中的 records
|
||||
System.out.println("Updated all files: " + allFiles);
|
||||
return tsFilesPage;
|
||||
}
|
||||
|
||||
// 递归查询所有子节点
|
||||
private List<TsFiles> getChildFilesRecursiveLocal(String parentId, List<TsFiles> allFiles) {
|
||||
// 构建查询条件,获取当前parentId的所有子节点
|
||||
QueryWrapper<TsFiles> childQueryWrapper = new QueryWrapper<>();
|
||||
childQueryWrapper.eq("parent_id", parentId)
|
||||
.isNotNull("work_path")
|
||||
.ne("work_path", "")
|
||||
.and(wq -> wq.isNull("backup_path").or().eq("backup_path", ""));
|
||||
|
||||
// @Override
|
||||
// public DualTreeResponse compareLocal(List<String> dataset, String nodeId, String taskId) {
|
||||
// // ================ 优化点1:改用普通集合提升性能 ================
|
||||
// List<TsFilesDTO> dtos = new ArrayList<>();
|
||||
// try {
|
||||
// // ================ 优化点2:分页查询避免内存溢出 ================
|
||||
// int pageSize = 1000; // 从配置文件读取(示例:@Value("${query.page-size:1000}"))
|
||||
// int currentPage = 1;
|
||||
// boolean hasMore;
|
||||
//
|
||||
// do {
|
||||
// Page<TsFiles> page = new Page<>(currentPage, pageSize);
|
||||
// QueryWrapper<TsFiles> queryWrapper = buildQueryWrapper(dataset, nodeId, taskId);
|
||||
//
|
||||
// // ================ 优化点3:分页查询并直接映射DTO ================
|
||||
// Page<TsFiles> resultPage = tsFilesMapper.selectPage(page, queryWrapper);
|
||||
// List<TsFilesDTO> pageDtos = resultPage.getRecords().stream()
|
||||
// .map(this::convertToDto) // 使用方法引用简化代码
|
||||
// .collect(Collectors.toList());
|
||||
// dtos.addAll(pageDtos);
|
||||
//
|
||||
// hasMore = resultPage.getCurrent() < resultPage.getPages();
|
||||
// currentPage++;
|
||||
// } while (hasMore);
|
||||
//
|
||||
// } catch (EmptyResultDataAccessException e) {
|
||||
// LOGGER.warn("无匹配数据: nodeId={}, taskId={}", nodeId, taskId); // 优化点4:细化异常类型
|
||||
// } catch (Exception e) {
|
||||
// LOGGER.error("本地文件对比失败", e); // 优化点5:精简日志内容
|
||||
// if (LOGGER.isDebugEnabled()) {
|
||||
// LOGGER.debug("失败详情:", e); // 优化点6:按需输出详细日志
|
||||
// }
|
||||
// }
|
||||
// // ================ 优化点7:移除冗余日志(原LOGGER.info) ================
|
||||
// return new DualTreeResponse(dtos);
|
||||
// }
|
||||
//
|
||||
// // ================ 优化点8:提取查询条件构建方法 ================
|
||||
// private QueryWrapper<TsFiles> buildQueryWrapper(List<String> dataset, String nodeId, String taskId) {
|
||||
// QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
|
||||
// queryWrapper.select("id", "node_id", "task_id", "is_file", "parent_id", "file_name",
|
||||
// "file_size", "work_path", "backup_path", "upload_time"); // 移除无用字段
|
||||
//
|
||||
// if (StringUtils.isNoneEmpty(nodeId, taskId)) {
|
||||
// queryWrapper.eq("task_id", taskId)
|
||||
// .eq("node_id", nodeId)
|
||||
// .isNotNull("work_path")
|
||||
// .ne("work_path", "")
|
||||
// .and(wq -> wq.isNull("backup_path").or().eq("backup_path", ""));
|
||||
// } else {
|
||||
// if (CollectionUtils.isEmpty(dataset)) {
|
||||
// throw new IllegalArgumentException("dataset参数不可为空"); // 优化点9:提前校验参数
|
||||
// }
|
||||
// queryWrapper.in("id", dataset)
|
||||
// .isNotNull("work_path")
|
||||
// .ne("work_path", "")
|
||||
// .and(wq -> wq.isNull("backup_path").or().eq("backup_path", ""));
|
||||
// }
|
||||
// return queryWrapper;
|
||||
// }
|
||||
//
|
||||
// // ================ 优化点10:提取DTO转换方法 ================
|
||||
// private TsFilesDTO convertToDto(TsFiles tsFile) {
|
||||
// TsFilesDTO dto = new TsFilesDTO();
|
||||
// dto.setId(tsFile.getId());
|
||||
// dto.setNodeId(tsFile.getNodeId());
|
||||
// dto.setTaskId(tsFile.getTaskId());
|
||||
// dto.setIsFile(tsFile.getIsFile());
|
||||
// dto.setParentId(tsFile.getParentId());
|
||||
// dto.setFileName(tsFile.getFileName());
|
||||
// dto.setFileSize(tsFile.getFileSize());
|
||||
// dto.setWorkPath(processingPath(tsFile.getWorkPath(), tsFile.getNodeId())); // 优化点11:路径处理内聚
|
||||
// dto.setUploadTime(tsFile.getUploadTime());
|
||||
// return dto;
|
||||
// }
|
||||
// 获取当前父节点的子节点
|
||||
List<TsFiles> children = tsFilesMapper.selectList(childQueryWrapper);
|
||||
|
||||
if (children != null && !children.isEmpty()) {
|
||||
|
||||
//allFiles.addAll(children);
|
||||
|
||||
// 对每个子节点递归查询其子节点
|
||||
for (TsFiles child : children) {
|
||||
child.setWorkPath(processingPath(child.getWorkPath(), child.getNodeId())); // 优化点11:路径处理内聚
|
||||
allFiles.add(child);
|
||||
if ("FOLDER".equals(child.getIsFile())) {
|
||||
List<TsFiles> childChildFiles = getChildFilesRecursiveLocal(child.getId(), allFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
return allFiles;
|
||||
}
|
||||
|
||||
|
||||
/**********************************
|
||||
@ -2598,25 +2556,23 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
public Page<TsFiles> compareMinio(List<String> dataset, String nodeId, String taskId, Page<TsFiles> page) {
|
||||
// ==================== 1. 构建查询条件 ====================
|
||||
QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.select(
|
||||
"id", "node_id", "task_id", "is_file",
|
||||
"parent_id", "file_name", "file_size",
|
||||
"backup_path", "upload_time" // 明确指定返回字段
|
||||
);
|
||||
queryWrapper.select("id", "node_id", "task_id", "is_file", "parent_id", "file_name",
|
||||
"file_size", "work_path", "backup_path", "upload_time");
|
||||
|
||||
|
||||
if (StringUtils.isNoneEmpty(nodeId, taskId)) {
|
||||
// 场景1:根据 nodeId + taskId 查询(确保数据库有联合索引)
|
||||
queryWrapper.eq("task_id", taskId)
|
||||
.eq("node_id", nodeId)
|
||||
queryWrapper.eq("node_id", nodeId)
|
||||
.eq("task_id", taskId)
|
||||
.isNotNull("backup_path")
|
||||
.ne("backup_path", "")
|
||||
.and(wq -> wq.isNull("work_path").or().eq("work_path", ""));
|
||||
} else {
|
||||
// 场景2:根据 id 列表查询(id字段需有索引)
|
||||
queryWrapper.in("id", dataset)
|
||||
.isNotNull("backup_path")
|
||||
.ne("backup_path", "")
|
||||
.and(wq -> wq.isNull("work_path").or().eq("work_path", ""));
|
||||
queryWrapper.in("id", dataset);
|
||||
// .isNotNull("backup_path")
|
||||
// .ne("backup_path", "")
|
||||
// .and(wq -> wq.isNull("work_path").or().eq("work_path", ""));
|
||||
}
|
||||
Page<TsFiles> tsFilesPage = tsFilesMapper.selectPage(page, queryWrapper);
|
||||
if (tsFilesPage == null) {
|
||||
@ -2625,90 +2581,52 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
}
|
||||
|
||||
List<TsFiles> records = tsFilesPage.getRecords();
|
||||
// 递归查询每个记录的子节点,并添加到 records 中
|
||||
List<TsFiles> allFiles = new ArrayList<>();
|
||||
for (TsFiles tsFiles : records) {
|
||||
tsFiles.setBackupPath(processingPath(tsFiles.getBackupPath(), tsFiles.getNodeId()));
|
||||
// 如果工作路径为空 增加 将当前节点加入结果列表
|
||||
if (StringUtils.isEmpty(tsFiles.getWorkPath())) {
|
||||
allFiles.add(tsFiles);
|
||||
|
||||
}
|
||||
// 查询该节点的所有子节点并递归添加
|
||||
if ("FOLDER".equals(tsFiles.getIsFile())) {
|
||||
List<TsFiles> childFiles = getChildFilesRecursiveMinio(tsFiles.getId(), allFiles);
|
||||
}
|
||||
}
|
||||
tsFilesPage.setRecords(records); // 同步到 tsFilesPage
|
||||
System.out.println("Updated records: " + records);
|
||||
|
||||
tsFilesPage.setTotal(allFiles.size());
|
||||
tsFilesPage.setRecords(allFiles); // 同步到 tsFilesPage
|
||||
System.out.println("Updated records: " + allFiles);
|
||||
return tsFilesPage;
|
||||
}
|
||||
|
||||
// 递归查询所有子节点
|
||||
private List<TsFiles> getChildFilesRecursiveMinio(String parentId, List<TsFiles> allFiles) {
|
||||
// 构建查询条件,获取当前parentId的所有子节点
|
||||
QueryWrapper<TsFiles> childQueryWrapper = new QueryWrapper<>();
|
||||
childQueryWrapper.eq("parent_id", parentId)
|
||||
.isNotNull("backup_path")
|
||||
.ne("backup_path", "")
|
||||
.and(wq -> wq.isNull("work_path").or().eq("work_path", ""));
|
||||
|
||||
// @Override
|
||||
// public DualTreeResponse compareMinio(List<String> dataset, String nodeId, String taskId) {
|
||||
// List<TsFilesDTO> dtos = new CopyOnWriteArrayList<>();
|
||||
// try {
|
||||
// // ==================== 1. 构建查询条件 ====================
|
||||
// QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
|
||||
// queryWrapper.select(
|
||||
// "id", "node_id", "task_id", "is_file",
|
||||
// "parent_id", "file_name", "file_size",
|
||||
// "backup_path", "upload_time" // 明确指定返回字段
|
||||
// );
|
||||
//
|
||||
// if (StringUtils.isNoneEmpty(nodeId, taskId)) {
|
||||
// // 场景1:根据 nodeId + taskId 查询(确保数据库有联合索引)
|
||||
// queryWrapper.eq("task_id", taskId)
|
||||
// .eq("node_id", nodeId)
|
||||
// .isNotNull("backup_path")
|
||||
// .ne("backup_path", "")
|
||||
// .and(wq -> wq.isNull("work_path").or().eq("work_path", ""));
|
||||
// } else {
|
||||
// // 场景2:根据 id 列表查询(id字段需有索引)
|
||||
// if (CollectionUtils.isEmpty(dataset)) {
|
||||
// LOGGER.warn("Dataset参数无效");
|
||||
// return new DualTreeResponse(dtos);
|
||||
// }
|
||||
// queryWrapper.in("id", dataset)
|
||||
// .isNotNull("backup_path")
|
||||
// .ne("backup_path", "")
|
||||
// .and(wq -> wq.isNull("work_path").or().eq("work_path", ""));
|
||||
// }
|
||||
//
|
||||
// // ==================== 2. 分页查询处理 ====================
|
||||
// int pageSize = 1000; // 根据内存调整分页大小
|
||||
// int currentPage = 1;
|
||||
// boolean hasMore = true;
|
||||
//
|
||||
// while (hasMore) {
|
||||
// Page<TsFiles> page = new Page<>(currentPage, pageSize);
|
||||
// Page<TsFiles> resultPage = tsFilesMapper.selectPage(page, queryWrapper);
|
||||
//
|
||||
// // ==================== 3. 并行流转换数据 ====================
|
||||
// List<TsFilesDTO> pageDtos = resultPage.getRecords()
|
||||
// .parallelStream() // 并行处理(确保processingPath线程安全)
|
||||
// .map(tsFile -> {
|
||||
// TsFilesDTO dto = new TsFilesDTO();
|
||||
// dto.setId(tsFile.getId());
|
||||
// dto.setNodeId(tsFile.getNodeId());
|
||||
// dto.setTaskId(tsFile.getTaskId());
|
||||
// dto.setIsFile(tsFile.getIsFile());
|
||||
// dto.setParentId(tsFile.getParentId());
|
||||
// dto.setFileName(tsFile.getFileName());
|
||||
// dto.setFileSize(tsFile.getFileSize());
|
||||
// dto.setBackupPath(processingPath(tsFile.getBackupPath(), tsFile.getNodeId()));
|
||||
// dto.setUploadTime(tsFile.getUploadTime());
|
||||
// return dto;
|
||||
// })
|
||||
// .collect(Collectors.toList());
|
||||
//
|
||||
// dtos.addAll(pageDtos);
|
||||
//
|
||||
// // ==================== 4. 判断是否继续查询 ====================
|
||||
// hasMore = resultPage.getCurrent() < resultPage.getPages();
|
||||
// currentPage++;
|
||||
// }
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// LOGGER.error("MinIO文件对比失败: {}", e.getMessage()); // 精简日志内容
|
||||
// if (LOGGER.isDebugEnabled()) { // 仅调试模式打印堆栈
|
||||
// LOGGER.debug("详细错误信息:", e);
|
||||
// }
|
||||
// }
|
||||
// return new DualTreeResponse(dtos);
|
||||
// }
|
||||
// 获取当前父节点的子节点
|
||||
List<TsFiles> children = tsFilesMapper.selectList(childQueryWrapper);
|
||||
|
||||
if (children != null && !children.isEmpty()) {
|
||||
// 对每个子节点递归查询其子节点
|
||||
for (TsFiles child : children) {
|
||||
child.setBackupPath(processingPath(child.getBackupPath(), child.getNodeId()));
|
||||
|
||||
allFiles.add(child);
|
||||
|
||||
if ("FOLDER".equals(child.getIsFile())) {
|
||||
List<TsFiles> childChildFiles = getChildFilesRecursiveLocal(child.getId(), allFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
return allFiles;
|
||||
}
|
||||
|
||||
|
||||
/**********************************
|
||||
@ -2724,11 +2642,31 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
StorageSourceConfig filePathConfig = getStorageConfig("filePath");
|
||||
StorageSourceConfig bucketConfig = getStorageConfig("bucketName");
|
||||
|
||||
|
||||
// ================ 1. 执行原始分页查询 ================
|
||||
QueryWrapper<TsFiles> queryWrapper = buildQueryWrapper(dataset, nodeId, taskId);
|
||||
Page<TsFiles> tsFilesPage = tsFilesMapper.selectPage(page, queryWrapper);
|
||||
|
||||
if (StringUtils.isEmpty(nodeId) || StringUtils.isEmpty(taskId)) {
|
||||
if (tsFilesPage == null) {
|
||||
tsFilesPage = new Page<>();
|
||||
tsFilesPage.setRecords(new ArrayList<>()); // 确保 records 被初始化
|
||||
}
|
||||
|
||||
List<TsFiles> records = tsFilesPage.getRecords();
|
||||
// 递归查询每个记录的子节点,并添加到 records 中
|
||||
List<TsFiles> allFiles = new ArrayList<>();
|
||||
for (TsFiles tsFiles : records) {
|
||||
// 将当前节点加入结果列表
|
||||
allFiles.add(tsFiles);
|
||||
// 查询该节点的所有子节点并递归添加
|
||||
if ("FOLDER".equals(tsFiles.getIsFile())) {
|
||||
List<TsFiles> childFiles = getChildFilesRecursiveMd5(tsFiles.getId(), allFiles);
|
||||
}
|
||||
}
|
||||
tsFilesPage.setRecords(allFiles); // 同步到 tsFilesPage
|
||||
System.out.println("Updated records: " + allFiles);
|
||||
}
|
||||
|
||||
|
||||
// ================ 2. 过滤并处理符合条件的记录 ================
|
||||
List<TsFiles> filteredRecords = tsFilesPage.getRecords().stream()
|
||||
@ -2752,8 +2690,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
|
||||
// 返回是否满足过滤条件
|
||||
return StringUtils.isNoneEmpty(localMD5, minioMD5) && !localMD5.equals(minioMD5);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("MD5计算失败: {}", tsFile.getFileName(), e);
|
||||
return false;
|
||||
@ -2773,66 +2709,34 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
);
|
||||
|
||||
return resultPage;
|
||||
|
||||
|
||||
// // ==================== 1. 构建查询条件 ====================
|
||||
// QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
|
||||
// if (StringUtils.isNoneEmpty(nodeId, taskId)) {
|
||||
// //查询数据库中 minio路径有值 本地没有值的所有数据 根据nodeId,taskid
|
||||
// queryWrapper.select("id", "node_id", "task_id", "is_file", "parent_id", "file_name", "file_size", "work_path", "backup_path", "upload_time", "update_time");
|
||||
// queryWrapper.eq("task_id", taskId)
|
||||
// .eq("node_id", nodeId)
|
||||
// .isNotNull("backup_path")
|
||||
// .ne("backup_path", "")
|
||||
// .isNotNull("work_path")
|
||||
// .ne("work_path", "");
|
||||
// System.out.println("完整SQL: " + queryWrapper.getCustomSqlSegment());
|
||||
// } else {
|
||||
// //查询数据库中 minio路径有值 本地没有值的所有数据 根据id
|
||||
// queryWrapper.in("id", dataset)
|
||||
// .isNotNull("backup_path")
|
||||
// .ne("backup_path", "")
|
||||
// .isNotNull("work_path")
|
||||
// .ne("work_path", "");
|
||||
// }
|
||||
// Page<TsFiles> tsFilesPage = tsFilesMapper.selectPage(page, queryWrapper);
|
||||
// if (tsFilesPage == null) {
|
||||
// tsFilesPage = new Page<>();
|
||||
// tsFilesPage.setRecords(new ArrayList<>()); // 确保 records 被初始化
|
||||
// }
|
||||
//
|
||||
// List<TsFiles> records = tsFilesPage.getRecords();
|
||||
// for (TsFiles tsFiles : records) {
|
||||
//
|
||||
// File localFileObj = new File(filePathConfig.getValue() + tsFiles.getWorkPath(), tsFiles.getFileName());
|
||||
// String localMD5 = null;
|
||||
// try {
|
||||
// localMD5 = calculateMD5Data(new FileInputStream(localFileObj));
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (NoSuchAlgorithmException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// String minioMD5 = getMinioMD5Data(bucketConfig.getValue(), tsFiles.getBackupPath(), tsFiles.getFileName());
|
||||
// String WorkPath = processingPath(tsFiles.getWorkPath(), tsFiles.getNodeId());
|
||||
// String BackupPath = processingPath(tsFiles.getBackupPath(), tsFiles.getNodeId());
|
||||
// tsFiles.setWorkPath(WorkPath);
|
||||
// tsFiles.setBackupPath(BackupPath);
|
||||
//
|
||||
// if (StringUtils.isNoneEmpty(localMD5, minioMD5) && !localMD5.equals(minioMD5)) {
|
||||
// tsFiles.setLocatMd5(localMD5);
|
||||
// tsFiles.setMinioMd5(minioMD5);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// tsFilesPage.setRecords(records); // 同步到 tsFilesPage
|
||||
// System.out.println("Updated records: " + records);
|
||||
//
|
||||
// return tsFilesPage;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 递归查询所有子节点
|
||||
private List<TsFiles> getChildFilesRecursiveMd5(String parentId, List<TsFiles> allFiles) {
|
||||
// 构建查询条件,获取当前parentId的所有子节点
|
||||
QueryWrapper<TsFiles> childQueryWrapper = new QueryWrapper<>();
|
||||
childQueryWrapper.eq("parent_id", parentId)
|
||||
.isNotNull("backup_path")
|
||||
.ne("backup_path", "")
|
||||
.isNotNull("work_path")
|
||||
.ne("work_path", "");
|
||||
|
||||
// 获取当前父节点的子节点
|
||||
List<TsFiles> children = tsFilesMapper.selectList(childQueryWrapper);
|
||||
|
||||
if (children != null && !children.isEmpty()) {
|
||||
allFiles.addAll(children);
|
||||
// 对每个子节点递归查询其子节点
|
||||
for (TsFiles child : children) {
|
||||
if ("FOLDER".equals(child.getIsFile())) {
|
||||
List<TsFiles> childChildFiles = getChildFilesRecursiveLocal(child.getId(), allFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
return allFiles;
|
||||
}
|
||||
|
||||
// ================ 辅助方法:构建查询条件 ================
|
||||
private QueryWrapper<TsFiles> buildQueryWrapper(List<String> dataset, String nodeId, String taskId) {
|
||||
QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
|
||||
@ -2840,8 +2744,8 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
|
||||
if (StringUtils.isNoneEmpty(nodeId, taskId)) {
|
||||
//查询数据库中 minio路径有值 本地没有值的所有数据 根据nodeId,taskid
|
||||
queryWrapper.eq("task_id", taskId)
|
||||
.eq("node_id", nodeId)
|
||||
queryWrapper.eq("node_id", nodeId)
|
||||
.eq("task_id", taskId)
|
||||
.isNotNull("backup_path")
|
||||
.ne("backup_path", "")
|
||||
.isNotNull("work_path")
|
||||
@ -2858,79 +2762,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public Page<TsFiles> compareMd5(List<String> dataset, String nodeId, String taskId) throws IOException, NoSuchAlgorithmException {
|
||||
// // 获取本地文件路径根目录和存储空间名称
|
||||
// StorageSourceConfig filePathConfig = getStorageConfig("filePath");
|
||||
// StorageSourceConfig bucketConfig = getStorageConfig("bucketName");
|
||||
// List<TsFiles> tsFiles = new CopyOnWriteArrayList<>();
|
||||
// List<TsFilesDTO> dtos = new CopyOnWriteArrayList<>();
|
||||
//
|
||||
// try {
|
||||
// if (StringUtils.isNoneEmpty(nodeId, taskId)) {
|
||||
// //查询数据库中 minio路径有值 本地没有值的所有数据 根据nodeId,taskid
|
||||
// QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
|
||||
// queryWrapper.select("id", "node_id", "task_id", "is_file", "parent_id", "file_name", "file_size", "work_path", "backup_path", "upload_time", "update_time");
|
||||
// queryWrapper.eq("task_id", taskId)
|
||||
// .eq("node_id", nodeId)
|
||||
// .isNotNull("backup_path")
|
||||
// .ne("backup_path", "")
|
||||
// .isNotNull("work_path")
|
||||
// .ne("work_path", "");
|
||||
// tsFiles = tsFilesMapper.selectList(queryWrapper);
|
||||
// System.out.println("完整SQL: " + queryWrapper.getCustomSqlSegment());
|
||||
// } else {
|
||||
// //查询数据库中 minio路径有值 本地没有值的所有数据 根据id
|
||||
// QueryWrapper<TsFiles> queryWrapper1 = new QueryWrapper<>();
|
||||
// queryWrapper1.select("id", "node_id", "task_id", "is_file", "parent_id", "file_name", "file_size", "work_path", "backup_path", "upload_time", "update_time");
|
||||
// queryWrapper1.in("id", dataset)
|
||||
// .isNotNull("backup_path")
|
||||
// .ne("backup_path", "")
|
||||
// .isNotNull("work_path")
|
||||
// .ne("work_path", "");
|
||||
// tsFiles = tsFilesMapper.selectList(queryWrapper1);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// LOGGER.error("获取Md5文件列表: {}", e.getMessage(), e);
|
||||
// }
|
||||
//
|
||||
// dtos = tsFiles.stream()
|
||||
// .map(tsFile -> {
|
||||
// TsFilesDTO dto = new TsFilesDTO();
|
||||
// dto.setId(tsFile.getId());
|
||||
// dto.setNodeId(tsFile.getNodeId());
|
||||
// dto.setTaskId(tsFile.getTaskId());
|
||||
// dto.setIsFile(tsFile.getIsFile());
|
||||
// dto.setParentId(tsFile.getParentId());
|
||||
// dto.setFileName(tsFile.getFileName());
|
||||
// dto.setFileSize(tsFile.getFileSize());
|
||||
// dto.setUploadTime(tsFile.getUploadTime());
|
||||
// File localFileObj = new File(filePathConfig.getValue() + tsFile.getWorkPath(), tsFile.getFileName());
|
||||
// String localMD5 = null;
|
||||
// try {
|
||||
// localMD5 = calculateMD5Data(new FileInputStream(localFileObj));
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (NoSuchAlgorithmException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// String minioMD5 = getMinioMD5Data(bucketConfig.getValue(), tsFile.getBackupPath(), tsFile.getFileName());
|
||||
// String WorkPath = processingPath(tsFile.getWorkPath(), tsFile.getNodeId());
|
||||
// String BackupPath = processingPath(tsFile.getBackupPath(), tsFile.getNodeId());
|
||||
// dto.setWorkPath(WorkPath);
|
||||
// dto.setBackupPath(BackupPath);
|
||||
//
|
||||
// if (StringUtils.isNoneEmpty(localMD5, minioMD5) && !localMD5.equals(minioMD5)) {
|
||||
// dto.setLocatMd5(localMD5);
|
||||
// dto.setMinioMd5(minioMD5);
|
||||
// }
|
||||
// return dto;
|
||||
// })
|
||||
// .collect(Collectors.toList());
|
||||
// return dtos;
|
||||
// }
|
||||
|
||||
// 辅助方法:获取 MinIO 文件 MD5
|
||||
private String getMinioMD5Data(String bucketName, String path, String name) {
|
||||
AbstractBaseFileService<?> minioService = storageSourceContext.getByStorageKey("minio");
|
||||
@ -3202,8 +3033,8 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
public String automaticFileBackup(String taskId, String nodeId) {
|
||||
//首先查询节点下面所有 备份路径为空的数据
|
||||
QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("task_id", taskId);
|
||||
queryWrapper.eq("node_id", nodeId);
|
||||
queryWrapper.eq("task_id", taskId);
|
||||
queryWrapper.and(wrapper -> wrapper.isNull("backup_path").or().eq("backup_path", ""));
|
||||
queryWrapper.isNotNull("work_path").ne("work_path", "");
|
||||
List<TsFiles> tsFilelist = tsFilesMapper.selectList(queryWrapper);
|
||||
@ -3529,11 +3360,12 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
String targetFileName = generateTargetFileName(targetParentPhysicalPath, fileName, rename, type);
|
||||
Path targetPath = targetParentPhysicalPath.resolve(targetFileName);
|
||||
|
||||
// 3. 再次检查自移动
|
||||
if (sourcePath.equals(targetPath)) {
|
||||
throw new IllegalArgumentException("不能移动到自己当前位置");
|
||||
// 3. 再次检查自移动 如果是覆盖不需要校验这个
|
||||
if ("1".equals(type)) {
|
||||
if (sourcePath.equals(targetPath)) {
|
||||
throw new IllegalArgumentException("不能移动到自己当前位置");
|
||||
}
|
||||
}
|
||||
|
||||
// 执行移动操作
|
||||
moveFile(sourcePath, targetPath, type);
|
||||
|
||||
@ -3649,8 +3481,8 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
newfileRecord.setFileName(targetFileName);
|
||||
newfileRecord.setUpdateTime(new Timestamp(System.currentTimeMillis())); // 更新时间
|
||||
tsFilesMapper.updateById(newfileRecord);
|
||||
// 删除原记录
|
||||
tsFilesMapper.deleteById(fileRecord.getId());
|
||||
// // 删除原记录 覆盖的时候不用删除原来的记录
|
||||
// tsFilesMapper.deleteById(fileRecord.getId());
|
||||
} else {
|
||||
// 插入新记录
|
||||
TsFiles newRecord = new TsFiles();
|
||||
@ -3672,9 +3504,10 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
// 先移动子项再删除原记录
|
||||
moveChildrenRecords(oldWorkPath, newWorkPath + targetFileName + "/", newRecord.getId(), type, fileRecord.getId());
|
||||
}
|
||||
// 删除原记录
|
||||
tsFilesMapper.deleteById(fileRecord.getId());
|
||||
}
|
||||
// 删除原记录
|
||||
tsFilesMapper.deleteById(fileRecord.getId());
|
||||
|
||||
|
||||
} else {
|
||||
// 重命名模式:插入新记录
|
||||
@ -4075,12 +3908,12 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
LOGGER.info("Starting to build dual trees for taskId={}, nodeId={}", taskId, nodeId);
|
||||
// 1. 批量查询所有相关节点
|
||||
QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
|
||||
if (taskId != null && !taskId.isEmpty()) {
|
||||
queryWrapper.eq("task_id", taskId);
|
||||
}
|
||||
if (nodeId != null && !nodeId.isEmpty()) {
|
||||
queryWrapper.eq("node_id", nodeId);
|
||||
}
|
||||
if (taskId != null && !taskId.isEmpty()) {
|
||||
queryWrapper.eq("task_id", taskId);
|
||||
}
|
||||
queryWrapper.isNotNull("work_path").ne("work_path", "");
|
||||
// queryWrapper.eq("parent_id", "00");
|
||||
|
||||
@ -4131,12 +3964,13 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
LOGGER.info("Starting to build dual trees for taskId={}, nodeId={}", taskId, nodeId);
|
||||
// 1. 批量查询所有相关节点
|
||||
QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
|
||||
if (taskId != null && !taskId.isEmpty()) {
|
||||
queryWrapper.eq("task_id", taskId);
|
||||
}
|
||||
if (nodeId != null && !nodeId.isEmpty()) {
|
||||
queryWrapper.eq("node_id", nodeId);
|
||||
}
|
||||
if (taskId != null && !taskId.isEmpty()) {
|
||||
queryWrapper.eq("task_id", taskId);
|
||||
}
|
||||
|
||||
queryWrapper.isNotNull("backup_path").ne("backup_path", "");
|
||||
// queryWrapper.eq("parent_id", "00");
|
||||
List<TsFiles> allNodes = tsFilesMapper.selectList(queryWrapper);
|
||||
|
Loading…
Reference in New Issue
Block a user