提交代码0325

This commit is contained in:
lilin 2025-03-25 11:45:45 +08:00
parent 26f2312b53
commit a477ae3952
3 changed files with 106 additions and 422 deletions

View File

@ -397,8 +397,16 @@ public class TsFilesController {
}
/**********************************
* 用途说明: 实时获取轨迹数据
* 参数说明 id 文件的ID
* 参数说明 samTimes 时间
* 参数说明 token SSE连接的token
* 返回值说明: com.yfd.platform.config.ResponseResult
***********************************/
@Log(module = "实验数据管理", value = "实时获取轨迹数据!")
@PostMapping("/startSimpleNavi")
@ApiOperation("实时获取轨迹数据")
public ResponseResult startSimpleNavi(String id,int samTimes,String token) {
try {
// 使用线程池异步执行任务

View File

@ -43,6 +43,7 @@ import com.yfd.platform.system.domain.SysDictionaryItems;
import com.yfd.platform.system.mapper.SysDictionaryItemsMapper;
import com.yfd.platform.utils.StringUtils;
import io.netty.channel.ChannelInboundHandlerAdapter;
import net.sf.jsqlparser.expression.LongValue;
import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;
import org.apache.commons.compress.archivers.sevenz.SevenZFile;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
@ -190,16 +191,9 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
List<TsFiles> records = tsFilesPage.getRecords();
for (TsFiles tsFiles : records) {
// 获取原始路径和 nodeId
String workPath = tsFiles.getWorkPath();
// 拼接需要去掉的部分
String toRemove = File.separator + nodeId;
String fileNameData = tsFiles.getFileName();
//主要是用于文件路径加名称
String path = workPath + fileNameData;
String path = tsFiles.getWorkPath() + fileNameData;
//准备获取文件的信息
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey("local");
FileItemResult fileItemResult = fileService.getFileItem(path);
@ -217,22 +211,8 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
if (tsFiles.getUpdateTime() == null) {
tsFiles.setUpdateTime(tsFiles.getUploadTime());
}
// 将路径分隔符统一为 "/"
String standardizedWorkPath = workPath.replace("\\", "/");
String standardizedToRemove = toRemove.replace("\\", "/");
// 检查 standardizedWorkPath 是否包含 standardizedToRemove
if (standardizedWorkPath.contains(standardizedToRemove)) {
// 去掉目标部分
String newWorkPath = standardizedWorkPath.replace(standardizedToRemove, "");
// 确保路径最后保留一个 '/'
if (!newWorkPath.endsWith("/")) {
newWorkPath += "/";
}
// 更新路径
tsFiles.setWorkPath(newWorkPath); // 更新路径
}
String ProcessingPath = processingPath(tsFiles.getWorkPath(), nodeId);
tsFiles.setWorkPath(ProcessingPath);
}
tsFilesPage.setRecords(records); // 同步到 tsFilesPage
System.out.println("Updated records: " + records);
@ -309,25 +289,8 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
List<TsFiles> tsFiles = tsFilesMapper.selectList(queryWrapper);
for (TsFiles tsFiles1 : tsFiles) {
// 获取原始路径和 nodeId
String workPath = tsFiles1.getWorkPath();
// 拼接需要去掉的部分
String toRemove = File.separator + nodeId;
// 将路径分隔符统一为 "/"
String standardizedWorkPath = workPath.replace("\\", "/");
String standardizedToRemove = toRemove.replace("\\", "/");
// 检查 standardizedWorkPath 是否包含 standardizedToRemove
if (standardizedWorkPath.contains(standardizedToRemove)) {
// 去掉目标部分
String newWorkPath = standardizedWorkPath.replace(standardizedToRemove, "");
// 确保路径最后保留一个 '/'
if (!newWorkPath.endsWith("/")) {
newWorkPath += "/";
}
// 更新路径
tsFiles1.setWorkPath(newWorkPath); // 更新路径
}
String ProcessingPath = processingPath(tsFiles1.getWorkPath(), nodeId);
tsFiles1.setWorkPath(ProcessingPath);
}
return tsFiles;
}
@ -464,8 +427,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
if (tsFiles.getIsFile().equals("FILE")) {
StorageSourceConfig config = storageSourceConfigMapper.selectOne(new QueryWrapper<StorageSourceConfig>().eq("name", "filePath"));
String basePath = config.getValue() + tsFiles.getWorkPath();
// 拼接完整文件路径
// 拼接完整的文件路径
Path filePath = Paths.get(basePath, tsFiles.getFileName() + ".txt");
@ -808,7 +769,9 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
if (valueInsert == 1) {
int valueUpdate = tsFilesMapper.updateById(tsFiles2);
if (valueUpdate == 1) {
if ("FOLDER".equals(subFile.getIsFile())) {
querySubFilesAndUpdatePaths(resultList, tsFiles2.getId(), oldName, newName, tsFiles1.getId());
}
}
}
@ -2106,100 +2069,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
}
// /**
// * 解析压缩包条目支持多种格式
// */
// private List<ZipEntryInfo> parseArchiveEntries(Path compressedFilePath) throws IOException {
// List<ZipEntryInfo> entries = new ArrayList<>();
// String suffix = getMatchedSuffix(compressedFilePath);
//
// switch (suffix) {
// case "zip":
// try (ZipInputStream zis = new ZipInputStream(Files.newInputStream(compressedFilePath))) {
// ZipEntry entry;
// while ((entry = zis.getNextEntry()) != null) {
// if (!entry.getName().startsWith("__MACOSX/")) {
// entries.add(new ZipEntryInfo(entry.getName(), entry.isDirectory()));
// }
// zis.closeEntry();
// }
// }
// break;
// case "tar":
// case "tar.gz":
// case "tar.bz2":
// try (ArchiveInputStream ais = createArchiveInputStream(compressedFilePath, suffix)) {
// ArchiveEntry entry;
// while ((entry = ais.getNextEntry()) != null) {
// if (!entry.getName().startsWith("__MACOSX/")) {
// entries.add(new ZipEntryInfo(entry.getName(), entry.isDirectory()));
// }
// }
// }
// break;
// case "rar":
// try (Archive archive = new Archive(compressedFilePath.toFile())) {
// FileHeader fileHeader;
// while ((fileHeader = archive.nextFileHeader()) != null) {
// if (!fileHeader.getFileName().startsWith("__MACOSX/")) {
// entries.add(new ZipEntryInfo(fileHeader.getFileName(), fileHeader.isDirectory()));
// }
// }
// } catch (RarException e) {
// throw new IOException("Failed to parse RAR entries", e);
// }
// break;
// default:
// throw new IOException("Unsupported format for entry parsing: " + suffix);
// }
// return entries;
// }
//上面这个方法会覆盖 TODO
// private File unzipToTemp(Path zipFilePath, String baseDir) throws IOException {
// // 1. 直接构建目标路径baseDir/zipName
// String zipName = getFileNameWithoutExtension(zipFilePath.getFileName().toString());
// Path destRoot = Paths.get(baseDir, zipName);
// Files.createDirectories(destRoot); // 确保目标目录存在
//
// try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFilePath.toFile()))) {
// ZipEntry entry;
// while ((entry = zis.getNextEntry()) != null) {
// if (entry.getName().startsWith("__MACOSX/")) {
// zis.closeEntry();
// continue;
// }
//
// // 2. 直接解压到目标路径不再嵌套临时目录
// Path destPath = destRoot.resolve(entry.getName()).normalize();
// validatePathSafety(destPath, destRoot); // 确保路径安全
//
// // 3. 处理目录
// if (entry.isDirectory()) {
// Files.createDirectories(destPath);
// }
// // 4. 处理文件
// else {
// // 确保父目录存在
// Files.createDirectories(destPath.getParent());
//
// // 写入文件使用缓冲提升性能
// try (BufferedOutputStream bos = new BufferedOutputStream(
// Files.newOutputStream(destPath, StandardOpenOption.CREATE_NEW))) {
// byte[] buffer = new byte[8192];
// int len;
// while ((len = zis.read(buffer)) > 0) {
// bos.write(buffer, 0, len);
// }
// }
// }
// zis.closeEntry();
// }
// }
// return destRoot.toFile();
// }
/**
* 校验路径安全性防御路径穿越攻击
@ -2298,13 +2167,31 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
private void processFileList(String path, String fileName, String storageKey, List<FileItemResult> targetList, String isFile, String nodeId, String taskId) throws Exception {
if (StringUtils.isNotEmpty(path)) {
AbstractBaseFileService<?> service = storageSourceContext.getByStorageKey(storageKey);
if (isFile.equals("FOLDER") && storageKey.equals("minio")) {
if (storageKey.equals("minio")) {
List<FileItemResult> files = service.fileListData(path, fileName + "/");
if (files != null) {
// 对每个文件的路径进行规范化
for (FileItemResult file : files) {
String normalizedPath = ensurePathFormat(file.getPath());
file.setPath(normalizedPath);
String ProcessingPath = processingPath(normalizedPath, nodeId);
file.setPath(ProcessingPath);
if (file.getSize() == null) {
file.setSize((long) 0);
} else {
// 获取文件大小字节
long fileSizeInBytes = file.getSize();
// 转换为 MB 并保留两位小数
double fileSizeInMB = fileSizeInBytes / (1024.0 * 1024.0);
String fileSizeFormatted = String.format("%.2f", fileSizeInMB); // 保留两位小数
// 判断是否为 "0.00"如果是则直接设置为 0
if ("0.00".equals(fileSizeFormatted)) {
file.setSize((long) 0); // 如果文件大小为 0.00直接设置为 0
} else {
// 否则将文件大小转换为 long去掉小数部分
file.setSize((long) Double.parseDouble(fileSizeFormatted));
}
}
QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("node_id", nodeId);
queryWrapper.eq("task_id", taskId);
@ -2313,6 +2200,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
TsFiles tsFiles1 = tsFilesMapper.selectOne(queryWrapper);
if (tsFiles1 != null) {
file.setParentId(tsFiles1.getParentId());
file.setId(tsFiles1.getId());
}
}
@ -2331,7 +2219,26 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
// 对每个文件的路径进行规范化
for (FileItemResult file : files) {
String normalizedPath = ensurePathFormat(file.getPath());
file.setPath(normalizedPath);
String ProcessingPath = processingPath(normalizedPath, nodeId);
file.setPath(ProcessingPath);
if (file.getSize() == null) {
file.setSize((long) 0);
} else {
// 获取文件大小字节
long fileSizeInBytes = file.getSize();
// 转换为 MB 并保留两位小数
double fileSizeInMB = fileSizeInBytes / (1024.0 * 1024.0);
String fileSizeFormatted = String.format("%.2f", fileSizeInMB); // 保留两位小数
// 判断是否为 "0.00"如果是则直接设置为 0
if ("0.00".equals(fileSizeFormatted)) {
file.setSize((long) 0); // 如果文件大小为 0.00直接设置为 0
} else {
// 否则将文件大小转换为 long去掉小数部分
file.setSize((long) Double.parseDouble(fileSizeFormatted));
}
}
// file.setPath(normalizedPath);
QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("node_id", nodeId);
queryWrapper.eq("task_id", taskId);
@ -2340,6 +2247,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
TsFiles tsFiles1 = tsFilesMapper.selectOne(queryWrapper);
if (tsFiles1 != null) {
file.setParentId(tsFiles1.getParentId());
file.setId(tsFiles1.getId());
}
}
// 同步添加线程安全
@ -2549,274 +2457,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
}
// @Override
// public TsFiles compareDirectories(List<String> dataset, String nodeId, String taskId) {
// //查询本地文件路径根目录 E:\yun
// QueryWrapper<StorageSourceConfig> queryWrapper = new QueryWrapper<>();
// queryWrapper.eq("name", "filePath");
// StorageSourceConfig storageSourceConfig = storageSourceConfigMapper.selectOne(queryWrapper);
//
// //查询存储空间名称根目录 如test-bucket
// QueryWrapper<StorageSourceConfig> queryWrapper1 = new QueryWrapper<>();
// queryWrapper1.eq("name", "bucketName");
// StorageSourceConfig storageSourceConfig1 = storageSourceConfigMapper.selectOne(queryWrapper1);
// // 获取文件列表
// TsFiles tsFiles = new TsFiles();
// try {
// List<FileItemResult> fileItemListMinio = new ArrayList<>();
// List<FileItemResult> fileItemListLocal = new ArrayList<>();
// if (StringUtils.isNotEmpty(nodeId) && StringUtils.isNotEmpty(taskId)) {
// QueryWrapper<TsFiles> queryWrapper2 = new QueryWrapper<>();
// queryWrapper2.eq("task_id", taskId)
// .eq("node_id", nodeId).and(i -> i.eq("work_path", "/").or()
// .eq("backup_path", "/"));
// List<TsFiles> allNodes = tsFilesMapper.selectList(queryWrapper2);
// for (TsFiles tsFiles1 : allNodes) {
// if (tsFiles1 != null) {
// // 获取minio文件列表
// if (StringUtils.isNotEmpty(tsFiles1.getBackupPath())) {
// AbstractBaseFileService<?> fileServiceMinio = storageSourceContext.getByStorageKey("minio");
// List<FileItemResult> minioFiles = fileServiceMinio.fileListData(tsFiles1.getBackupPath(), tsFiles1.getFileName());
// // 将当前文件列表添加到 fileItemListMinio
// if (minioFiles != null) {
// fileItemListMinio.addAll(minioFiles);
// }
// }
//
// // 获取本地文件列表
// if (StringUtils.isNotEmpty(tsFiles1.getWorkPath())) {
// AbstractBaseFileService<?> fileServiceLocal = storageSourceContext.getByStorageKey("local");
// List<FileItemResult> localFiles = fileServiceLocal.fileListData(tsFiles1.getWorkPath(), tsFiles1.getFileName());
//
// // 将当前文件列表添加到 fileItemListLocal
// if (localFiles != null) {
// fileItemListLocal.addAll(localFiles);
// }
// }
// }
// }
//
// } else {
// for (String id : dataset) {
// TsFiles tsFiles1 = tsFilesMapper.selectById(id);
// if (tsFiles1 != null) {
// // 获取minio文件列表
// if (StringUtils.isNotEmpty(tsFiles1.getBackupPath())) {
// AbstractBaseFileService<?> fileServiceMinio = storageSourceContext.getByStorageKey("minio");
// List<FileItemResult> minioFiles = fileServiceMinio.fileListData(tsFiles1.getBackupPath(), tsFiles1.getFileName());
// // 将当前文件列表添加到 fileItemListMinio
// if (minioFiles != null) {
// fileItemListMinio.addAll(minioFiles);
// }
// }
//
// // 获取本地文件列表
// if (StringUtils.isNotEmpty(tsFiles1.getWorkPath())) {
// AbstractBaseFileService<?> fileServiceLocal = storageSourceContext.getByStorageKey("local");
// List<FileItemResult> localFiles = fileServiceLocal.fileListData(tsFiles1.getWorkPath(), tsFiles1.getFileName());
//
// // 将当前文件列表添加到 fileItemListLocal
// if (localFiles != null) {
// fileItemListLocal.addAll(localFiles);
// }
// }
// }
// }
// }
//
// //去除重复的
// Set<String> seenMinioPaths = new HashSet<>(); // 用于记录已经处理过的 path + name
// Iterator<FileItemResult> iteratorMinio = fileItemListMinio.iterator();
// while (iteratorMinio.hasNext()) {
// FileItemResult fileItemResult = iteratorMinio.next();
// String path = normalizePath(fileItemResult.getPath());
// String name = fileItemResult.getName();
// String uniqueKey = path + name; // 唯一标识
// if (seenMinioPaths.contains(uniqueKey)) {
// // 如果已经存在则移除当前项
// iteratorMinio.remove();
// } else {
// // 如果不存在则添加到已处理集合中并更新 path
// seenMinioPaths.add(uniqueKey);
// fileItemResult.setPath(path);
// }
// }
//
// //去除重复的
// Set<String> seenLocalPaths = new HashSet<>(); // 用于记录已经处理过的 path + name
// Iterator<FileItemResult> iteratorLocal = fileItemListLocal.iterator();
// while (iteratorLocal.hasNext()) {
// FileItemResult fileItemResult = iteratorLocal.next();
// String path = normalizePath(fileItemResult.getPath());
// String name = fileItemResult.getName();
// String uniqueKey = path + name; // 唯一标识
//
// if (seenLocalPaths.contains(uniqueKey)) {
// // 如果已经存在则移除当前项
// iteratorLocal.remove();
// } else {
// // 如果不存在则添加到已处理集合中并更新 path
// seenLocalPaths.add(uniqueKey);
// fileItemResult.setPath(path);
// }
// }
//
// // 对比文件
// tsFiles = compareFiles(fileItemListMinio, fileItemListLocal, storageSourceConfig.getValue(), storageSourceConfig1.getValue());
// LOGGER.info("minio文件 " + fileItemListMinio);
// LOGGER.info("本地文件 " + fileItemListLocal);
//
// } catch (Exception e) {
// e.printStackTrace();
// }
// return tsFiles;
// }
//
//
//
//
// public TsFiles compareFiles(List<FileItemResult> fileItemListMinio, List<FileItemResult> fileItemListLocal, String filePath, String bucketName) {
// TsFiles tsFiles = new TsFiles();
//
// // MinIO 文件列表转换为 Map文件名 -> 文件信息
// Map<String, FileItemResult> minioFileMap = new HashMap<>();
// for (FileItemResult file : fileItemListMinio) {
// // 处理路径格式
// String path = normalizePath(file.getPath());
// QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
// queryWrapper.eq("file_name", file.getName());
// queryWrapper.eq("backup_path", path);
// TsFiles tsFiles1 = tsFilesMapper.selectOne(queryWrapper);
// if (tsFiles1 != null) {
// file.setId(tsFiles1.getId());
//
// }
//
// minioFileMap.put(path + file.getName(), file);
// }
//
// // 将本地文件列表转换为 Map文件名 -> 文件信息
// Map<String, FileItemResult> localFileMap = new HashMap<>();
// for (FileItemResult file : fileItemListLocal) {
// // 处理路径格式
// String path = normalizePath(file.getPath());
// QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
// queryWrapper.eq("file_name", file.getName());
// queryWrapper.eq("work_path", path);
// TsFiles tsFiles1 = tsFilesMapper.selectOne(queryWrapper);
// if (tsFiles1 != null) {
// file.setId(tsFiles1.getId());
//
// }
// localFileMap.put(path + file.getName(), file);
// }
//
// // 检查本地有而 MinIO 没有的文件
// List<FileItemResult> localOnlyFiles = new ArrayList<>();
// for (FileItemResult localFile : fileItemListLocal) {
// // 处理路径格式
// String path = normalizePath(localFile.getPath());
// if (!minioFileMap.containsKey(path + localFile.getName())) {
// localOnlyFiles.add(localFile);
// }
// }
// LOGGER.info("本地有而 MinIO 没有的文件:" + localOnlyFiles);
//
// // 检查 MinIO 有而本地没有的文件
// List<FileItemResult> minioOnlyFiles = new ArrayList<>();
// for (FileItemResult minioFile : fileItemListMinio) {
// String path = normalizePath(minioFile.getPath());
// if (!localFileMap.containsKey(path + minioFile.getName())) {
// minioOnlyFiles.add(minioFile);
// }
// }
// LOGGER.info("MinIO 有而本地没有的文件:" + minioOnlyFiles);
//
// // 检查文件大小不一致的文件
// List<String> sizeMismatchedFiles = new ArrayList<>();
//
// // 检查 MD5 不一致的文件
// List<FileItemResult> md5MismatchedFiles = new ArrayList<>();
//
// // 遍历 MinIO 文件
// for (FileItemResult minioFile : fileItemListMinio) {
// String path = normalizePath(minioFile.getPath());
// // 检查 MinIO 文件是否在本地存在
// if (localFileMap.containsKey(path + minioFile.getName())) {
// FileItemResult localFile = localFileMap.get(path + minioFile.getName());
// String localBasePath = filePath + minioFile.getPath();
// // 检查文件是否为文件夹如果是文件夹跳过
// File localFilePath = new File(localBasePath + localFile.getName());
// if (localFilePath.isDirectory()) {
// LOGGER.error("路径指向的是一个文件夹,跳过该文件夹:" + localFilePath.getAbsolutePath());
// continue; // 跳过文件夹
// }
//
// // 检查文件大小是否匹配
// if (minioFile.getSize() != null && localFile.getSize() != null && minioFile.getSize().longValue() != localFile.getSize().longValue()) {
// sizeMismatchedFiles.add(minioFile.getName());
// }
// // 如果文件大小一致进一步检查 MD5
// try {
// // 计算本地文件的 MD5
// String localMD5 = calculateMD5(new FileInputStream(localFilePath));
// if (localMD5 == null || localMD5.isEmpty()) {
// continue;
// }
//
// // 获取 MinIO 文件的 MD5
// String minioMD5;
// AbstractBaseFileService<?> fileServiceMinio = storageSourceContext.getByStorageKey("minio");
// String key = StringUtils.concat(minioFile.getPath(), minioFile.getName()); // 构造文件的 key
// if (minioFile.getSize() <= 5 * 1024 * 1024 * 1024L) { // 小于 5GB使用 ETag
// ObjectMetadata metadata = fileServiceMinio.getObjectMetadata(bucketName, key);
// minioMD5 = metadata.getETag().replace("\"", ""); // 去除 ETag 的引号
// } else { // 大于 5GB手动计算 MD5
// S3Object s3Object = fileServiceMinio.getObject(bucketName, key);
// minioMD5 = calculateMD5(s3Object.getObjectContent());
// }
//
// // 比较 MD5
// if (!minioMD5.equals(localMD5)) {
// minioFile.setLocatMd5(localMD5);
// minioFile.setMinioMd5(minioMD5);
// md5MismatchedFiles.add(minioFile);
// }
// } catch (Exception e) {
// LOGGER.error("计算 MD5 失败:" + e.getMessage());
// }
//
// } else {
// // 如果 MinIO 中没有该文件本地有的情况下跳过该文件
// LOGGER.info("MinIO 中没有该文件,本地有文件,跳过对比: " + minioFile.getName());
// }
// }
// tsFiles.setLocalOnlyFiles(localOnlyFiles);
// tsFiles.setMinioOnlyFiles(minioOnlyFiles);
// tsFiles.setMd5MismatchedFiles(md5MismatchedFiles);
// LOGGER.info("文件大小不一致的文件:" + sizeMismatchedFiles);
// LOGGER.info("文件大小一致但 MD5 不一致的文件:" + md5MismatchedFiles);
// return tsFiles;
//
// }
//
//
// public String calculateMD5(InputStream inputStream) throws Exception {
// MessageDigest md = MessageDigest.getInstance("MD5");
// byte[] buffer = new byte[8192];
// int bytesRead;
// while ((bytesRead = inputStream.read(buffer)) != -1) {
// md.update(buffer, 0, bytesRead);
// }
// byte[] digest = md.digest();
// StringBuilder sb = new StringBuilder();
// for (byte b : digest) {
// sb.append(String.format("%02x", b));
// }
// return sb.toString();
// }
/*******************************************************本地和minio对比结束****************************************************************/
@ -3968,6 +3608,8 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
FileItemResult fileItemResult = fileService.getFileItem(path);
if (fileItemResult != null || fileItemResult.getName() != null) {
dto.setUrl(fileItemResult.getUrl());
String ProcessingPath = processingPath(fileItemResult.getPath(), node.getNodeId());
dto.setPath(ProcessingPath);
//如果是压缩文件 类型就给zip
boolean isValid = hasValidExtension(fileItemResult.getName(), sysDictionaryItems);
if (isValid) {
@ -3975,6 +3617,9 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
} else {
dto.setType(fileItemResult.getType().getValue());
}
} else {
dto.setUrl(null);
dto.setType(null);
}
}
@ -3995,8 +3640,8 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
if (fileItemResult == null) {
dto.setUrl(null);
dto.setType(null);
} else {
dto.setUrl(fileItemResult.getUrl());
//如果是压缩文件 类型就给zip
boolean isValid = hasValidExtension(fileItemResult.getName(), sysDictionaryItems);
@ -4009,10 +3654,41 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
}
}
// 设置路径字段
dto.setPath(isLocal ? node.getWorkPath() : node.getBackupPath());
if (isLocal) {
String ProcessingPath = processingPath(node.getWorkPath(), node.getNodeId());
dto.setPath(ProcessingPath);
} else {
String ProcessingPath = processingPath(node.getBackupPath(), node.getNodeId());
dto.setPath(ProcessingPath);
}
return dto;
}
public String processingPath(String Path, String nodeId) {
String newWorkPath = "";
if(Path == null || nodeId == null){
return newWorkPath;
}
// 获取原始路径和 nodeId
String workPath1 = Path;
// 拼接需要去掉的部分
String toRemove = File.separator + nodeId;
// 将路径分隔符统一为 "/"
String standardizedWorkPath = workPath1.replace("\\", "/");
String standardizedToRemove = toRemove.replace("\\", "/");
// 检查 standardizedWorkPath 是否包含 standardizedToRemove
if (standardizedWorkPath.contains(standardizedToRemove)) {
// 去掉目标部分
newWorkPath = standardizedWorkPath.replace(standardizedToRemove, "");
// 确保路径最后保留一个 '/'
if (!newWorkPath.endsWith("/")) {
newWorkPath += "/";
}
}
return newWorkPath;
}
/*******************************************读取文件内容经纬度**************************************************************/

View File

@ -88,14 +88,14 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
***********************************/
@Override
public Boolean addSdproject(Project project) {
//查询字典表获取项目类型对应数据字典
QueryWrapper<SysDictionaryItems> queryWrapperSysDictionary = new QueryWrapper<>();
queryWrapperSysDictionary.eq("parentcode", "compressType");
queryWrapperSysDictionary.orderByAsc("orderno");
SysDictionaryItems sysDictionaryItems = sysDictionaryItemsMapper.selectOne(queryWrapperSysDictionary);
if(sysDictionaryItems != null){
project.setProjectType(sysDictionaryItems.getDictName());
}
// //查询字典表获取项目类型对应数据字典
// QueryWrapper<SysDictionaryItems> queryWrapperSysDictionary = new QueryWrapper<>();
// queryWrapperSysDictionary.eq("parentcode", "compressType");
// queryWrapperSysDictionary.orderByAsc("orderno");
// SysDictionaryItems sysDictionaryItems = sysDictionaryItemsMapper.selectOne(queryWrapperSysDictionary);
// if(sysDictionaryItems != null){
// project.setProjectType(sysDictionaryItems.getDictName());
// }
//TODO 01.21沟通以后说是先不用管重复校验问题