代码提交
This commit is contained in:
parent
11c17eb3bc
commit
ab0a5a8e81
@ -12,9 +12,12 @@ import com.yfd.platform.modules.experimentalData.domain.TsNodes;
|
||||
import com.yfd.platform.modules.experimentalData.service.ITsNodesService;
|
||||
import com.yfd.platform.modules.experimentalData.service.ITsTaskService;
|
||||
import com.yfd.platform.modules.specialDocument.domain.Nodes;
|
||||
import com.yfd.platform.system.domain.LoginUser;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@ -156,10 +159,12 @@ public class TsNodesController {
|
||||
} else if ("COMPLETED".equals(existingStatus)) {
|
||||
return ResponseResult.success("验数据扫描任务已完成!");
|
||||
}
|
||||
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
LoginUser loginuser = (LoginUser) authentication.getPrincipal();
|
||||
// 原子性启动新任务
|
||||
if (taskStatusHolder.startTaskIfAbsent(asyncKey)) {
|
||||
// 直接异步执行并推送结果
|
||||
tsNodesService.testDataScanByIdAsync(id);
|
||||
tsNodesService.testDataScanByIdAsync(id,loginuser);
|
||||
return ResponseResult.success("验数据扫描任务开始处理!");
|
||||
} else {
|
||||
return ResponseResult.success("验数据扫描任务已由其他请求启动!");
|
||||
|
@ -3,6 +3,7 @@ package com.yfd.platform.modules.experimentalData.service;
|
||||
import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.modules.experimentalData.domain.TsNodes;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yfd.platform.system.domain.LoginUser;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -56,7 +57,7 @@ public interface ITsNodesService extends IService<TsNodes> {
|
||||
* 参数说明 id 试验任务ID
|
||||
* 返回值说明: com.yfd.platform.config.ResponseResult 返回成功或者失败
|
||||
***********************************/
|
||||
void testDataScanByIdAsync(String id) throws Exception;
|
||||
void testDataScanByIdAsync(String id, LoginUser loginuser) throws Exception;
|
||||
|
||||
/**********************************
|
||||
* 用途说明: 根据ID确认是否可以实验任务项目
|
||||
|
@ -312,20 +312,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
|
||||
return null; // 或返回空分页对象 new Page<>(0)
|
||||
|
||||
// if (data instanceof IPage<?>) {
|
||||
// // 由于启用了类型信息,可以直接强制转换
|
||||
// @SuppressWarnings("unchecked")
|
||||
// IPage<TsFiles> page = (IPage<TsFiles>) data;
|
||||
// // 检查 records 是否已正确反序列化
|
||||
// if (page.getRecords() != null && !page.getRecords().isEmpty()
|
||||
// && page.getRecords().get(0) instanceof TsFiles) {
|
||||
// return page;
|
||||
// } else {
|
||||
// // 处理可能的反序列化异常
|
||||
// throw new IllegalStateException("反序列化失败,records 类型不正确");
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -464,27 +450,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
return ResponseResult.error("文件名称和文件大小的列表长度不一致!");
|
||||
}
|
||||
|
||||
//
|
||||
// //判断文件夹是否创建
|
||||
// AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey("local");
|
||||
// boolean flag = fileService.isFolderCreated(File.separator + tsFiles.getNodeId());
|
||||
//如果是false 说明没有创建 那就新建一个文件夹
|
||||
// if(!flag){
|
||||
// //本地创建文件夹
|
||||
// NewFolderRequest newFolderRequest = new NewFolderRequest();
|
||||
// newFolderRequest.setStorageKey("local");
|
||||
// newFolderRequest.setPath(tsFiles.getWorkPath());
|
||||
// newFolderRequest.setPassword(null);
|
||||
// newFolderRequest.setName(tsFiles.getFileName());
|
||||
//
|
||||
// AbstractBaseFileService<?> fileServiceData = storageSourceContext.getByStorageKey(newFolderRequest.getStorageKey());
|
||||
// boolean flagData = fileServiceData.newFolder(newFolderRequest.getPath(), newFolderRequest.getName());
|
||||
// if(!flagData){
|
||||
// LOGGER.error("创建节点文件夹失败!");
|
||||
// return ResponseResult.error("新增文件失败!");
|
||||
// }
|
||||
// }
|
||||
|
||||
List<TsFiles> filesToSave = new ArrayList<>();
|
||||
// 设置当前时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
@ -1321,9 +1286,9 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
|
||||
// 获取文件大小(字节)
|
||||
long fileSizeInBytes = zipFilePath.toFile().length();
|
||||
// 转换为 MB 并保留两位小数
|
||||
double fileSizeInMB = fileSizeInBytes / (1024.0 * 1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInMB); // 保留两位小数
|
||||
// 转换为 KB 并保留两位小数
|
||||
double fileSizeInKB = fileSizeInBytes / (1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInKB); // 保留两位小数
|
||||
// 设置文件大小
|
||||
tsFiles.setFileSize(fileSizeFormatted);
|
||||
//tsFiles.setFileSize(String.valueOf(zipFilePath.toFile().length()));
|
||||
@ -1414,26 +1379,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
.filter(s -> !s.isEmpty())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// // 校验路径是否以nodeId开头
|
||||
// if (pathSegments.isEmpty() || !pathSegments.get(0).equals(nodeId)) {
|
||||
// throw new RuntimeException("路径必须包含当前节点ID");
|
||||
// }
|
||||
// String nodePath = "/" + nodeId + "/";
|
||||
// if (compressedPath.equals(nodePath)) {
|
||||
// return "00";
|
||||
// }
|
||||
|
||||
|
||||
// 提取实际要处理的目录层级(去掉开头的nodeId)
|
||||
// List<String> dirSegments = null;
|
||||
// if (pathSegments.size() > 1) {
|
||||
// // 如果 pathSegments 大于 1,去掉 nodeId
|
||||
// dirSegments = pathSegments.subList(1, pathSegments.size());
|
||||
// }
|
||||
// if (dirSegments.isEmpty()) {
|
||||
// throw new RuntimeException("路径缺少有效目录层级");
|
||||
// }
|
||||
|
||||
|
||||
// 2. 初始化根目录信息(基于nodeId)
|
||||
String parentId = "00"; // 根目录的父ID为0
|
||||
@ -1867,10 +1812,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
}
|
||||
}
|
||||
|
||||
// ================== 通用工具方法 ==================
|
||||
private interface EntryProcessor {
|
||||
void process(String entryName, boolean isDir) throws IOException;
|
||||
}
|
||||
|
||||
/*************************************解压缩*******************************************/
|
||||
|
||||
@ -1974,9 +1915,9 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
} else {
|
||||
// 获取文件大小(字节)
|
||||
long fileSizeInBytes = file.length();
|
||||
// 转换为 MB 并保留两位小数
|
||||
double fileSizeInMB = fileSizeInBytes / (1024.0 * 1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInMB); // 保留两位小数
|
||||
// 转换为 KB 并保留两位小数
|
||||
double fileSizeInKB = fileSizeInBytes / (1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInKB); // 保留两位小数
|
||||
|
||||
TsFiles fileRecord = createFileRecord(
|
||||
file.getName(),
|
||||
@ -2091,9 +2032,9 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
||||
|
||||
// 获取文件大小(字节)
|
||||
long fileSizeInBytes = child.length();
|
||||
// 转换为 MB 并保留两位小数
|
||||
double fileSizeInMB = fileSizeInBytes / (1024.0 * 1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInMB); // 保留两位小数
|
||||
// 转换为 KB 并保留两位小数
|
||||
double fileSizeInKB = fileSizeInBytes / (1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInKB); // 保留两位小数
|
||||
// 处理文件(示例:1.txt)
|
||||
TsFiles fileRecord = new TsFiles();
|
||||
fileRecord.setNodeId(nodeId);
|
||||
|
@ -676,10 +676,10 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
***********************************/
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public void testDataScanByIdAsync(String id) throws Exception {
|
||||
public void testDataScanByIdAsync(String id,LoginUser loginuser) throws Exception {
|
||||
try {
|
||||
// 执行扫描并且插入数据库
|
||||
this.testDataScanById(id);
|
||||
this.testDataScanById(id,loginuser);
|
||||
} finally {
|
||||
// 生成唯一Key
|
||||
String asyncKey = taskStatusHolder.testDatascanKey(id);
|
||||
@ -728,7 +728,7 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
return ResponseResult.successData(jsonObject);
|
||||
}
|
||||
|
||||
private String testDataScanById(String id) throws Exception {
|
||||
private String testDataScanById(String id,LoginUser loginuser) throws Exception {
|
||||
|
||||
//查询试验任务信息
|
||||
TsTask tsTask = tsTaskMapper.selectById(id);
|
||||
@ -750,7 +750,7 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
if (fileItemList.size() == 0) {
|
||||
throw new Exception("该试验任务管理项目目录不存在或没有项目文档,请先建立项目目录和文档。");
|
||||
}
|
||||
firstLayerData(fileItemList, id);
|
||||
firstLayerData(fileItemList, id, loginuser);
|
||||
|
||||
return "扫描完成";
|
||||
}
|
||||
@ -762,7 +762,7 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
* @param taskId 所属任务ID
|
||||
* @throws Exception
|
||||
*/
|
||||
public void firstLayerData(List<FileItemResult> fileItemList, String taskId) throws Exception {
|
||||
public void firstLayerData(List<FileItemResult> fileItemList, String taskId,LoginUser loginuser) throws Exception {
|
||||
|
||||
for (FileItemResult item : fileItemList) {
|
||||
//思路就是 如果是文件夹 就查询一下 没有就新增, 新的的时候递归往下走
|
||||
@ -776,9 +776,9 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
//如果没有 新增 并且递归
|
||||
if (nodeData == null) {
|
||||
TsNodes node = savetsNodes(taskId, TOP_LEVEL_PARENT_NODE, item.getName());
|
||||
otherLevelsData(taskId, node.getNodeId(), item.getName(), item.getPath(), TOP_LEVEL_PARENT_NODE);
|
||||
otherLevelsData(taskId, node.getNodeId(), item.getName(), item.getPath(), TOP_LEVEL_PARENT_NODE, loginuser);
|
||||
} else {
|
||||
otherLevelsData(taskId, nodeData.getNodeId(), item.getName(), item.getPath(), TOP_LEVEL_PARENT_NODE);
|
||||
otherLevelsData(taskId, nodeData.getNodeId(), item.getName(), item.getPath(), TOP_LEVEL_PARENT_NODE, loginuser);
|
||||
}
|
||||
|
||||
}
|
||||
@ -793,20 +793,8 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
* @param parentId 父级ID
|
||||
* @return
|
||||
*/
|
||||
private void otherLevelsData(String taskId, String nodeId, String nodeName, String path, String parentId) throws Exception {
|
||||
private void otherLevelsData(String taskId, String nodeId, String nodeName, String path, String parentId,LoginUser loginuser) throws Exception {
|
||||
|
||||
//获取当前登录用户 上传人是当前登录人
|
||||
UsernamePasswordAuthenticationToken authentication =
|
||||
(UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
LoginUser loginuser = null;
|
||||
if (authentication != null) {
|
||||
loginuser = (LoginUser) authentication.getPrincipal();
|
||||
}
|
||||
//登录人
|
||||
String uploader = null;
|
||||
if (loginuser != null) {
|
||||
uploader = loginuser.getUsername();
|
||||
}
|
||||
// 存储所有目录和文件的列表
|
||||
List<TsFiles> tsFilesToCreate = new ArrayList<>();
|
||||
|
||||
@ -848,18 +836,24 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
//工作空间路径
|
||||
tsFiles1.setWorkPath(ensurePathFormat(finalPath));
|
||||
tsFiles1.setUploadTime(currentTime);
|
||||
tsFiles1.setUploader(uploader);
|
||||
tsFiles1.setUploader(loginuser.getUsername());
|
||||
long bytes = subDir.length();
|
||||
// 转换为 KB 并保留两位小数
|
||||
double fileSizeInKB = bytes / (1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInKB); // 保留两位小数
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
LOGGER.info("[构建文件表中的文件夹列表] 耗时 {} ms | 待处理数量: {} 条",
|
||||
@ -895,17 +889,22 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
//工作空间路径
|
||||
tsFiles1.setWorkPath(ensurePathFormat(finalPath));
|
||||
tsFiles1.setUploadTime(currentTime);
|
||||
tsFiles1.setUploader(uploader);
|
||||
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()));
|
||||
}
|
||||
}
|
||||
tsFiles1.setUploader(loginuser.getUsername());
|
||||
long bytes = file.length();
|
||||
// 转换为 KB 并保留两位小数
|
||||
double fileSizeInKB = bytes / (1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInKB); // 保留两位小数
|
||||
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);
|
||||
}
|
||||
LOGGER.info("[构建文件表中的文件列表] 耗时 {} ms | 待处理数量: {} 条",
|
||||
|
@ -13,9 +13,12 @@ import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.modules.experimentalData.domain.TsNodes;
|
||||
import com.yfd.platform.modules.specialDocument.domain.Nodes;
|
||||
import com.yfd.platform.modules.specialDocument.service.INodesService;
|
||||
import com.yfd.platform.system.domain.LoginUser;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@ -139,10 +142,12 @@ public class NodesController {
|
||||
} else if ("COMPLETED".equals(existingStatus)) {
|
||||
return ResponseResult.success("专项文档扫描任务已完成!");
|
||||
}
|
||||
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
LoginUser loginuser = (LoginUser) authentication.getPrincipal();
|
||||
// 原子性启动新任务
|
||||
if (taskStatusHolder.startTaskIfAbsent(asyncKey)) {
|
||||
// 直接异步执行并推送结果
|
||||
nodesService.specialScanByIdAsync(id);
|
||||
nodesService.specialScanByIdAsync(id,loginuser);
|
||||
return ResponseResult.success("专项文档扫描任务开始处理!");
|
||||
} else {
|
||||
return ResponseResult.success("专项文档扫描任务已由其他请求启动!");
|
||||
@ -237,10 +242,12 @@ public class NodesController {
|
||||
} else if ("COMPLETED".equals(existingStatus)) {
|
||||
return ResponseResult.success("专项文档上传任务已完成!");
|
||||
}
|
||||
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
LoginUser loginuser = (LoginUser) authentication.getPrincipal();
|
||||
// 原子性启动新任务
|
||||
if (taskStatusHolder.startTaskIfAbsent(asyncKey)) {
|
||||
// 直接异步执行并推送结果
|
||||
nodesService.documentUploadByIdAsync(id, fileName);
|
||||
nodesService.documentUploadByIdAsync(id, fileName, loginuser);
|
||||
return ResponseResult.success("专项文档上传任务开始处理!");
|
||||
} else {
|
||||
return ResponseResult.success("专项文档上传任务已由其他请求启动");
|
||||
|
@ -3,6 +3,7 @@ package com.yfd.platform.modules.specialDocument.service;
|
||||
import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.modules.specialDocument.domain.Nodes;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yfd.platform.system.domain.LoginUser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@ -55,12 +56,12 @@ public interface INodesService extends IService<Nodes> {
|
||||
* 参数说明 id 所属项目ID
|
||||
* 返回值说明: com.yfd.platform.config.ResponseResult 返回成功或者失败
|
||||
***********************************/
|
||||
void specialScanByIdAsync(String id) throws Exception;
|
||||
void specialScanByIdAsync(String id, LoginUser loginuser) throws Exception;
|
||||
|
||||
/**********************************
|
||||
* 用途说明: 专项文档管理文档上传接口
|
||||
* 参数说明 id 所属项目ID
|
||||
* 返回值说明: com.yfd.platform.config.ResponseResult 返回成功或者失败
|
||||
***********************************/
|
||||
void documentUploadByIdAsync(String id,String fileName) throws IOException;
|
||||
void documentUploadByIdAsync(String id,String fileName,LoginUser loginuser) throws IOException;
|
||||
}
|
||||
|
@ -415,9 +415,9 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
||||
//todo
|
||||
files1.setFilePath(targetFilePath);
|
||||
long fileSizeInBytes = fileItemResult.getSize();
|
||||
// 转换为 MB 并保留两位小数
|
||||
double fileSizeInMB = fileSizeInBytes / (1024.0 * 1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInMB); // 保留两位小数
|
||||
// 转换为 KB 并保留两位小数
|
||||
double fileSizeInKB = fileSizeInBytes / (1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInKB); // 保留两位小数
|
||||
files1.setFileSize(fileSizeFormatted);
|
||||
files1.setUploadTime(currentTime);
|
||||
filesList.add(files1);
|
||||
@ -441,9 +441,9 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
|
||||
//todo
|
||||
files1.setFilePath(targetFilePath);
|
||||
long fileSizeInBytes = fileItemResult.getSize();
|
||||
// 转换为 MB 并保留两位小数
|
||||
double fileSizeInMB = fileSizeInBytes / (1024.0 * 1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInMB); // 保留两位小数
|
||||
// 转换为 KB 并保留两位小数
|
||||
double fileSizeInKB = fileSizeInBytes / (1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInKB); // 保留两位小数
|
||||
files1.setFileSize(fileSizeFormatted);
|
||||
files1.setUploadTime(currentTime);
|
||||
filesList.add(files1);
|
||||
|
@ -538,6 +538,7 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
public boolean deleteNodesById(String id, String path) {
|
||||
Boolean value = false;
|
||||
|
||||
|
||||
// 根据ID 查询当前数据
|
||||
Nodes nodes = nodesMapper.selectById(id);
|
||||
|
||||
@ -561,7 +562,7 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
if (!nodeIds.isEmpty()) {
|
||||
QueryWrapper<Files> deleteWrapper = new QueryWrapper<>();
|
||||
deleteWrapper.in("node_id", nodeIds); // 根据节点 ID 批量删除
|
||||
deleteWrapper.eq("project_id",nodes.getProjectId());
|
||||
deleteWrapper.eq("project_id", nodes.getProjectId());
|
||||
filesMapper.delete(deleteWrapper);
|
||||
}
|
||||
|
||||
@ -615,7 +616,7 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
* projectId 项目ID
|
||||
*/
|
||||
private List<Nodes> selectChildrenNodes(String parentId, String projectId) {
|
||||
List<Nodes> nodesList = new ArrayList<>();
|
||||
List<Nodes> nodesList = new ArrayList<>();
|
||||
Nodes nodes = nodesMapper.selectById(parentId);
|
||||
// 查询当前节点的所有子节点
|
||||
QueryWrapper<Nodes> queryWrapper = new QueryWrapper<>();
|
||||
@ -670,16 +671,16 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
***********************************/
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public void specialScanByIdAsync(String id) throws Exception {
|
||||
public void specialScanByIdAsync(String id, LoginUser loginuser) throws Exception {
|
||||
try {
|
||||
// 执行扫描并且插入数据库
|
||||
this.specialScanById(id);
|
||||
this.specialScanById(id, loginuser);
|
||||
} finally {
|
||||
// 生成唯一Key
|
||||
String asyncKey = taskStatusHolder.specialGenerateKey(id);
|
||||
// 无论成功失败都标记完成
|
||||
taskStatusHolder.finishTask(asyncKey);
|
||||
WebSocketServer.sendMessageTo("专项文档扫描任务处理完成!", "projectId_"+id);
|
||||
WebSocketServer.sendMessageTo("专项文档扫描任务处理完成!", "projectId_" + id);
|
||||
|
||||
}
|
||||
}
|
||||
@ -690,7 +691,7 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
* 参数说明 id 所属项目ID
|
||||
* 返回值说明: com.yfd.platform.config.ResponseResult 返回成功或者失败
|
||||
***********************************/
|
||||
public String specialScanById(String id) throws Exception {
|
||||
public String specialScanById(String id, LoginUser loginuser) throws Exception {
|
||||
|
||||
//查询项目信息
|
||||
Project project = projectMapper.selectById(id);
|
||||
@ -704,18 +705,6 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
|
||||
//获取文件列表
|
||||
String absolutePath = "/" + project.getProjectName() + "/";
|
||||
//获取当前登录用户 上传人是当前登录人
|
||||
UsernamePasswordAuthenticationToken authentication =
|
||||
(UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
LoginUser loginuser = null;
|
||||
if (authentication != null) {
|
||||
loginuser = (LoginUser) authentication.getPrincipal();
|
||||
}
|
||||
//登录人
|
||||
String uploader = null;
|
||||
if (loginuser != null) {
|
||||
uploader = loginuser.getUsername();
|
||||
}
|
||||
// 设置当前时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 转换为 Timestamp
|
||||
@ -787,9 +776,9 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
long startTime = System.currentTimeMillis();
|
||||
// 执行修改操作
|
||||
int affectedLevelRows = nodesMapper.updateParentIdByPathHierarchy();
|
||||
// 记录结束时间
|
||||
// 记录结束时间
|
||||
long endTime = System.currentTimeMillis();
|
||||
// 计算耗时
|
||||
// 计算耗时
|
||||
long costTime = endTime - startTime;
|
||||
// 打印日志
|
||||
LOGGER.info("节点表中的parent_id更新完成,影响 {} 行,总耗时 {} 毫秒", affectedLevelRows, costTime);
|
||||
@ -814,9 +803,15 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
files.setNodeId("00");
|
||||
files.setFileName(file.getName());
|
||||
files.setFilePath(ensurePathFormat(finalPath));
|
||||
files.setFileSize(String.valueOf(file.length()));
|
||||
|
||||
long bytes = file.length();
|
||||
// 转换为 KB 并保留两位小数
|
||||
double fileSizeInKB = bytes / (1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInKB); // 保留两位小数
|
||||
files.setFileSize(fileSizeFormatted);
|
||||
|
||||
files.setUploadTime(currentTime);
|
||||
files.setUploader(uploader);
|
||||
files.setUploader(loginuser.getUsername());
|
||||
filesToCreate.add(files);
|
||||
}
|
||||
LOGGER.info("[构建文件列表] 耗时 {} ms | 待处理数量: {} 条",
|
||||
@ -834,9 +829,9 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
|
||||
// 记录开始时间
|
||||
long startTimeFiles = System.currentTimeMillis();
|
||||
// 执行更新操作
|
||||
// 执行更新操作
|
||||
int affectedLevelFilesRows = filesMapper.updateNodeIdByPathHierarchy(id);
|
||||
// 记录结束时间
|
||||
// 记录结束时间
|
||||
long endTimeFiles = System.currentTimeMillis();
|
||||
// 计算耗时
|
||||
long costTimeFiles = endTimeFiles - startTimeFiles;
|
||||
@ -928,30 +923,6 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
} else {
|
||||
//第一层属于节点,同级别的文件不做处理
|
||||
continue;
|
||||
// //获取节点名称
|
||||
// String nodeName = getLastPathSegment(item.getPath());
|
||||
// //获取节点信息 主要用到ID
|
||||
// QueryWrapper<Nodes> queryWrapper = new QueryWrapper<>();
|
||||
// queryWrapper.eq("node_name", nodeName);
|
||||
// queryWrapper.eq("parent_id", TOP_LEVEL_PARENT_NODE);
|
||||
// Nodes node = nodesMapper.selectOne(queryWrapper);
|
||||
//
|
||||
// //新增之前先查询
|
||||
// LambdaQueryWrapper<Files> queryWrapper1 = new LambdaQueryWrapper<>();
|
||||
// queryWrapper1.eq(Files::getProjectId, projectId);
|
||||
// queryWrapper1.eq(Files::getNodeId, node.getId());
|
||||
// queryWrapper1.eq(Files::getFilePath, item.getPath());
|
||||
// queryWrapper1.eq(Files::getFileName, item.getName());
|
||||
// Files files = filesMapper.selectOne(queryWrapper1);
|
||||
// if (files == null) {
|
||||
// // 获取文件大小(字节)
|
||||
// long fileSizeInBytes = item.getSize();
|
||||
// // 转换为 MB 并保留两位小数
|
||||
// double fileSizeInMB = fileSizeInBytes / (1024.0 * 1024.0);
|
||||
// String fileSizeFormatted = String.format("%.2f", fileSizeInMB); // 保留两位小数
|
||||
// //保存文件信息
|
||||
// saveFiles(projectId, node.getId(), item.getPath(), item.getName(), fileSizeFormatted);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1014,9 +985,9 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
if (files == null) {
|
||||
// 获取文件大小(字节)
|
||||
long fileSizeInBytes = item.getSize();
|
||||
// 转换为 MB 并保留两位小数
|
||||
double fileSizeInMB = fileSizeInBytes / (1024.0 * 1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInMB); // 保留两位小数
|
||||
// 转换为 KB 并保留两位小数
|
||||
double fileSizeInKB = fileSizeInBytes / (1024.0);
|
||||
String fileSizeFormatted = String.format("%.2f", fileSizeInKB); // 保留两位小数
|
||||
//保存文件
|
||||
saveFiles(projectId, parentId, item.getPath(), item.getName(), fileSizeFormatted);
|
||||
}
|
||||
@ -1138,7 +1109,7 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public void documentUploadByIdAsync(String id, String fileName) throws IOException {
|
||||
public void documentUploadByIdAsync(String id, String fileName, LoginUser loginuser) throws IOException {
|
||||
try {
|
||||
|
||||
// 查询本地文件路径根目录(如 E:\yun)
|
||||
@ -1179,7 +1150,7 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
// 执行上传并且插入数据库
|
||||
this.documentUploadById(id, sourceFolderPath, targetFolderPath, storageSourceConfig.getValue());
|
||||
//开始执行更新表数据 名称是去掉后缀以后的
|
||||
uploadProject(zipName);
|
||||
uploadProject(zipName, loginuser);
|
||||
LOGGER.info("开始更新表数据:{}", zipName);
|
||||
|
||||
//获取文件路径
|
||||
@ -1199,7 +1170,7 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
String asyncKey = taskStatusHolder.documentUploadKey(id);
|
||||
// 无论成功失败都标记完成
|
||||
taskStatusHolder.finishTask(asyncKey);
|
||||
WebSocketServer.sendMessageTo("专项文档上传任务处理完成!", "projectId_"+id);
|
||||
WebSocketServer.sendMessageTo("专项文档上传任务处理完成!", "projectId_" + id);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1340,7 +1311,7 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
}
|
||||
|
||||
|
||||
public String uploadProject(String projectName) throws Exception {
|
||||
public String uploadProject(String projectName, LoginUser loginuser) throws Exception {
|
||||
|
||||
//查询项目信息
|
||||
LambdaQueryWrapper<Project> projectLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
@ -1371,7 +1342,7 @@ public class NodesServiceImpl extends ServiceImpl<NodesMapper, Nodes> implements
|
||||
boolean flag = fileService.newFolder(newFolderRequest.getPath(), newFolderRequest.getName());
|
||||
}
|
||||
}
|
||||
specialScanById(project.getId());
|
||||
specialScanById(project.getId(), loginuser);
|
||||
|
||||
return "扫描完成";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user