perf: scc流程生成性能优化

This commit is contained in:
2024-08-19 11:22:06 +08:00
parent d793b42eff
commit 42262e5651
2 changed files with 25 additions and 17 deletions
@@ -487,29 +487,41 @@ public class ProcessStandardComplianceCheckServiceImpl extends ServiceImpl<Proce
@Override
public List<ProcessStandardComplianceCheckDetail> generate(ProcessStandardComplianceCheck scc) throws Exception {
String splitFileSource = scc.getSplitFileSource();
// 异步获取文件
CompletableFuture<MultipartFile> splitFileFuture = CompletableFuture.supplyAsync(() -> {
if (StrUtil.isBlank(scc.getSplitFileSource())) {
return this.getFileById(scc.getSplitFile());
}
return null;
});
CompletableFuture<MultipartFile> modelFileFuture = CompletableFuture.supplyAsync(() ->
this.getFileById(scc.getModelFile())
);
// 获取拆分数据
List<ProcessStandardComplianceCheckDetail> detailInfoList;
// 找到拆分数据
if (StrUtil.isBlank(splitFileSource)) {
MultipartFile splitFile = this.getFileById(scc.getSplitFile());
if (StrUtil.isBlank(scc.getSplitFileSource())) {
MultipartFile splitFile = splitFileFuture.get(); // 等待获取的文件完成
detailInfoList = this.getSplitData(scc, splitFile);
} else {
detailInfoList = this.getSplitDataByStandard(scc);
// 是否与上一般一致
// 是否与上一版一致
String isSameLastVersion = scc.getIsSameLastVersion();
if (YesOrNoEnum.NO.getValue().equals(isSameLastVersion)) {
// 过滤出也为否的数据
// 过滤出也为否的数据
detailInfoList = detailInfoList.stream()
.parallel() // 使用并行流
.parallel() // 使用并行流
.filter(detail -> YesOrNoEnum.NO.getValue().equals(detail.getIsSameAsPrevVersion()))
.collect(Collectors.toList());
}
}
// 获取两个文件
MultipartFile modelFile = this.getFileById(scc.getModelFile());
// 文件内容转换
// 等待模型文件获取完成并进行文件内容转换
MultipartFile modelFile = modelFileFuture.get(); // 等待获取的文件完成
List<ModelExcelVO> modelExcelVOList = this.getModelExcelData(modelFile);
// 根据主表数据和车型文件生成子表数据并保存
return this.saveAllDetailData(modelExcelVOList, detailInfoList);
}
@@ -1061,11 +1073,7 @@ public class ProcessStandardComplianceCheckServiceImpl extends ServiceImpl<Proce
}
private MultipartFile getFileById(String fileId) {
List<OSSFile> fileInfos = ossFileService.getFileInfos(fileId);
if (fileInfos == null || fileInfos.isEmpty()) {
return null;
}
OSSFile fileInfo = fileInfos.get(0);
OSSFile fileInfo = ossFileService.getById(fileId);
String fileName = fileInfo.getFileName();
String url = fileInfo.getUrl();
try (InputStream originalInputStream = ObsBootUtil.getOssFile(url)) {
@@ -29,8 +29,8 @@ public class BeanCopyUtils {
}
public static <O,V> List<V> copyBeanList(List<O> list, Class<V> clazz) {
return list.stream()
return list.parallelStream() // 使用并行流
.map(o -> copyBean(o, clazz))
.collect(Collectors.toList());
.collect(Collectors.toList()); // 保持原有顺序
}
}