From 85d0b788019ac1283bf552202228d94c3862abbe Mon Sep 17 00:00:00 2001 From: metersphere-bot <78466014+metersphere-bot@users.noreply.github.com> Date: Tue, 27 Jul 2021 08:02:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=EF=BC=8C=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8=E5=8C=96):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9E=83=E5=9C=BE=E7=AB=99=E7=9A=84=E6=97=A7?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=97=A0=E6=B3=95=E6=81=A2=E5=A4=8D=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#5071)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1005429 --user=宋天阳 【github#4993】场景回收站无法批量恢复 https://www.tapd.cn/55049933/s/1029410 Co-authored-by: song-tianyang --- .../api/service/ApiAutomationService.java | 15 ++++++- .../api/service/ApiDefinitionService.java | 39 ++++++++++++------- 2 files changed, 38 insertions(+), 16 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 ce771b3219..839807b786 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -570,7 +570,20 @@ public class ApiAutomationService { ApiScenarioExample example = new ApiScenarioExample(); example.createCriteria().andIdIn(ids); List scenarioList = apiScenarioMapper.selectByExample(example); - Map> nodeMap = scenarioList.stream().collect(Collectors.groupingBy(ApiScenario :: getApiScenarioModuleId)); + Map> nodeMap = new HashMap<>(); + for (ApiScenario api:scenarioList) { + String moduleId = api.getApiScenarioModuleId(); + if(StringUtils.isEmpty(moduleId)){ + moduleId = ""; + } + if(nodeMap.containsKey(moduleId)){ + nodeMap.get(moduleId).add(api); + }else { + List list = new ArrayList<>(); + list.add(api); + nodeMap.put(moduleId,list); + } + } ApiScenarioModuleService apiScenarioModuleService = CommonBeanFactory.getBean(ApiScenarioModuleService.class); for(Map.Entry> entry : nodeMap.entrySet()){ String nodeId = entry.getKey(); 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 d0904ed793..20e3899872 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -241,20 +241,34 @@ public class ApiDefinitionService { ApiDefinitionExample example = new ApiDefinitionExample(); example.createCriteria().andIdIn(request.getIds()); List reductionCaseList = apiDefinitionMapper.selectByExample(example); - Map> nodeMap = reductionCaseList.stream().collect(Collectors.groupingBy(ApiDefinition::getModuleId)); + Map> nodeMap = new HashMap<>(); + for (ApiDefinition api:reductionCaseList) { + String moduleId = api.getModuleId(); + if(StringUtils.isEmpty(moduleId)){ + moduleId = ""; + } + if(nodeMap.containsKey(moduleId)){ + nodeMap.get(moduleId).add(api); + }else { + List list = new ArrayList<>(); + list.add(api); + nodeMap.put(moduleId,list); + } + } +// Map> nodeMap = reductionCaseList.stream().collect(Collectors.groupingBy(ApiDefinition :: getModuleId)); ApiModuleService apiModuleService = CommonBeanFactory.getBean(ApiModuleService.class); - for (Map.Entry> entry : nodeMap.entrySet()) { + for(Map.Entry> entry : nodeMap.entrySet()){ String nodeId = entry.getKey(); long nodeCount = apiModuleService.countById(nodeId); - if (nodeCount <= 0) { + if(nodeCount <= 0){ String projectId = request.getProjectId(); - ApiModule node = apiModuleService.getDefaultNode(projectId, request.getProtocol()); + ApiModule node = apiModuleService.getDefaultNode(projectId,request.getProtocol()); List testCaseList = entry.getValue(); - for (ApiDefinition apiDefinition : testCaseList) { + for (ApiDefinition apiDefinition: testCaseList) { ApiDefinitionWithBLOBs updateCase = new ApiDefinitionWithBLOBs(); updateCase.setId(apiDefinition.getId()); updateCase.setModuleId(node.getId()); - updateCase.setModulePath("/" + node.getName()); + updateCase.setModulePath("/"+node.getName()); apiDefinitionMapper.updateByPrimaryKeySelective(updateCase); } @@ -537,7 +551,7 @@ public class ApiDefinitionService { if (i == 0) { nextNum = apiTestCaseService.getNextNum(item.getApiDefinitionId()); } else { - nextNum++; + nextNum ++; } checkRequest.setName(item.getName()); checkRequest.setApiDefinitionId(item.getApiDefinitionId()); @@ -649,10 +663,10 @@ public class ApiDefinitionService { } - try { + try{ //检查TCP数据结构,等其他进行处理 tcpApiParamService.checkTestElement(request.getTestElement()); - } catch (Exception e) { + }catch (Exception e){ } HashTree hashTree = request.getTestElement().generateHashTree(config); @@ -855,10 +869,6 @@ public class ApiDefinitionService { BeanUtils.copyBean(definitionWithBLOBs, request); definitionWithBLOBs.setUpdateTime(System.currentTimeMillis()); apiDefinitionMapper.updateByExampleSelective(definitionWithBLOBs, getBatchExample(request)); - - // 同步修改用例 - apiTestCaseService.updateByApiDefinitionId(request.getIds(), request.getPath(), request.getMethod(), request.getProtocol()); - } public void testPlanRelevance(ApiCaseRelevanceRequest request) { @@ -1051,7 +1061,6 @@ public class ApiDefinitionService { /** * 列表开关切换 - * * @param request */ public void switchSchedule(Schedule request) { @@ -1291,7 +1300,7 @@ public class ApiDefinitionService { List apiList = apiDefinitionMapper.selectByExample(apiDefinitionExample); List apiIdList = new ArrayList<>(); apiList.forEach(item -> { - apiIdList.add(item.getId()); + apiIdList.add(item.getId()); }); this.removeToGc(apiIdList); }