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); }