diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtilService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtilService.java index cfa973d8e8..f738e8a156 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtilService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtilService.java @@ -386,7 +386,7 @@ public class ApiDefinitionImportUtilService { ApiTestImportRequest request = apiImportParamDto.getRequest(); List optionData = apiImportParamDto.getOptionData(); ApiModuleDTO chooseModule = apiImportParamDto.getChooseModule(); - Map idPathMap = apiImportParamDto.getIdPathMap(); + Map moduleIdPathMap = apiImportParamDto.getIdPathMap(); Boolean fullCoverage = apiImportParamDto.getFullCoverage(); List toUpdateList = apiImportParamDto.getToUpdateList(); List optionDataCases = apiImportParamDto.getOptionDataCases(); @@ -413,7 +413,7 @@ public class ApiDefinitionImportUtilService { if (chooseModule != null) { //如果有选中的模块,则在选中的模块下过滤 过滤规则是 选择的模块路径+名称+method+path String chooseModuleParentId = getChooseModuleParentId(chooseModule); - String chooseModulePath = getChooseModulePath(idPathMap, chooseModule, chooseModuleParentId); + String chooseModulePath = getChooseModulePath(moduleIdPathMap, chooseModule, chooseModuleParentId); //这样的过滤规则下可能存在重复接口,如果是覆盖模块,需要按照去重规则再次去重,否则就加上接口原有的模块 if (fullCoverage) { removeHttpChooseModuleRepeat(optionData, chooseModulePath); @@ -829,7 +829,7 @@ public class ApiDefinitionImportUtilService { ApiTestImportRequest request = apiImportParamDto.getRequest(); List optionData = apiImportParamDto.getOptionData(); ApiModuleDTO chooseModule = apiImportParamDto.getChooseModule(); - Map idPathMap = apiImportParamDto.getIdPathMap(); + Map moduleIdPathMap = apiImportParamDto.getIdPathMap(); Boolean fullCoverage = apiImportParamDto.getFullCoverage(); List toUpdateList = apiImportParamDto.getToUpdateList(); List optionDataCases = apiImportParamDto.getOptionDataCases(); @@ -851,7 +851,7 @@ public class ApiDefinitionImportUtilService { if (chooseModule != null) { String chooseModuleParentId = getChooseModuleParentId(chooseModule); - String chooseModulePath = getChooseModulePath(idPathMap, chooseModule, chooseModuleParentId); + String chooseModulePath = getChooseModulePath(moduleIdPathMap, chooseModule, chooseModuleParentId); if (fullCoverage) { List singleOptionData = new ArrayList<>(); removeOtherChooseModuleRepeat(optionData, singleOptionData, chooseModulePath); @@ -1090,7 +1090,10 @@ public class ApiDefinitionImportUtilService { private void removeSameData(Map> repeatDataMap, Map methodPathMap, List optionData, Map moduleMap, List optionDataCases) { - + Map parentIdModuleMap = new HashMap<>(); + for (ApiModule value : moduleMap.values()) { + parentIdModuleMap.put(value.getParentId(), value); + } Map> moduleOptionData = optionData.stream().collect(Collectors.groupingBy(ApiDefinition::getModulePath)); repeatDataMap.forEach((k, v) -> { ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = methodPathMap.get(k); @@ -1100,7 +1103,10 @@ public class ApiDefinitionImportUtilService { String modulePath = apiDefinitionWithBLOBs.getModulePath(); List moduleData = moduleOptionData.get(modulePath); if (moduleData != null && moduleData.size() <= 1) { - moduleMap.remove(modulePath); + ApiModule apiModule = moduleMap.get(modulePath); + if (parentIdModuleMap.get(apiModule.getId()) == null) { + moduleMap.remove(modulePath); + } moduleData.remove(apiDefinitionWithBLOBs); } //不覆盖同一接口不做更新 注意原接口的update时间不变