From 3cc12dd46a1ed4446647c537949516aab410cefc Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Fri, 14 Jun 2024 14:09:40 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):?= =?UTF-8?q?=20=E8=84=91=E5=9B=BE=E8=A7=84=E5=88=92=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestPlanCollectionMinderEditRequest.java | 3 -- .../TestPlanCollectionMinderService.java | 36 ++++++++++++++----- ...stPlanCollectionMinderControllerTests.java | 7 ++-- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCollectionMinderEditRequest.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCollectionMinderEditRequest.java index b759225806..32f5447a7f 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCollectionMinderEditRequest.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCollectionMinderEditRequest.java @@ -24,7 +24,4 @@ public class TestPlanCollectionMinderEditRequest implements Serializable { @Schema(description = "新增/修改的节点集合", requiredMode = Schema.RequiredMode.REQUIRED) private List editList; - @Schema(description = "删除的节点集合", requiredMode = Schema.RequiredMode.REQUIRED) - private List deletedIds; - } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCollectionMinderService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCollectionMinderService.java index 8422485226..d71a1d796c 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCollectionMinderService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCollectionMinderService.java @@ -7,6 +7,7 @@ import io.metersphere.plan.dto.request.TestPlanCollectionMinderEditRequest; import io.metersphere.plan.mapper.*; import io.metersphere.sdk.constants.ApiBatchRunMode; import io.metersphere.sdk.constants.CaseType; +import io.metersphere.sdk.constants.CommonConstants; import io.metersphere.sdk.constants.ModuleConstants; import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.Translator; @@ -100,9 +101,9 @@ public class TestPlanCollectionMinderService { BeanUtils.copyBean(typeTreeNodeDTO, testPlanCollection); typeTreeNodeDTO.setText(Translator.get(testPlanCollection.getName(), testPlanCollection.getName())); if (StringUtils.equalsIgnoreCase(testPlanCollection.getExecuteMethod(), ApiBatchRunMode.PARALLEL.toString())) { - typeTreeNodeDTO.setPriority(2); - } else { typeTreeNodeDTO.setPriority(3); + } else { + typeTreeNodeDTO.setPriority(2); } if (StringUtils.equalsIgnoreCase(CaseType.FUNCTIONAL_CASE.getKey(),testPlanCollection.getType())) { typeTreeNodeDTO.setPriority(null); @@ -240,10 +241,6 @@ public class TestPlanCollectionMinderService { public void editMindTestPlanCase(TestPlanCollectionMinderEditRequest request, String userId) { - //处理删除 - if (CollectionUtils.isNotEmpty(request.getDeletedIds())) { - testPlanService.deletePlanCollectionResource(request.getDeletedIds()); - } Map> associateMap = new HashMap<>(); //处理新增与更新 dealEditList(request, userId, associateMap); @@ -268,9 +265,14 @@ public class TestPlanCollectionMinderService { } } - private static void dealUpdateList(TestPlanCollectionMinderEditRequest request, String userId, Map> associateMap, Map> parentMap, TestPlanCollectionMapper collectionMapper) { + private void dealUpdateList(TestPlanCollectionMinderEditRequest request, String userId, Map> associateMap, Map> parentMap, TestPlanCollectionMapper collectionMapper) { List updateList = request.getEditList().stream().filter(t -> StringUtils.isNotBlank(t.getId())).toList(); + + if (CollectionUtils.isNotEmpty(updateList)) { + //处理删除 + deleteCollection(updateList); + //处理更新 for (TestPlanCollectionMinderEditDTO testPlanCollectionMinderEditDTO : updateList) { TestPlanCollection testPlanCollection = updateCollection(request, userId, testPlanCollectionMinderEditDTO, parentMap, collectionMapper); setAssociateMap(testPlanCollectionMinderEditDTO, associateMap, testPlanCollection); @@ -278,6 +280,17 @@ public class TestPlanCollectionMinderService { } } + private void deleteCollection(List updateList) { + List existIds = updateList.stream().map(TestPlanCollectionMinderEditDTO::getId).toList(); + TestPlanCollectionExample example = new TestPlanCollectionExample(); + example.createCriteria().andIdNotIn(existIds); + List collections = testPlanCollectionMapper.selectByExample(example); + if (CollectionUtils.isNotEmpty(collections)) { + List deletedIds = collections.stream().map(TestPlanCollection::getId).toList(); + testPlanService.deletePlanCollectionResource(deletedIds); + } + } + private static void dealAddList(TestPlanCollectionMinderEditRequest request, String userId, Map> associateMap, Map> parentMap, TestPlanCollectionMapper collectionMapper) { List addList = request.getEditList().stream().filter(t -> StringUtils.isBlank(t.getId())).toList(); if (CollectionUtils.isNotEmpty(addList)) { @@ -325,8 +338,13 @@ public class TestPlanCollectionMinderService { testPlanCollection.setName(testPlanCollectionMinderEditDTO.getText()); testPlanCollection.setTestPlanId(request.getPlanId()); testPlanCollection.setType(testPlanCollectionMinderEditDTO.getType()); - TestPlanCollection parent = parentMap.get(testPlanCollectionMinderEditDTO.getType()).get(0); - testPlanCollection.setParentId(parent.getId()); + List testPlanCollections = parentMap.get(testPlanCollectionMinderEditDTO.getType()); + if (CollectionUtils.isNotEmpty(testPlanCollections)) { + TestPlanCollection parent = testPlanCollections.get(0); + testPlanCollection.setParentId(parent.getId()); + } else { + testPlanCollection.setParentId(CommonConstants.DEFAULT_NULL_VALUE); + } testPlanCollection.setCreateUser(userId); testPlanCollection.setCreateTime(System.currentTimeMillis()); testPlanCollection.setPos(testPlanCollectionMinderEditDTO.getNum()); diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCollectionMinderControllerTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCollectionMinderControllerTests.java index df8275653c..55abc7ee82 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCollectionMinderControllerTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCollectionMinderControllerTests.java @@ -58,6 +58,7 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest { TestPlanCollectionMinderEditRequest request = new TestPlanCollectionMinderEditRequest(); request.setPlanId("gyq_plan_1"); List editList = new ArrayList<>(); + TestPlanCollectionMinderEditDTO deleteDTO = new TestPlanCollectionMinderEditDTO(); TestPlanCollectionMinderEditDTO testPlanCollectionMinderEditDTO = new TestPlanCollectionMinderEditDTO(); testPlanCollectionMinderEditDTO.setId("gyq_wxxx_4"); testPlanCollectionMinderEditDTO.setText("更新名称"); @@ -79,6 +80,7 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest { testPlanCollectionAssociateDTO.setIds(List.of("gyq_plan_api-case-associate-1")); associateDTOS.add(testPlanCollectionAssociateDTO); testPlanCollectionMinderEditDTO.setAssociateDTOS(associateDTOS); + deleteDTO = testPlanCollectionMinderEditDTO; editList.add(testPlanCollectionMinderEditDTO); request.setEditList(editList); this.requestPostWithOkAndReturn(EDIT_MIND, request); @@ -114,8 +116,9 @@ public class TestPlanCollectionMinderControllerTests extends BaseTest { testPlanCollectionExample.createCriteria().andNameEqualTo("新建名称"); List testPlanCollections = testPlanCollectionMapper.selectByExample(testPlanCollectionExample); Assertions.assertTrue(CollectionUtils.isNotEmpty(testPlanCollections)); - request.setEditList(new ArrayList<>()); - request.setDeletedIds(List.of(testPlanCollections.get(0).getId())); + editList = new ArrayList<>(); + editList.add(deleteDTO); + request.setEditList(editList); this.requestPostWithOkAndReturn(EDIT_MIND, request); testPlanCollectionExample = new TestPlanCollectionExample(); testPlanCollectionExample.createCriteria().andNameEqualTo("新建名称");