From fd6819efd81762051ebe13628f86217f11403d80 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Wed, 26 Jan 2022 18:49:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=9B=9E=E6=94=B6=E7=AB=99=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=97=B6=E5=88=A0=E9=99=A4=E6=89=80=E6=9C=89=E7=9A=84=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/ApiAutomationService.java | 21 +++++++++++++++---- .../api/service/ApiDefinitionService.java | 21 +++++++++++++++++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 1c51b15abd..9c5eb66feb 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import io.metersphere.api.dto.*; import io.metersphere.api.dto.automation.*; -import io.metersphere.api.dto.automation.parse.ApiScenarioImportUtil; import io.metersphere.api.dto.automation.parse.ScenarioImport; import io.metersphere.api.dto.automation.parse.ScenarioImportParserFactory; import io.metersphere.api.dto.datacount.ApiDataCountResult; @@ -1363,11 +1362,11 @@ public class ApiAutomationService { request.setDefaultVersion(defaultVersion); for (int i = 0; i < data.size(); i++) { ApiScenarioWithBLOBs item = data.get(i); - if(StringUtils.isBlank(item.getApiScenarioModuleId())|| "default-module".equals(item.getApiScenarioModuleId())){ + if (StringUtils.isBlank(item.getApiScenarioModuleId()) || "default-module".equals(item.getApiScenarioModuleId())) { replenishScenarioModuleIdPath(request.getProjectId(), apiScenarioModuleMapper, item); } - if(StringUtils.isBlank(item.getCreateUser())){ + if (StringUtils.isBlank(item.getCreateUser())) { item.setCreateUser(SessionUtils.getUserId()); } if (item.getName().length() > 255) { @@ -1617,7 +1616,21 @@ public class ApiAutomationService { public void deleteBatchByCondition(ApiScenarioBatchRequest request) { ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extApiScenarioMapper.selectIdsByQuery(query)); - this.deleteBatch(request.getIds()); + List ids = request.getIds(); + if (CollectionUtils.isEmpty(ids)) { + return; + } + ids.forEach(id -> { + ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(id); + if (scenario == null) { + return; + } + ApiScenarioExample example = new ApiScenarioExample(); + example.createCriteria().andRefIdEqualTo(scenario.getRefId()); + List apiScenarios = apiScenarioMapper.selectByExample(example); + List apiIds = apiScenarios.stream().map(ApiScenario::getId).collect(Collectors.toList()); + this.deleteBatch(apiIds); + }); } /** diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index 063b6c531e..7e75e8c086 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -1320,8 +1320,25 @@ public class ApiDefinitionService { } public void deleteByParams(ApiBatchRequest request) { - apiDefinitionMapper.deleteByExample(getBatchExample(request)); - apiTestCaseService.deleteBatchByDefinitionId(request.getIds()); + List ids = request.getIds(); + if (CollectionUtils.isEmpty(ids)) { + return; + } + ids.forEach(id -> { + // 把所有版本的api移到回收站 + ApiDefinitionWithBLOBs api = apiDefinitionMapper.selectByPrimaryKey(id); + if (api == null) { + return; + } + ApiDefinitionExample example = new ApiDefinitionExample(); + example.createCriteria().andRefIdEqualTo(api.getRefId()); + List apiDefinitions = apiDefinitionMapper.selectByExample(example); + + List apiIds = apiDefinitions.stream().map(ApiDefinition::getId).collect(Collectors.toList()); + apiTestCaseService.deleteBatchByDefinitionId(apiIds); + // + apiDefinitionMapper.deleteByExample(example); + }); } public ApiDefinitionExample getBatchExample(ApiBatchRequest request) {