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 f738e8a156..1188e7c3f2 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 @@ -267,7 +267,7 @@ public class ApiDefinitionImportUtilService { if (item.getVersionId() == null || (!item.getVersionId().equals("new") && !item.getVersionId().equals("update"))) { item.setNum(num++); } - //如果EsbData需要存储,则需要进行接口是否更新的判断 + ApiDefinitionImportParamDTO apiDefinitionImportParam = new ApiDefinitionImportParamDTO(item, request, apiImport.getMocks(), toUpdateList, caseList); apiDefinitionImportParam.setRepeatList(sameRefIds); ApiImportSendNoticeDTO apiImportSendNoticeDTO = importCreate(batchMapper, apiDefinitionImportParam); @@ -754,17 +754,13 @@ public class ApiDefinitionImportUtilService { if (CollectionUtils.isEmpty(repeatList)) { return; } - if (apiDefinition.getLatest()) { - for (ApiDefinitionWithBLOBs apiDefinitionWithBLOBs : repeatList) { - if (apiDefinitionWithBLOBs.getLatest() && !apiDefinition.getId().equalsIgnoreCase(apiDefinitionWithBLOBs.getId())) { + for (ApiDefinitionWithBLOBs apiDefinitionWithBLOBs : repeatList) { + if (!apiDefinition.getId().equalsIgnoreCase(apiDefinitionWithBLOBs.getId())) { + if (apiDefinition.getLatest() && apiDefinitionWithBLOBs.getLatest()) { apiDefinitionWithBLOBs.setLatest(false); } batchMapper.updateByPrimaryKey(apiDefinitionWithBLOBs); } - } else { - for (ApiDefinitionWithBLOBs apiDefinitionWithBLOBs : repeatList) { - batchMapper.updateByPrimaryKey(apiDefinitionWithBLOBs); - } } } @@ -947,7 +943,9 @@ public class ApiDefinitionImportUtilService { Map methodPathMap, Map> repeatDataMap, String updateVersionId, List optionDataCases, Map> oldCaseMap) { + //要去覆盖接口的集合 List coverApiList = new ArrayList<>(); + //记录已存在数据可以被更新的集合 List updateApiList = new ArrayList<>(); repeatDataMap.forEach((k, v) -> { ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = methodPathMap.get(k); @@ -956,11 +954,13 @@ public class ApiDefinitionImportUtilService { Map> definitionIdCaseMAp = optionDataCases.stream().collect(Collectors.groupingBy(ApiTestCase::getApiDefinitionId)); Map caseNameMap = getDistinctCaseNameMap(definitionIdCaseMAp, apiDefinitionWithBLOBs); int i = 0; + //定义最新版本 ApiDefinitionWithBLOBs latestApi = null; for (ApiDefinitionWithBLOBs definitionWithBLOBs : v) { if (definitionWithBLOBs.getLatest()) { latestApi = definitionWithBLOBs; } + //为了记录指定版本是否有数据 if (!definitionWithBLOBs.getVersionId().equals(updateVersionId)) { i += 1; continue;