优化代码提交

This commit is contained in:
lilin 2025-06-25 14:36:15 +08:00
parent 6a8ba92485
commit fe39197754
11 changed files with 42 additions and 37 deletions

View File

@ -14,8 +14,6 @@ import com.yfd.platform.modules.experimentalData.domain.TsTask;
import com.yfd.platform.modules.experimentalData.service.ITsFilesService;
import com.yfd.platform.modules.experimentalData.service.ITsNodesService;
import com.yfd.platform.modules.experimentalData.service.ITsTaskService;
import com.yfd.platform.modules.specialDocument.domain.Files;
import com.yfd.platform.modules.specialDocument.domain.Nodes;
import com.yfd.platform.system.domain.LoginUser;
import com.yfd.platform.utils.TableNameContextHolder;
import io.swagger.annotations.ApiOperation;
@ -26,7 +24,6 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

View File

@ -5,13 +5,11 @@ import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.platform.annotation.Log;
import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.modules.experimentalData.domain.TsTask;
import com.yfd.platform.modules.experimentalData.service.ITsTaskService;
import com.yfd.platform.modules.specialDocument.domain.Project;
import com.yfd.platform.utils.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;

View File

@ -171,6 +171,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
TsTask tsTask = tsTaskMapper.selectById(taskId);
TableNameContextHolder.setTaskCode(tsTask.getTaskCode());
StorageSource storageSource = getStorageConfig(tsTask.getLocalStorageId());
QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
// 固定条件过滤
@ -248,7 +249,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
//主要是用于文件路径加名称
String path = tsFiles.getWorkPath() + fileNameData;
//准备获取文件的信息
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey("local");
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey(storageSource.getKey());
FileItemResult fileItemResult = fileService.getFileItem(path);
if (fileItemResult == null || fileItemResult.getName() == null) {
LOGGER.error("{}文件没有上传到工作空间,请重新选择上传", fileNameData);
@ -447,6 +448,8 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
try {
TsTask tsTask = tsTaskMapper.selectById(tsFiles.getTaskId());
TableNameContextHolder.setTaskCode(tsTask.getTaskCode());
StorageSource storageSource = getStorageConfig(tsTask.getLocalStorageId());
// 清理 Redis 缓存
for (int page = 1; page <= 5; page++) {
String redisKey = "tsfiles_" + tsFiles.getTaskId() + "_" + tsFiles.getNodeId() + "_parentId" + tsFiles.getParentId() + "_page_" + page;
@ -486,7 +489,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
String sizeStr = sizes.get(i).trim();
String pathAndName = tsFiles.getWorkPath() + name;
AbstractBaseFileService<?> fileServicefile = storageSourceContext.getByStorageKey("local");
AbstractBaseFileService<?> fileServicefile = storageSourceContext.getByStorageKey(storageSource.getKey());
FileItemResult fileItemResult = fileServicefile.getFileItem(pathAndName);
if (fileItemResult == null || fileItemResult.getName() == null) {
return ResponseResult.error(name + "文件没有上传到工作空间,请重新选择上传!");
@ -977,7 +980,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
BatchDeleteRequest.DeleteItem deleteItemData = new BatchDeleteRequest.DeleteItem();
deleteItemData.setName(files.getFileName());
deleteItemData.setPassword("");
if (storageSource.getKey().equals(type)) {
if ("local".equals(type)) {
deleteItemData.setPath(files.getWorkPath());
} else {
deleteItemData.setPath(files.getBackupPath());
@ -1039,7 +1042,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
BatchDeleteRequest.DeleteItem deleteItemData = new BatchDeleteRequest.DeleteItem();
deleteItemData.setName(files.getFileName());
deleteItemData.setPassword("");
if (storageSource.getKey().equals(type)) {
if ("local".equals(type)) {
deleteItemData.setPath(files.getWorkPath());
} else {
deleteItemData.setPath(files.getBackupPath());
@ -3055,6 +3058,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
TsTask tsTask = tsTaskMapper.selectById(taskId);
TableNameContextHolder.setTaskCode(tsTask.getTaskCode());
StorageSource storageSource = getStorageConfig(tsTask.getBackupStorageId());
// 获取本地文件路径根目录和存储空间名称
StorageSourceConfig filePathConfig = getStorageSourceConfig("filePath", "local",tsTask.getLocalStorageId());
StorageSourceConfig bucketConfig = getStorageSourceConfig("bucketName", "minio",tsTask.getBackupStorageId());
@ -3094,7 +3098,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
// 计算MinIO文件MD5
String minioMD5 = getMinioMD5Data(bucketConfig.getValue(), tsFile.getBackupPath(), tsFile.getFileName());
String minioMD5 = getMinioMD5Data(bucketConfig.getValue(), tsFile.getBackupPath(), tsFile.getFileName(),storageSource);
// 路径处理
//tsFile.setWorkPath(processingPath(tsFile.getWorkPath(), tsFile.getNodeId()));
@ -3140,6 +3144,9 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
try {
TsTask tsTask = tsTaskMapper.selectById(taskId);
TableNameContextHolder.setTaskCode(tsTask.getTaskCode());
StorageSource storageSource = getStorageConfig(tsTask.getBackupStorageId());
// 获取本地文件路径根目录和存储空间名称
StorageSourceConfig filePathConfig = getStorageSourceConfig("filePath", "local",tsTask.getLocalStorageId());
StorageSourceConfig bucketConfig = getStorageSourceConfig("bucketName", "minio",tsTask.getBackupStorageId());
@ -3175,7 +3182,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
// 计算MinIO文件MD5
String minioMD5 = getMinioMD5Data(bucketConfig.getValue(), tsFile.getBackupPath(), tsFile.getFileName());
String minioMD5 = getMinioMD5Data(bucketConfig.getValue(), tsFile.getBackupPath(), tsFile.getFileName(),storageSource);
// 路径处理
// tsFile.setWorkPath(processingPath(tsFile.getWorkPath(), tsFile.getNodeId()));
@ -3255,8 +3262,8 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
}
// 辅助方法获取 MinIO 文件 MD5
private String getMinioMD5Data(String bucketName, String path, String name) {
AbstractBaseFileService<?> minioService = storageSourceContext.getByStorageKey("minio");
private String getMinioMD5Data(String bucketName, String path, String name,StorageSource storageSource) {
AbstractBaseFileService<?> minioService = storageSourceContext.getByStorageKey(storageSource.getKey());
String key = normalizePath(path) + name;
try {
@ -3415,7 +3422,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
return false;
}
//把本地文件上传到minio
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey("minio");
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey(storageSourceMinio.getKey());
boolean flag1 = fileService.UploadFiles(storageSourceConfig1.getValue(), minioPath + name, zipFile);
LOGGER.info("同步本地到minio文件路径加名称" + storageSourceConfig1.getValue() + minioPath + name);
@ -3550,7 +3557,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
return false;
}
//把本地文件上传到minio
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey("minio");
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey(storageSourceMinio.getKey());
boolean flag1 = fileService.UploadFiles(storageSourceConfig1.getValue(), minioPath + name, zipFile);
LOGGER.info("同步本地到minio文件路径加名称" + storageSourceConfig1.getValue() + minioPath + name);
@ -3912,8 +3919,8 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
try {
TsTask tsTask = tsTaskMapper.selectById(parameter.getTaskId());
TableNameContextHolder.setTaskCode(tsTask.getTaskCode());
StorageSource storageSource = getStorageConfig(tsTask.getLocalStorageId());
StorageSource storageSourceLocal = getStorageConfig(tsTask.getLocalStorageId());
StorageSource storageSourceMinio = getStorageConfig(tsTask.getBackupStorageId());
// 设置当前时间
LocalDateTime now = LocalDateTime.now();
// 转换为 Timestamp
@ -3960,7 +3967,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
newFolderRequest.setName(tsFiles.getFileName());//新建的文件夹名称,示例值(/a/b/c)
newFolderRequest.setPassword("");//文件夹密码, 如果文件夹需要密码才能访问则支持请求密码,示例值(123456)
newFolderRequest.setPath(path);//请求路径,示例值(/)
newFolderRequest.setStorageKey(storageSource.getKey());//存储源 key,示例值(local minio)
newFolderRequest.setStorageKey(storageSourceLocal.getKey());//存储源 key,示例值(local minio)
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey(newFolderRequest.getStorageKey());
boolean flag = fileService.newFolder(newFolderRequest.getPath(), newFolderRequest.getName());
LOGGER.info("同步minio到本地文件夹路径加名称" + newFolderRequest.getPath() + newFolderRequest.getName());
@ -4013,7 +4020,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
S3ObjectInputStream inputStream = null; // 输入流
S3Object s3Object = null;
try {
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey("minio");
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey(storageSourceMinio.getKey());
// 获取 MinIO 文件对象
s3Object = fileService.getObject(storageSourceConfig1.getValue(), minioPath);
// 获取文件输入流
@ -4920,6 +4927,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
TsTask tsTask = tsTaskMapper.selectById(taskId);
TableNameContextHolder.setTaskCode(tsTask.getTaskCode());
StorageSource storageSourceLocal = getStorageConfig(tsTask.getLocalStorageId());
TsFiles tsFiles = tsFilesMapper.selectById(id);
String fileNameData = tsFiles.getFileName();
String path = "";
@ -4932,7 +4940,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
}
//准备获取文件的信息
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey(type);
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey(storageSourceLocal.getKey());
fileItemResult = fileService.getFileItem(path);
return fileItemResult;
} catch (Exception e) {

View File

@ -22,7 +22,6 @@ import com.yfd.platform.modules.experimentalData.mapper.TsTaskMapper;
import com.yfd.platform.modules.experimentalData.service.ITsFilesService;
import com.yfd.platform.modules.experimentalData.service.ITsNodesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfd.platform.modules.specialDocument.domain.Nodes;
import com.yfd.platform.modules.storage.context.StorageSourceContext;
import com.yfd.platform.modules.storage.mapper.StorageSourceConfigMapper;
import com.yfd.platform.modules.storage.mapper.StorageSourceMapper;
@ -982,6 +981,8 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
// 存储所有目录和文件的列表
List<TsFiles> tsFilesToCreate = new ArrayList<>();
TsTask tsTask = tsTaskMapper.selectById(taskId);
StorageSource storageSourceLocal = getStorageConfig(tsTask.getLocalStorageId());
// 设置当前时间
LocalDateTime now = LocalDateTime.now();
@ -990,7 +991,7 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
// 查询本地文件路径根目录 E:\yun
QueryWrapper<StorageSourceConfig> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name", "filePath");
queryWrapper.eq("storage_id", "1");
queryWrapper.eq("storage_id", tsTask.getLocalStorageId());
queryWrapper.eq("type", "local");
StorageSourceConfig storageSourceConfig = storageSourceConfigMapper.selectOne(queryWrapper);
//获取文件列表 这个地方path+name

View File

@ -7,7 +7,6 @@ import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.modules.experimentalData.domain.TsFiles;
@ -20,11 +19,9 @@ import com.yfd.platform.modules.experimentalData.service.ITsFilesService;
import com.yfd.platform.modules.experimentalData.service.ITsNodesService;
import com.yfd.platform.modules.experimentalData.service.ITsTaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfd.platform.modules.specialDocument.domain.Project;
import com.yfd.platform.modules.storage.context.StorageSourceContext;
import com.yfd.platform.modules.storage.mapper.StorageSourceMapper;
import com.yfd.platform.modules.storage.model.entity.StorageSource;
import com.yfd.platform.modules.storage.model.entity.StorageSourceConfig;
import com.yfd.platform.modules.storage.model.enums.FileTypeEnum;
import com.yfd.platform.modules.storage.model.request.BatchDeleteRequest;
import com.yfd.platform.modules.storage.model.request.NewFolderRequest;

View File

@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.platform.annotation.Log;
import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.modules.experimentalData.domain.TsFiles;
import com.yfd.platform.modules.specialDocument.domain.Files;
import com.yfd.platform.modules.specialDocument.service.IFilesService;
import com.yfd.platform.modules.storage.model.result.FileItemResult;
@ -15,8 +14,6 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

View File

@ -5,8 +5,6 @@ import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.platform.annotation.Log;
import com.yfd.platform.config.ResponseResult;

View File

@ -3,11 +3,9 @@ package com.yfd.platform.modules.specialDocument.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.modules.experimentalData.domain.TsFiles;
import com.yfd.platform.modules.specialDocument.domain.Files;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yfd.platform.modules.storage.model.result.FileItemResult;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;

View File

@ -5,7 +5,6 @@ import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.platform.config.ResponseResult;
@ -19,7 +18,6 @@ import com.yfd.platform.modules.specialDocument.service.IFilesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfd.platform.modules.storage.chain.FileChain;
import com.yfd.platform.modules.storage.context.StorageSourceContext;
import com.yfd.platform.modules.storage.controller.file.FileController;
import com.yfd.platform.modules.storage.mapper.StorageSourceConfigMapper;
import com.yfd.platform.modules.storage.mapper.StorageSourceMapper;
import com.yfd.platform.modules.storage.model.entity.StorageSource;
@ -27,7 +25,6 @@ import com.yfd.platform.modules.storage.model.entity.StorageSourceConfig;
import com.yfd.platform.modules.storage.model.enums.FileTypeEnum;
import com.yfd.platform.modules.storage.model.request.BatchDeleteRequest;
import com.yfd.platform.modules.storage.model.request.RenameFileRequest;
import com.yfd.platform.modules.storage.model.result.FileInfoResult;
import com.yfd.platform.modules.storage.model.result.FileItemResult;
import com.yfd.platform.modules.storage.service.StorageSourceService;
import com.yfd.platform.modules.storage.service.base.AbstractBaseFileService;

View File

@ -32,7 +32,6 @@ import java.io.IOException;
import java.sql.*;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/**

View File

@ -28,6 +28,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@ -164,9 +165,23 @@ public class StorageSourceConvertImpl implements StorageSourceConvert {
queryWrapperData.eq(StorageSourceConfig::getName, "filePath");
String value = storageSourceConfigMapper.selectOne(queryWrapperData).getValue();
storageSource.setValueData(value);
if(StringUtils.isNotBlank(value)){
String[] values = value.split(";");
// 将结果存入集合
List<String> valueList = Arrays.asList(values);
StringBuilder spaceOccupancyRatio = new StringBuilder();
for (String valueData : valueList){
String percentage = calculateLocalStorageUsage(valueData);
if (spaceOccupancyRatio.length() > 0) {
spaceOccupancyRatio.append(";"); // 添加分号分隔
}
spaceOccupancyRatio.append(percentage);
}
//空间使用率
storageSource.setSpaceOccupancyRatio(calculateLocalStorageUsage(value));
storageSource.setSpaceOccupancyRatio(spaceOccupancyRatio.toString());
}