生成报告脚本

This commit is contained in:
2025-12-08 16:07:57 +08:00
parent 190fa4160e
commit 6c4b082d3e
10 changed files with 220 additions and 125 deletions

View File

@@ -440,6 +440,13 @@ public class DataFileController implements IDataFeignClient {
IDataFileService.downloadFileToLocal(fileId,path);
}
@PostMapping("/downloadFolderToLocal")
public SdmResponse downloadFolderToLocal(@RequestParam(value = "downloadDirId") @Validated Long downloadDirId,
@RequestParam(value = "basePath") @Validated String basePath,
@RequestParam(value = "fileRegularStr", required = false) String fileRegularStr) throws Exception {
return IDataFileService.downloadFolderToLocal(downloadDirId, basePath, fileRegularStr);
}
/**
* 导出知识库
* @param knowledgeExportExcelFormat

View File

@@ -337,8 +337,9 @@ public interface IDataFileService {
* 批量下载指定文件夹到本地目录
* @param downloadDirId
* @param basePath
* @param fileRegularStr 用于过滤文件的正则表达式
*/
default void downloadFolderToLocal(Long downloadDirId, String basePath) throws Exception {}
default SdmResponse downloadFolderToLocal(Long downloadDirId, String basePath, String fileRegularStr) throws Exception {return null;}
/**
* 导出知识库

View File

@@ -76,6 +76,7 @@ import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -2523,7 +2524,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
}
}
public void downloadFolderToLocal(Long downloadDirId, String basePath) throws Exception {
public SdmResponse downloadFolderToLocal(Long downloadDirId, String basePath, String fileRegularStr) throws Exception {
if (downloadDirId == null || basePath == null) {
throw new IllegalArgumentException("downloadDirId 和 basePath 不能为空");
}
@@ -2565,11 +2566,19 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
throw new RuntimeException("无法创建本地目录: " + fullLocalBase, e);
}
// 3. 列出 MinIO 中该前缀下的所有对象(递归)
Iterable<Result<Item>> results = minioService.listObjects(folderObjectKey);
// 编译正则表达式(如果提供)
Pattern pattern = null;
if (fileRegularStr != null && !fileRegularStr.isEmpty()) {
try {
pattern = Pattern.compile(fileRegularStr);
} catch (Exception e) {
throw new RuntimeException("无效的正则表达式: " + fileRegularStr, e);
}
}
// 4. 遍历并下载每个对象(任一失败立即抛出 RuntimeException
for (Result<Item> result : results) {
Item item = result.get();
@@ -2580,6 +2589,15 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
continue;
}
// 如果提供了正则表达式,则进行过滤
if (pattern != null) {
String fileName = Paths.get(objectKey).getFileName().toString();
if (!pattern.matcher(fileName).matches()) {
// 不匹配正则表达式的文件跳过下载
continue;
}
}
// 构建本地文件路径basePath + objectKey
Path localFilePath = localBaseDir.resolve(objectKey).normalize();
@@ -2606,6 +2624,8 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
throw new RuntimeException("下载对象失败: " + objectKey, e);
}
}
return SdmResponse.success();
}
@Override