提交代码修改重命名
This commit is contained in:
parent
4a6346d683
commit
1037136405
@ -629,18 +629,60 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
if (flag) {
|
if (flag) {
|
||||||
//递归下面所有的文件文件夹 路径都需要修改
|
//递归下面所有的文件文件夹 路径都需要修改
|
||||||
List<TsFiles> resultList = new ArrayList<>();
|
List<TsFiles> resultList = new ArrayList<>();
|
||||||
// 获取当前文件夹的完整路径(如 "/147/222/")
|
|
||||||
String oldFullPath = filesData.getWorkPath() + filesData.getFileName() + "/";
|
if (tsFiles.getBackupPath() != null && tsFiles.getBackupPath() != "") {
|
||||||
String newFullPath = filesData.getWorkPath() + tsFiles.getFileName() + "/";
|
// 设置当前时间
|
||||||
querySubFilesAndUpdatePaths(resultList, tsFiles.getId(), oldFullPath, newFullPath);
|
LocalDateTime now = LocalDateTime.now();
|
||||||
// 修改数据库
|
// 转换为 Timestamp
|
||||||
int valueUpdate = tsFilesMapper.updateById(tsFiles);
|
Timestamp currentTime = Timestamp.valueOf(now);
|
||||||
if (valueUpdate == 1) {
|
//新通过id找到表中现有的 修改也是修改表中现有的数据 新增的一条就是重命名以后的 所有备份空间路径为空 原来的哪条数据把工作空间路径改成空
|
||||||
LOGGER.info("local和minio修改成功,表结构修改成功");
|
TsFiles tsFiles2 = tsFilesMapper.selectById(tsFiles.getId());//查询原来的数据 把原来的数据
|
||||||
return ResponseResult.success();
|
tsFiles2.setWorkPath("");
|
||||||
|
|
||||||
|
TsFiles tsFiles1 = new TsFiles();
|
||||||
|
tsFiles1.setNodeId(tsFiles.getNodeId());
|
||||||
|
tsFiles1.setTaskId(tsFiles.getTaskId());
|
||||||
|
tsFiles1.setIsFile(tsFiles.getIsFile());
|
||||||
|
tsFiles1.setParentId(tsFiles.getParentId());
|
||||||
|
tsFiles1.setFileName(tsFiles.getFileName());
|
||||||
|
tsFiles1.setFileSize(tsFiles.getFileSize());
|
||||||
|
tsFiles1.setWorkPath(tsFiles.getWorkPath());
|
||||||
|
tsFiles1.setBackupPath("");
|
||||||
|
tsFiles1.setKeywords(tsFiles.getKeywords());
|
||||||
|
tsFiles1.setDescription(tsFiles.getDescription());
|
||||||
|
tsFiles1.setUploadTime(currentTime);
|
||||||
|
tsFiles1.setUploader(tsFiles.getUploader());
|
||||||
|
tsFiles1.setUpdateTime(currentTime);
|
||||||
|
int valueInsert = tsFilesMapper.insert(tsFiles1);
|
||||||
|
if (valueInsert == 1) {
|
||||||
|
int valueUpdate = tsFilesMapper.updateById(tsFiles2);
|
||||||
|
// 获取当前文件夹的完整路径(如 "/147/222/")
|
||||||
|
String oldFullPath = filesData.getWorkPath() + filesData.getFileName() + "/";
|
||||||
|
String newFullPath = filesData.getWorkPath() + tsFiles.getFileName() + "/";
|
||||||
|
querySubFilesAndUpdatePaths(resultList, tsFiles2.getId(), oldFullPath, newFullPath, tsFiles1.getId());
|
||||||
|
if (valueUpdate == 1) {
|
||||||
|
LOGGER.info("local和minio修改成功,表结构修改成功");
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
LOGGER.error("local和minio修改成功,表结构修改失败");
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGGER.error("local和minio修改成功,表结构修改失败");
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("local和minio修改成功,表结构修改失败");
|
// 如果备份空间为空 直接修改数据库
|
||||||
return ResponseResult.error();
|
int valueUpdate = tsFilesMapper.updateById(tsFiles);
|
||||||
|
if (valueUpdate == 1) {
|
||||||
|
LOGGER.info("local和minio修改成功,表结构修改成功");
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
LOGGER.error("local和minio修改成功,表结构修改失败");
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("local和minio修改失败");
|
LOGGER.error("local和minio修改失败");
|
||||||
@ -668,17 +710,61 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
renameFileRequest.setStorageKey("local");
|
renameFileRequest.setStorageKey("local");
|
||||||
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey(renameFileRequest.getStorageKey());
|
AbstractBaseFileService<?> fileService = storageSourceContext.getByStorageKey(renameFileRequest.getStorageKey());
|
||||||
Boolean flag = fileService.renameFile(renameFileRequest.getPath(), renameFileRequest.getName(), renameFileRequest.getNewName());
|
Boolean flag = fileService.renameFile(renameFileRequest.getPath(), renameFileRequest.getName(), renameFileRequest.getNewName());
|
||||||
//如果是true 说明至少有一个修改了文件夹
|
//如果是true 说明至少有一个修改了文件
|
||||||
if (flag) {
|
if (flag) {
|
||||||
// 修改数据库
|
//如果备份路径不为空 那么就先增加一条 然后修改本地的
|
||||||
int valueUpdate = tsFilesMapper.updateById(tsFiles);
|
if (tsFiles.getBackupPath() != null && tsFiles.getBackupPath() != "") {
|
||||||
if (valueUpdate == 1) {
|
// 设置当前时间
|
||||||
LOGGER.info("local和minio修改成功,表结构修改成功");
|
LocalDateTime now = LocalDateTime.now();
|
||||||
return ResponseResult.success();
|
// 转换为 Timestamp
|
||||||
|
Timestamp currentTime = Timestamp.valueOf(now);
|
||||||
|
//新通过id找到表中现有的 修改也是修改表中现有的数据 新增的一条就是重命名以后的 所有备份空间路径为空 原来的哪条数据把工作空间路径改成空
|
||||||
|
TsFiles tsFiles2 = tsFilesMapper.selectById(tsFiles.getId());//查询原来的数据 把原来的数据
|
||||||
|
tsFiles2.setWorkPath("");
|
||||||
|
|
||||||
|
TsFiles tsFiles1 = new TsFiles();
|
||||||
|
tsFiles1.setNodeId(tsFiles.getNodeId());
|
||||||
|
tsFiles1.setTaskId(tsFiles.getTaskId());
|
||||||
|
tsFiles1.setIsFile(tsFiles.getIsFile());
|
||||||
|
tsFiles1.setParentId(tsFiles.getParentId());
|
||||||
|
tsFiles1.setFileName(tsFiles.getFileName());
|
||||||
|
tsFiles1.setFileSize(tsFiles.getFileSize());
|
||||||
|
tsFiles1.setWorkPath(tsFiles.getWorkPath());
|
||||||
|
tsFiles1.setBackupPath("");
|
||||||
|
tsFiles1.setKeywords(tsFiles.getKeywords());
|
||||||
|
tsFiles1.setDescription(tsFiles.getDescription());
|
||||||
|
tsFiles1.setUploadTime(currentTime);
|
||||||
|
tsFiles1.setUploader(tsFiles.getUploader());
|
||||||
|
tsFiles1.setUpdateTime(currentTime);
|
||||||
|
int valueInsert = tsFilesMapper.insert(tsFiles1);
|
||||||
|
if (valueInsert == 1) {
|
||||||
|
int valueUpdate = tsFilesMapper.updateById(tsFiles2);
|
||||||
|
if (valueUpdate == 1) {
|
||||||
|
LOGGER.info("local和minio修改成功,表结构修改成功");
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
LOGGER.error("local和minio修改成功,表结构修改失败");
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGGER.error("local和minio修改成功,表结构修改失败");
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("local和minio修改成功,表结构修改失败");
|
// 如果备份空间为空 直接修改数据库
|
||||||
return ResponseResult.error();
|
int valueUpdate = tsFilesMapper.updateById(tsFiles);
|
||||||
|
if (valueUpdate == 1) {
|
||||||
|
LOGGER.info("local和minio修改成功,表结构修改成功");
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
LOGGER.error("local和minio修改成功,表结构修改失败");
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("local和minio修改失败");
|
LOGGER.error("local和minio修改失败");
|
||||||
return ResponseResult.error();
|
return ResponseResult.error();
|
||||||
@ -695,8 +781,8 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
private void querySubFilesAndUpdatePaths(List<TsFiles> resultList, String id, String oldName, String newName) {
|
private void querySubFilesAndUpdatePaths(List<TsFiles> resultList, String id, String oldName, String newName, String newid) {
|
||||||
// 构造 QueryWrapper 查询当前文件夹下的文件
|
// 构造 QueryWrapper 查询当前文件夹下的文件
|
||||||
QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<TsFiles> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("parent_id", id);
|
queryWrapper.eq("parent_id", id);
|
||||||
@ -712,16 +798,51 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
|
|
||||||
// 遍历每个子项,更新路径并递归查询其子项
|
// 遍历每个子项,更新路径并递归查询其子项
|
||||||
for (TsFiles subFile : subFiles) {
|
for (TsFiles subFile : subFiles) {
|
||||||
|
|
||||||
String oldWorkPath = subFile.getWorkPath();
|
String oldWorkPath = subFile.getWorkPath();
|
||||||
// 使用正则表达式替换目标文件夹名称
|
// 使用正则表达式替换目标文件夹名称
|
||||||
String newWorkPath = oldWorkPath.replaceAll(oldName, newName);
|
String newWorkPath = oldWorkPath.replaceAll(oldName, newName);
|
||||||
// 更新数据库中的路径
|
|
||||||
subFile.setWorkPath(newWorkPath);
|
//判断备份空间路径是否为空 如果不为
|
||||||
tsFilesMapper.updateById(subFile);
|
if (subFile.getBackupPath() != null && subFile.getBackupPath() != "") {
|
||||||
// 递归查询每个子项的子文件
|
// 设置当前时间
|
||||||
if ("FOLDER".equals(subFile.getIsFile())) {
|
LocalDateTime now = LocalDateTime.now();
|
||||||
querySubFilesAndUpdatePaths(resultList, subFile.getId(), oldName, newName);
|
// 转换为 Timestamp
|
||||||
|
Timestamp currentTime = Timestamp.valueOf(now);
|
||||||
|
//新通过id找到表中现有的 修改也是修改表中现有的数据 新增的一条就是重命名以后的 所有备份空间路径为空 原来的哪条数据把工作空间路径改成空
|
||||||
|
TsFiles tsFiles2 = tsFilesMapper.selectById(subFile.getId());//查询原来的数据 把原来的数据
|
||||||
|
tsFiles2.setWorkPath("");
|
||||||
|
|
||||||
|
TsFiles tsFiles1 = new TsFiles();
|
||||||
|
tsFiles1.setNodeId(subFile.getNodeId());
|
||||||
|
tsFiles1.setTaskId(subFile.getTaskId());
|
||||||
|
tsFiles1.setIsFile(subFile.getIsFile());
|
||||||
|
tsFiles1.setParentId(newid);
|
||||||
|
tsFiles1.setFileName(subFile.getFileName());
|
||||||
|
tsFiles1.setFileSize(subFile.getFileSize());
|
||||||
|
tsFiles1.setWorkPath(newWorkPath);
|
||||||
|
tsFiles1.setBackupPath("");
|
||||||
|
tsFiles1.setKeywords(subFile.getKeywords());
|
||||||
|
tsFiles1.setDescription(subFile.getDescription());
|
||||||
|
tsFiles1.setUploadTime(currentTime);
|
||||||
|
tsFiles1.setUploader(subFile.getUploader());
|
||||||
|
tsFiles1.setUpdateTime(currentTime);
|
||||||
|
int valueInsert = tsFilesMapper.insert(tsFiles1);
|
||||||
|
if (valueInsert == 1) {
|
||||||
|
int valueUpdate = tsFilesMapper.updateById(tsFiles2);
|
||||||
|
if (valueUpdate == 1) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// 更新数据库中的路径
|
||||||
|
subFile.setWorkPath(newWorkPath);
|
||||||
|
subFile.setParentId(newid);
|
||||||
|
tsFilesMapper.updateById(subFile);
|
||||||
|
// 递归查询每个子项的子文件
|
||||||
|
if ("FOLDER".equals(subFile.getIsFile())) {
|
||||||
|
querySubFilesAndUpdatePaths(resultList, subFile.getId(), oldName, newName, subFile.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3649,7 +3770,6 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
private TreeDTO buildTree(TsFiles current, Map<String, List<TsFiles>> parentChildrenMap, boolean isLocal) {
|
private TreeDTO buildTree(TsFiles current, Map<String, List<TsFiles>> parentChildrenMap, boolean isLocal) {
|
||||||
// 1. 转换为DTO并检查路径有效性
|
// 1. 转换为DTO并检查路径有效性
|
||||||
TreeDTO dto = convertToDTO(current, isLocal);
|
TreeDTO dto = convertToDTO(current, isLocal);
|
||||||
String path = isLocal ? current.getWorkPath() : current.getBackupPath();
|
|
||||||
if (dto.getPath() == null || dto.getPath().trim().isEmpty()) {
|
if (dto.getPath() == null || dto.getPath().trim().isEmpty()) {
|
||||||
LOGGER.warn("由于路径为空,跳过节点{}", current.getId());
|
LOGGER.warn("由于路径为空,跳过节点{}", current.getId());
|
||||||
return null;
|
return null;
|
||||||
|
@ -178,7 +178,13 @@ public abstract class AbstractS3BaseFileService<P extends S3BaseParam> extends A
|
|||||||
String targetPath = buildTargetPath(path, name, isFolder);
|
String targetPath = buildTargetPath(path, name, isFolder);
|
||||||
|
|
||||||
if (isFolder) {
|
if (isFolder) {
|
||||||
// 处理文件夹
|
// 处理文件夹时,先添加文件夹自身
|
||||||
|
FileItemResult folderItem = createFolderItemSelf(targetPath);
|
||||||
|
if (folderItem != null) {
|
||||||
|
fileItemList.add(folderItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 列出文件夹内容(包含子目录)
|
||||||
String fullPrefix = StringUtils.trimStartSlashes(
|
String fullPrefix = StringUtils.trimStartSlashes(
|
||||||
StringUtils.concat(param.getBasePath(), targetPath)
|
StringUtils.concat(param.getBasePath(), targetPath)
|
||||||
);
|
);
|
||||||
@ -227,7 +233,7 @@ public abstract class AbstractS3BaseFileService<P extends S3BaseParam> extends A
|
|||||||
item.setSize(objectSummary.getSize());
|
item.setSize(objectSummary.getSize());
|
||||||
item.setTime(objectSummary.getLastModified());
|
item.setTime(objectSummary.getLastModified());
|
||||||
item.setType(FileTypeEnum.FILE);
|
item.setType(FileTypeEnum.FILE);
|
||||||
item.setPath(extractParentPath(targetPath));
|
item.setPath(extractParentPatha(targetPath));
|
||||||
item.setUrl(getDownloadUrl(targetPath));
|
item.setUrl(getDownloadUrl(targetPath));
|
||||||
return item;
|
return item;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -237,7 +243,43 @@ public abstract class AbstractS3BaseFileService<P extends S3BaseParam> extends A
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列出文件夹内容(包括子目录)
|
* 创建目标文件夹自身的条目
|
||||||
|
*/
|
||||||
|
private FileItemResult createFolderItemSelf(String targetPath) {
|
||||||
|
if (targetPath.equals("/") || targetPath.isEmpty()) {
|
||||||
|
return null; // 根目录不单独添加
|
||||||
|
}
|
||||||
|
|
||||||
|
String parentPath = extractParentPatha(targetPath);
|
||||||
|
String folderName = extractFolderName(targetPath);
|
||||||
|
|
||||||
|
FileItemResult item = new FileItemResult();
|
||||||
|
item.setName(folderName);
|
||||||
|
item.setType(FileTypeEnum.FOLDER);
|
||||||
|
item.setPath(parentPath);
|
||||||
|
item.setTime(new Date()); // S3 无文件夹实体,时间设为当前时间或留空
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从路径中提取父路径(如 /1/2/3/ → /1/2/)
|
||||||
|
*/
|
||||||
|
private String extractParentPatha(String path) {
|
||||||
|
path = StringUtils.trimEndSlashes(path);
|
||||||
|
int lastSlashIndex = path.lastIndexOf('/');
|
||||||
|
return (lastSlashIndex > 0) ? path.substring(0, lastSlashIndex + 1) : "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从路径中提取文件夹名称(如 /1/2/3/ → 3)
|
||||||
|
*/
|
||||||
|
private String extractFolderName(String path) {
|
||||||
|
path = StringUtils.trimEndSlashes(path);
|
||||||
|
int lastSlashIndex = path.lastIndexOf('/');
|
||||||
|
return (lastSlashIndex > 0) ? path.substring(lastSlashIndex + 1) : path;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 列出文件夹内容(包括子目录,递归时不重复添加自身)
|
||||||
*/
|
*/
|
||||||
private void listFolderContents(
|
private void listFolderContents(
|
||||||
String bucketName,
|
String bucketName,
|
||||||
@ -263,14 +305,14 @@ public abstract class AbstractS3BaseFileService<P extends S3BaseParam> extends A
|
|||||||
results.add(createFileItem(fileName, s, currentPath));
|
results.add(createFileItem(fileName, s, currentPath));
|
||||||
});
|
});
|
||||||
|
|
||||||
// 处理子文件夹
|
// 处理子文件夹(通过递归添加)
|
||||||
listing.getCommonPrefixes().forEach(commonPrefix -> {
|
listing.getCommonPrefixes().forEach(commonPrefix -> {
|
||||||
String folderName = commonPrefix.substring(prefix.length(), commonPrefix.length()-1);
|
String subFolderPrefix = commonPrefix;
|
||||||
String folderPath = currentPath;
|
String folderName = subFolderPrefix.substring(prefix.length(), subFolderPrefix.length() - 1);
|
||||||
results.add(createFolderItem(folderName, folderPath));
|
String subCurrentPath = currentPath + folderName + "/";
|
||||||
String folderPath1 = currentPath + folderName + "/";
|
|
||||||
// 递归列出子目录内容
|
// 递归调用以处理子目录(子目录的自身条目会在递归时添加)
|
||||||
listFolderContents(bucketName, commonPrefix, folderPath1, results);
|
listFolderContents(bucketName, subFolderPrefix, subCurrentPath, results);
|
||||||
});
|
});
|
||||||
|
|
||||||
request.setMarker(listing.getNextMarker());
|
request.setMarker(listing.getNextMarker());
|
||||||
|
@ -219,6 +219,11 @@ public class LocalServiceImpl extends AbstractProxyTransferService<LocalParam> {
|
|||||||
|
|
||||||
// 2. 直接处理文件或目录
|
// 2. 直接处理文件或目录
|
||||||
if (target.isDirectory()) {
|
if (target.isDirectory()) {
|
||||||
|
// 添加目标文件夹自身
|
||||||
|
FileItemResult folderItem = convertToFileItem(target, folderPath);
|
||||||
|
resultList.add(folderItem);
|
||||||
|
|
||||||
|
// 递归列出目录内容
|
||||||
listFilesInDirectory(target, targetPath, resultList);
|
listFilesInDirectory(target, targetPath, resultList);
|
||||||
} else {
|
} else {
|
||||||
// 如果是文件,直接添加到结果列表
|
// 如果是文件,直接添加到结果列表
|
||||||
@ -313,10 +318,16 @@ public class LocalServiceImpl extends AbstractProxyTransferService<LocalParam> {
|
|||||||
private FileItemResult convertToFileItem(File file, String parentPath) {
|
private FileItemResult convertToFileItem(File file, String parentPath) {
|
||||||
FileItemResult item = new FileItemResult();
|
FileItemResult item = new FileItemResult();
|
||||||
item.setName(file.getName());
|
item.setName(file.getName());
|
||||||
item.setPath(formatSinglePath(parentPath)); // 关键修改点
|
item.setPath(parentPath);
|
||||||
item.setType(file.isDirectory() ? FileTypeEnum.FOLDER : FileTypeEnum.FILE);
|
|
||||||
item.setSize(file.isDirectory() ? 0 : file.length());
|
item.setSize(file.isDirectory() ? 0 : file.length());
|
||||||
item.setTime(new Date(file.lastModified()));
|
item.setTime(new Date(file.lastModified()));
|
||||||
|
item.setType(file.isDirectory() ? FileTypeEnum.FOLDER : FileTypeEnum.FILE);
|
||||||
|
|
||||||
|
// 如果是文件,设置下载 URL
|
||||||
|
if (file.isFile()) {
|
||||||
|
item.setUrl(getDownloadUrl(parentPath + file.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user