refactor(接口测试): 优化本地附件csv的清理逻辑

This commit is contained in:
wxg0103 2023-07-12 14:18:59 +08:00 committed by fit2-zhao
parent 656cde481c
commit 3002749f2d
1 changed files with 17 additions and 4 deletions

View File

@ -488,10 +488,23 @@ public class ApiScenarioService {
.filter(ScenarioVariable::isEnable).collect(toList());
if (CollectionUtils.isNotEmpty(oldVariables) && CollectionUtils.isNotEmpty(newVariables)) {
List<String> ids = newVariables.get(0).getFiles().stream().map(BodyFile::getId).collect(toList());
oldVariables.get(0).getFiles().forEach(item -> {
if (!ids.contains(item.getId())) {
ApiFileUtil.deleteBodyFiles(item.getId() + "_" + item.getName());
List<String> ids = newVariables.stream()
.flatMap(nv -> Optional.ofNullable(nv.getFiles()).orElse(List.of()).stream())
.map(BodyFile::getId)
.toList();
oldVariables.forEach(item ->{
if (CollectionUtils.isNotEmpty(item.getFiles()) &&
StringUtils.isNotBlank(item.getFiles().get(0).getId()) &&
!ids.contains(item.getFiles().get(0).getId())) {
ApiFileUtil.deleteBodyFiles(item.getFiles().get(0).getId() + "_" + item.getFiles().get(0).getName());
}
});
}
if (CollectionUtils.isEmpty(newVariables) && CollectionUtils.isNotEmpty(oldVariables)) {
oldVariables.forEach(item ->{
if (CollectionUtils.isNotEmpty(item.getFiles()) &&
StringUtils.isNotBlank(item.getFiles().get(0).getId())) {
ApiFileUtil.deleteBodyFiles(item.getFiles().get(0).getId() + "_" + item.getFiles().get(0).getName());
}
});
}