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