优化专项文档分页查询
This commit is contained in:
parent
e8b25d4455
commit
7eccb66643
@ -70,8 +70,6 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
@ -220,11 +218,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
queryWrapper.eq("parent_id", "00");
|
queryWrapper.eq("parent_id", "00");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// // 无ID时:childNode=1则查根目录,childNode=0查全表
|
|
||||||
// if (childNode != null && childNode.equals("1")) {
|
|
||||||
// queryWrapper.eq("parent_id", "00");
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
queryWrapper.isNotNull("work_path");
|
queryWrapper.isNotNull("work_path");
|
||||||
@ -262,8 +255,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
if (tsFiles.getUpdateTime() == null) {
|
if (tsFiles.getUpdateTime() == null) {
|
||||||
tsFiles.setUpdateTime(tsFiles.getUploadTime());
|
tsFiles.setUpdateTime(tsFiles.getUploadTime());
|
||||||
}
|
}
|
||||||
// String ProcessingPath = processingPath(tsFiles.getWorkPath(), nodeId);
|
|
||||||
// tsFiles.setWorkPath(ProcessingPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1670,17 +1662,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成压缩文件路径(去除源文件扩展名)
|
|
||||||
*/
|
|
||||||
private Path getCompressedFilePath(Path sourcePath, String extension) {
|
|
||||||
String fileName = sourcePath.getFileName().toString();
|
|
||||||
String baseName = fileName.contains(".")
|
|
||||||
? fileName.substring(0, fileName.lastIndexOf('.'))
|
|
||||||
: fileName;
|
|
||||||
return sourcePath.resolveSibling(baseName + "." + extension);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ================== TAR格式压缩实现 ==================
|
// ================== TAR格式压缩实现 ==================
|
||||||
|
|
||||||
@ -4395,13 +4376,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
return path.endsWith("/") ? path : path + "/";
|
return path.endsWith("/") ? path : path + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前用户(封装重复逻辑)
|
|
||||||
*/
|
|
||||||
private LoginUser getCurrentUser() {
|
|
||||||
return (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关键安全校验
|
* 关键安全校验
|
||||||
*/
|
*/
|
||||||
@ -4439,7 +4413,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
queryWrapper.eq("task_id", taskId);
|
queryWrapper.eq("task_id", taskId);
|
||||||
}
|
}
|
||||||
queryWrapper.isNotNull("work_path").ne("work_path", "");
|
queryWrapper.isNotNull("work_path").ne("work_path", "");
|
||||||
// queryWrapper.eq("parent_id", "00");
|
|
||||||
|
|
||||||
List<TsFiles> allNodes = tsFilesMapper.selectList(queryWrapper);
|
List<TsFiles> allNodes = tsFilesMapper.selectList(queryWrapper);
|
||||||
|
|
||||||
@ -4620,14 +4593,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 设置路径字段
|
// 设置路径字段
|
||||||
// if (isLocal) {
|
|
||||||
// String ProcessingPath = processingPath(node.getWorkPath(), node.getNodeId());
|
|
||||||
// dto.setPath(ProcessingPath);
|
|
||||||
// } else {
|
|
||||||
// String ProcessingPath = processingPath(node.getBackupPath(), node.getNodeId());
|
|
||||||
// dto.setPath(ProcessingPath);
|
|
||||||
// }
|
|
||||||
// 设置路径字段
|
|
||||||
if (isLocal) {
|
if (isLocal) {
|
||||||
String ProcessingPath = node.getWorkPath();
|
String ProcessingPath = node.getWorkPath();
|
||||||
dto.setPath(ProcessingPath);
|
dto.setPath(ProcessingPath);
|
||||||
@ -4642,29 +4607,29 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String processingPath(String Path, String nodeId) {
|
// public String processingPath(String Path, String nodeId) {
|
||||||
String newWorkPath = "";
|
// String newWorkPath = "";
|
||||||
if (Path == null || nodeId == null) {
|
// if (Path == null || nodeId == null) {
|
||||||
return newWorkPath;
|
// return newWorkPath;
|
||||||
}
|
// }
|
||||||
// 获取原始路径和 nodeId
|
// // 获取原始路径和 nodeId
|
||||||
String workPath1 = Path;
|
// String workPath1 = Path;
|
||||||
// 拼接需要去掉的部分
|
// // 拼接需要去掉的部分
|
||||||
String toRemove = File.separator + nodeId;
|
// String toRemove = File.separator + nodeId;
|
||||||
// 将路径分隔符统一为 "/"
|
// // 将路径分隔符统一为 "/"
|
||||||
String standardizedWorkPath = workPath1.replace("\\", "/");
|
// String standardizedWorkPath = workPath1.replace("\\", "/");
|
||||||
String standardizedToRemove = toRemove.replace("\\", "/");
|
// String standardizedToRemove = toRemove.replace("\\", "/");
|
||||||
// 检查 standardizedWorkPath 是否包含 standardizedToRemove
|
// // 检查 standardizedWorkPath 是否包含 standardizedToRemove
|
||||||
if (standardizedWorkPath.contains(standardizedToRemove)) {
|
// if (standardizedWorkPath.contains(standardizedToRemove)) {
|
||||||
// 去掉目标部分
|
// // 去掉目标部分
|
||||||
newWorkPath = standardizedWorkPath.replace(standardizedToRemove, "");
|
// newWorkPath = standardizedWorkPath.replace(standardizedToRemove, "");
|
||||||
// 确保路径最后保留一个 '/'
|
// // 确保路径最后保留一个 '/'
|
||||||
if (!newWorkPath.endsWith("/")) {
|
// if (!newWorkPath.endsWith("/")) {
|
||||||
newWorkPath += "/";
|
// newWorkPath += "/";
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return newWorkPath;
|
// return newWorkPath;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
/*******************************************读取文件内容经纬度**************************************************************/
|
/*******************************************读取文件内容经纬度**************************************************************/
|
||||||
|
@ -22,9 +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.ITsFilesService;
|
||||||
import com.yfd.platform.modules.experimentalData.service.ITsNodesService;
|
import com.yfd.platform.modules.experimentalData.service.ITsNodesService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.yfd.platform.modules.specialDocument.domain.Files;
|
|
||||||
import com.yfd.platform.modules.specialDocument.domain.Nodes;
|
|
||||||
import com.yfd.platform.modules.specialDocument.domain.Project;
|
|
||||||
import com.yfd.platform.modules.storage.context.StorageSourceContext;
|
import com.yfd.platform.modules.storage.context.StorageSourceContext;
|
||||||
import com.yfd.platform.modules.storage.mapper.StorageSourceConfigMapper;
|
import com.yfd.platform.modules.storage.mapper.StorageSourceConfigMapper;
|
||||||
import com.yfd.platform.modules.storage.model.entity.StorageSourceConfig;
|
import com.yfd.platform.modules.storage.model.entity.StorageSourceConfig;
|
||||||
@ -37,7 +34,6 @@ import com.yfd.platform.modules.storage.service.base.AbstractBaseFileService;
|
|||||||
import com.yfd.platform.system.domain.LoginUser;
|
import com.yfd.platform.system.domain.LoginUser;
|
||||||
import com.yfd.platform.utils.StringUtils;
|
import com.yfd.platform.utils.StringUtils;
|
||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
import lombok.val;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -358,22 +354,6 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
|||||||
LOGGER.error("节点新增成功,但是local创建文件失败");
|
LOGGER.error("节点新增成功,但是local创建文件失败");
|
||||||
return ResponseResult.error();
|
return ResponseResult.error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// //判断文件夹是否创建
|
|
||||||
// AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey("local");
|
|
||||||
// boolean flag = fileService.isFolderCreated(File.separator + tsnodes.getNodeId());
|
|
||||||
// //如果是false 说明没有创建 那就新建一个文件夹
|
|
||||||
// if (!flag) {
|
|
||||||
// //本地创建文件夹
|
|
||||||
// AbstractBaseFileService<?> fileServiceData = storageSourceContext.getByStorageKey("local");
|
|
||||||
// boolean flagData = fileServiceData.newFolder(File.separator, tsnodes.getNodeId());
|
|
||||||
// if (!flagData) {
|
|
||||||
// LOGGER.error("创建节点文件夹失败!");
|
|
||||||
// return ResponseResult.error("新增节点失败!");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return ResponseResult.success();
|
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("tsnodes表结构增加失败");
|
LOGGER.error("tsnodes表结构增加失败");
|
||||||
return ResponseResult.error();
|
return ResponseResult.error();
|
||||||
@ -476,19 +456,6 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
|||||||
tsFilesMapper.delete(deleteWrapper);
|
tsFilesMapper.delete(deleteWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
// //查询所有的文件
|
|
||||||
// QueryWrapper<TsFiles> queryWrapper1 = new QueryWrapper<>();
|
|
||||||
// queryWrapper1.in("node_id", nodeIds);
|
|
||||||
// queryWrapper1.eq("task_id", tsNodes.getTaskId());
|
|
||||||
// List<TsFiles> tsFiles = tsFilesMapper.selectList(queryWrapper1);
|
|
||||||
// //获取所有文件的ID集合
|
|
||||||
// List<String> dataset = new ArrayList<>();
|
|
||||||
// if (tsFiles != null && !tsFiles.isEmpty()) {
|
|
||||||
// dataset.addAll(tsFiles.stream()
|
|
||||||
// .map(TsFiles::getId)
|
|
||||||
// .collect(Collectors.toList()));
|
|
||||||
// }
|
|
||||||
|
|
||||||
//删除当前节点的文件夹 todo 这个地方改动
|
//删除当前节点的文件夹 todo 这个地方改动
|
||||||
// 删除 sdlocal 中的文件夹
|
// 删除 sdlocal 中的文件夹
|
||||||
List<BatchDeleteRequest.DeleteItem> deleteItemList = new ArrayList<>();
|
List<BatchDeleteRequest.DeleteItem> deleteItemList = new ArrayList<>();
|
||||||
@ -702,21 +669,6 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
|||||||
jsonObject.putOpt("status", "1");
|
jsonObject.putOpt("status", "1");
|
||||||
return ResponseResult.successData(jsonObject);
|
return ResponseResult.successData(jsonObject);
|
||||||
}
|
}
|
||||||
// //递归查询所有的子节点
|
|
||||||
// List<TsNodes> tsNodesList = selectChildrentsNodes(tsNodes.getNodeId(), tsNodes.getTaskId());
|
|
||||||
// // 提取所有节点的 ID
|
|
||||||
// List<String> nodeIds = tsNodesList.stream()
|
|
||||||
// .map(TsNodes::getNodeId) // 获取每个节点的 ID
|
|
||||||
// .collect(Collectors.toList());
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// LambdaQueryWrapper<TsFiles> queryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
// queryWrapper.eq(TsFiles::getTaskId, tsNodes.getTaskId())
|
|
||||||
// .in(TsFiles::getNodeId, nodeIds)
|
|
||||||
// .and(wrapper -> wrapper.isNotNull(TsFiles::getBackupPath)
|
|
||||||
// .or().ne(TsFiles::getBackupPath, ""));
|
|
||||||
|
|
||||||
|
|
||||||
//SQL通过节点ID 递归查询节点下面的所有子节点 以及files表中 backup_path IS NOT NULL
|
//SQL通过节点ID 递归查询节点下面的所有子节点 以及files表中 backup_path IS NOT NULL
|
||||||
int count = tsFilesService.countFiles(id);
|
int count = tsFilesService.countFiles(id);
|
||||||
//如果大于0不让删
|
//如果大于0不让删
|
||||||
@ -842,18 +794,6 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
|||||||
double fileSizeInKB = bytes / (1024.0);
|
double fileSizeInKB = bytes / (1024.0);
|
||||||
String fileSizeFormatted = String.format("%.2f", fileSizeInKB); // 保留两位小数
|
String fileSizeFormatted = String.format("%.2f", fileSizeInKB); // 保留两位小数
|
||||||
tsFiles1.setFileSize(fileSizeFormatted);
|
tsFiles1.setFileSize(fileSizeFormatted);
|
||||||
|
|
||||||
|
|
||||||
// if ("null".equals(String.valueOf(subDir.length()))) {
|
|
||||||
// tsFiles1.setFileSize("0.001");
|
|
||||||
// } else {
|
|
||||||
// //文件大小
|
|
||||||
// if ("0.000".equals(String.valueOf(subDir.length()))) {
|
|
||||||
// tsFiles1.setFileSize("0.001");
|
|
||||||
// } else {
|
|
||||||
// tsFiles1.setFileSize(String.valueOf(subDir.length()));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
tsFilesToCreate.add(tsFiles1);
|
tsFilesToCreate.add(tsFiles1);
|
||||||
}
|
}
|
||||||
LOGGER.info("[构建文件表中的文件夹列表] 耗时 {} ms | 待处理数量: {} 条",
|
LOGGER.info("[构建文件表中的文件夹列表] 耗时 {} ms | 待处理数量: {} 条",
|
||||||
@ -895,16 +835,6 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
|||||||
double fileSizeInKB = bytes / (1024.0);
|
double fileSizeInKB = bytes / (1024.0);
|
||||||
String fileSizeFormatted = String.format("%.2f", fileSizeInKB); // 保留两位小数
|
String fileSizeFormatted = String.format("%.2f", fileSizeInKB); // 保留两位小数
|
||||||
tsFiles1.setFileSize(fileSizeFormatted);
|
tsFiles1.setFileSize(fileSizeFormatted);
|
||||||
// if ("null".equals(String.valueOf(file.length()))) {
|
|
||||||
// tsFiles1.setFileSize("0.001");
|
|
||||||
// } else {
|
|
||||||
// //文件大小
|
|
||||||
// if ("0.000".equals(String.valueOf(file.length()))) {
|
|
||||||
// tsFiles1.setFileSize("0.001");
|
|
||||||
// } else {
|
|
||||||
// tsFiles1.setFileSize(String.valueOf(file.length()));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
tsFilesToCreate.add(tsFiles1);
|
tsFilesToCreate.add(tsFiles1);
|
||||||
}
|
}
|
||||||
LOGGER.info("[构建文件表中的文件列表] 耗时 {} ms | 待处理数量: {} 条",
|
LOGGER.info("[构建文件表中的文件列表] 耗时 {} ms | 待处理数量: {} 条",
|
||||||
|
@ -10,6 +10,7 @@ import com.yfd.platform.config.ResponseResult;
|
|||||||
import com.yfd.platform.modules.experimentalData.domain.TsFiles;
|
import com.yfd.platform.modules.experimentalData.domain.TsFiles;
|
||||||
import com.yfd.platform.modules.specialDocument.domain.Files;
|
import com.yfd.platform.modules.specialDocument.domain.Files;
|
||||||
import com.yfd.platform.modules.specialDocument.service.IFilesService;
|
import com.yfd.platform.modules.specialDocument.service.IFilesService;
|
||||||
|
import com.yfd.platform.modules.storage.model.result.FileItemResult;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -153,5 +154,22 @@ public class FilesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 获取专项文档文件url
|
||||||
|
* 参数说明 id 文件ID
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回文件信息
|
||||||
|
***********************************/
|
||||||
|
@Log(module = "专项文档管理", value = "获取专项文档文件url!")
|
||||||
|
@PostMapping("/sdLocalUrl")
|
||||||
|
@ApiOperation("获取专项文档文件url")
|
||||||
|
public ResponseResult sdLocalUrl(String id) {
|
||||||
|
if (StrUtil.isBlank(id)) {
|
||||||
|
return ResponseResult.error("参数为空");
|
||||||
|
}
|
||||||
|
//查询本地树和minio树
|
||||||
|
FileItemResult fileItemResult = filesService.sdLocalUrl(id);
|
||||||
|
return ResponseResult.successData(fileItemResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import com.yfd.platform.config.ResponseResult;
|
|||||||
import com.yfd.platform.modules.experimentalData.domain.TsFiles;
|
import com.yfd.platform.modules.experimentalData.domain.TsFiles;
|
||||||
import com.yfd.platform.modules.specialDocument.domain.Files;
|
import com.yfd.platform.modules.specialDocument.domain.Files;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.yfd.platform.modules.storage.model.result.FileItemResult;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -62,4 +63,11 @@ public interface IFilesService extends IService<Files> {
|
|||||||
String deleteFilesByIds(List<String> dataset);
|
String deleteFilesByIds(List<String> dataset);
|
||||||
|
|
||||||
IPage<Files> getCachedFilesPage(String projectId, String nodeId, int currentPage);
|
IPage<Files> getCachedFilesPage(String projectId, String nodeId, int currentPage);
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 获取专项文档文件url
|
||||||
|
* 参数说明 id 文件ID
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回文件信息
|
||||||
|
***********************************/
|
||||||
|
FileItemResult sdLocalUrl(String id);
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,10 @@ import cn.hutool.core.collection.CollUtil;
|
|||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.json.JSONObject;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.config.ResponseResult;
|
||||||
import com.yfd.platform.exception.file.InvalidStorageSourceException;
|
import com.yfd.platform.exception.file.InvalidStorageSourceException;
|
||||||
import com.yfd.platform.modules.config.model.request.FileListRequest;
|
import com.yfd.platform.modules.config.model.request.FileListRequest;
|
||||||
@ -46,7 +44,6 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
|
|||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -61,7 +58,6 @@ import java.sql.Timestamp;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -120,47 +116,47 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
|||||||
|
|
||||||
//先查询路径下的所有文件
|
//先查询路径下的所有文件
|
||||||
//首先通过项目ID 和节点ID去查询表 获取一个路径 如果不是空 就调用minio的获取文件列表接口 查询的数据放在集合中
|
//首先通过项目ID 和节点ID去查询表 获取一个路径 如果不是空 就调用minio的获取文件列表接口 查询的数据放在集合中
|
||||||
FileInfoResult fileInfoResult = null;
|
// FileInfoResult fileInfoResult = null;
|
||||||
|
//
|
||||||
QueryWrapper<Files> queryWrapper = new QueryWrapper<>();
|
// QueryWrapper<Files> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("project_id", projectId);
|
// queryWrapper.eq("project_id", projectId);
|
||||||
queryWrapper.eq("node_id", nodeId);
|
// queryWrapper.eq("node_id", nodeId);
|
||||||
List<Files> filess = filesMapper.selectList(queryWrapper);
|
// List<Files> filess = filesMapper.selectList(queryWrapper);
|
||||||
String filePath = null;
|
// String filePath = null;
|
||||||
if (filess != null && !filess.isEmpty()) {
|
// if (filess != null && !filess.isEmpty()) {
|
||||||
for (Files files : filess) {
|
// for (Files files : filess) {
|
||||||
filePath = files.getFilePath();
|
// filePath = files.getFilePath();
|
||||||
if (filePath != null && !filePath.isEmpty()) {
|
// if (filePath != null && !filePath.isEmpty()) {
|
||||||
break; // 如果找到非空的 filePath,终止循环
|
// break; // 如果找到非空的 filePath,终止循环
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (filePath != null) {
|
// if (filePath != null) {
|
||||||
FileListRequest fileListRequest = new FileListRequest();
|
// FileListRequest fileListRequest = new FileListRequest();
|
||||||
fileListRequest.setOrderBy("time");
|
// fileListRequest.setOrderBy("time");
|
||||||
fileListRequest.setOrderDirection("desc");
|
// fileListRequest.setOrderDirection("desc");
|
||||||
fileListRequest.setPassword("");
|
// fileListRequest.setPassword("");
|
||||||
fileListRequest.setPath(filePath);
|
// fileListRequest.setPath(filePath);
|
||||||
fileListRequest.setStorageKey("sdlocal");
|
// fileListRequest.setStorageKey("sdlocal");
|
||||||
|
//
|
||||||
String storageKey = fileListRequest.getStorageKey();
|
// String storageKey = fileListRequest.getStorageKey();
|
||||||
Integer storageId = storageSourceService.findIdByKey(storageKey);
|
// Integer storageId = storageSourceService.findIdByKey(storageKey);
|
||||||
if (storageId == null) {
|
// if (storageId == null) {
|
||||||
throw new InvalidStorageSourceException("通过存储源 key 未找到存储源, key: " + storageKey);
|
// throw new InvalidStorageSourceException("通过存储源 key 未找到存储源, key: " + storageKey);
|
||||||
}
|
// }
|
||||||
// 处理请求参数默认值
|
// // 处理请求参数默认值
|
||||||
fileListRequest.handleDefaultValue();
|
// fileListRequest.handleDefaultValue();
|
||||||
// 获取文件列表
|
// // 获取文件列表
|
||||||
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageId(storageId);
|
// AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageId(storageId);
|
||||||
List<FileItemResult> fileItemList = fileService.fileList(fileListRequest.getPath());
|
// List<FileItemResult> fileItemList = fileService.fileList(fileListRequest.getPath());
|
||||||
// 执行责任链
|
// // 执行责任链
|
||||||
FileContext fileContext = FileContext.builder()
|
// FileContext fileContext = FileContext.builder()
|
||||||
.storageId(storageId)
|
// .storageId(storageId)
|
||||||
.fileListRequest(fileListRequest)
|
// .fileListRequest(fileListRequest)
|
||||||
.fileItemList(fileItemList).build();
|
// .fileItemList(fileItemList).build();
|
||||||
fileChain.execute(fileContext);
|
// fileChain.execute(fileContext);
|
||||||
fileInfoResult = new FileInfoResult(fileContext.getFileItemList(), fileContext.getPasswordPattern());
|
// fileInfoResult = new FileInfoResult(fileContext.getFileItemList(), fileContext.getPasswordPattern());
|
||||||
}
|
// }
|
||||||
|
|
||||||
//分页查询专项文档管理-文档内容
|
//分页查询专项文档管理-文档内容
|
||||||
LambdaQueryWrapper<Files> queryWrapperfiles = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<Files> queryWrapperfiles = new LambdaQueryWrapper<>();
|
||||||
@ -186,27 +182,27 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
|||||||
//分页查询
|
//分页查询
|
||||||
Page<Files> filesPage = filesMapper.selectPage(page, queryWrapperfiles);
|
Page<Files> filesPage = filesMapper.selectPage(page, queryWrapperfiles);
|
||||||
//处理文件内容
|
//处理文件内容
|
||||||
List<Files> records = filesPage.getRecords();
|
// List<Files> records = filesPage.getRecords();
|
||||||
for (Files files : records) {
|
// for (Files files : records) {
|
||||||
//循环从minio拿出来的数据 然后把url放到files里面
|
// //循环从minio拿出来的数据 然后把url放到files里面
|
||||||
files.setUrl("");
|
// files.setUrl("");
|
||||||
files.setType("");
|
// files.setType("");
|
||||||
List<FileItemResult> filelist = fileInfoResult.getFiles();
|
// List<FileItemResult> filelist = fileInfoResult.getFiles();
|
||||||
if (filelist != null && !filelist.isEmpty()) {
|
// if (filelist != null && !filelist.isEmpty()) {
|
||||||
for (FileItemResult fileItemResult : filelist) {
|
// for (FileItemResult fileItemResult : filelist) {
|
||||||
if (fileItemResult.getUrl() == null || fileItemResult.getUrl().isEmpty()) {
|
// if (fileItemResult.getUrl() == null || fileItemResult.getUrl().isEmpty()) {
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
if (files.getFileName().equals(fileItemResult.getName())) {
|
// if (files.getFileName().equals(fileItemResult.getName())) {
|
||||||
files.setUrl(fileItemResult.getUrl());
|
// files.setUrl(fileItemResult.getUrl());
|
||||||
files.setType(fileItemResult.getType().getValue());
|
// files.setType(fileItemResult.getType().getValue());
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
filesPage.setRecords(records);
|
// filesPage.setRecords(records);
|
||||||
int currentPage = (int) page.getCurrent();
|
int currentPage = (int) page.getCurrent();
|
||||||
// 如果是前五页,将结果存入Redis(有效期建议30分钟)
|
// 如果是前五页,将结果存入Redis(有效期建议30分钟)
|
||||||
if (StrUtil.isBlank(fileName) && StrUtil.isBlank(keywords) && StrUtil.isBlank(startDate) && StrUtil.isBlank(endDate)) {
|
if (StrUtil.isBlank(fileName) && StrUtil.isBlank(keywords) && StrUtil.isBlank(startDate) && StrUtil.isBlank(endDate)) {
|
||||||
@ -218,6 +214,22 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
|||||||
return filesPage;
|
return filesPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**********************************
|
||||||
|
* 用途说明: 获取专项文档文件url
|
||||||
|
* 参数说明 id 文件ID
|
||||||
|
* 返回值说明: com.yfd.platform.config.ResponseResult 返回文件信息
|
||||||
|
***********************************/
|
||||||
|
@Override
|
||||||
|
public FileItemResult sdLocalUrl(String id) {
|
||||||
|
FileItemResult fileItemResult = new FileItemResult();
|
||||||
|
Files files = filesMapper.selectById(id);
|
||||||
|
String pathAndName = files.getFilePath() + files.getFileName();
|
||||||
|
//准备获取文件的信息
|
||||||
|
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey("sdlocal");
|
||||||
|
fileItemResult = fileService.getFileItem(pathAndName);
|
||||||
|
return fileItemResult;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存中获取节点文件
|
* 缓存中获取节点文件
|
||||||
*
|
*
|
||||||
@ -252,6 +264,8 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
|||||||
return null; // 或返回空分页对象 new Page<>(0)
|
return null; // 或返回空分页对象 new Page<>(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean isValidPage(IPage<Files> page) {
|
private boolean isValidPage(IPage<Files> page) {
|
||||||
return page.getRecords() != null
|
return page.getRecords() != null
|
||||||
&& !page.getRecords().isEmpty()
|
&& !page.getRecords().isEmpty()
|
||||||
|
Loading…
Reference in New Issue
Block a user