From b31a208690a7bb1e3780643df2b4da2d358f80c0 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Thu, 14 Jul 2022 15:16:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E5=AF=BC=E5=85=A5refid=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 --- .../api/service/ApiAutomationService.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 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 5b16069e98..2c4316b3b7 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -599,9 +599,14 @@ public class ApiAutomationService { if (scenario == null) { return; } - ApiScenarioRequest request = new ApiScenarioRequest(); - request.setRefId(scenario.getRefId()); - List scenarioIds = extApiScenarioMapper.selectIdsByQuery(request); + List scenarioIds = new ArrayList<>(); + if (StringUtils.isNotBlank(scenario.getRefId())) { + ApiScenarioRequest request = new ApiScenarioRequest(); + request.setRefId(scenario.getRefId()); + scenarioIds = extApiScenarioMapper.selectIdsByQuery(request); + } else { + scenarioIds.add(scenario.getId()); + } //将这些场景的定时任务删除掉 scenarioIds.forEach(scenarioId -> scheduleService.deleteByResourceId(scenarioId, ScheduleGroup.API_SCENARIO_TEST.name())); ApiScenarioExampleWithOperation example = new ApiScenarioExampleWithOperation(); @@ -1238,6 +1243,9 @@ public class ApiAutomationService { if (scenarioWithBLOBs.getNum() == null) { scenarioWithBLOBs.setNum(getNextNum(scenarioWithBLOBs.getProjectId())); } + if (scenarioWithBLOBs.getRefId() == null) { + scenarioWithBLOBs.setRefId(scenarioWithBLOBs.getId()); + } batchMapper.insert(scenarioWithBLOBs); apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenarioWithBLOBs); extApiScenarioMapper.clearLatestVersion(scenarioWithBLOBs.getRefId()); @@ -1268,6 +1276,9 @@ public class ApiAutomationService { if (scenarioWithBLOBs.getNum() == null) { scenarioWithBLOBs.setNum(getNextNum(scenarioWithBLOBs.getProjectId())); } + if (scenarioWithBLOBs.getRefId() == null) { + scenarioWithBLOBs.setRefId(scenarioWithBLOBs.getId()); + } batchMapper.insert(scenarioWithBLOBs); } else { ApiScenarioWithBLOBs existScenario = scenarioOp.get(); @@ -1282,6 +1293,9 @@ public class ApiAutomationService { if (scenarioWithBLOBs.getNum() == null) { scenarioWithBLOBs.setNum(getNextNum(scenarioWithBLOBs.getProjectId())); } + if (scenarioWithBLOBs.getRefId() == null) { + scenarioWithBLOBs.setRefId(scenarioWithBLOBs.getId()); + } batchMapper.updateByPrimaryKeyWithBLOBs(scenarioWithBLOBs); } checkReferenceCase(scenarioWithBLOBs, apiTestCaseMapper, apiDefinitionMapper); @@ -1362,6 +1376,9 @@ public class ApiAutomationService { if (scenarioWithBLOBs.getNum() == null) { scenarioWithBLOBs.setNum(getNextNum(scenarioWithBLOBs.getProjectId())); } + if (scenarioWithBLOBs.getRefId() == null) { + scenarioWithBLOBs.setRefId(scenarioWithBLOBs.getId()); + } batchMapper.insert(scenarioWithBLOBs); // 存储依赖关系 ApiAutomationRelationshipEdgeService relationshipEdgeService = CommonBeanFactory.getBean(ApiAutomationRelationshipEdgeService.class);