diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java index 98ccbe6726..179cbeb488 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java @@ -307,7 +307,12 @@ public class FunctionalCaseMinderService { //处理用例 Map sourceIdAndInsertCaseIdMap = dealCase(request, userId, sqlSession, sourceIdAndInsertModuleIdMap, functionalMinderUpdateDTO); List needToTurnCaseIds = new ArrayList<>(sourceIdAndInsertCaseIdMap.keySet().stream().distinct().toList()); - + //删除模块 + if (CollectionUtils.isNotEmpty(needToTurnCaseIds)) { + FunctionalCaseModuleExample functionalCaseModuleExample = new FunctionalCaseModuleExample(); + functionalCaseModuleExample.createCriteria().andIdIn(needToTurnCaseIds); + moduleMapper.deleteByExample(functionalCaseModuleExample); + } //删除已转为模块或用例的空白节点 needToTurnCaseIds.addAll(needToTurnModuleIds); if (CollectionUtils.isNotEmpty(needToTurnCaseIds)) { @@ -337,7 +342,7 @@ public class FunctionalCaseMinderService { if (CollectionUtils.isNotEmpty(targetIds)) { FunctionalCaseModuleExample functionalCaseModuleExample = new FunctionalCaseModuleExample(); functionalCaseModuleExample.createCriteria().andIdIn(targetIds); - List targetModuleIds = functionalCaseModuleMapper.selectByExample(functionalCaseModuleExample); + List targetModuleIds = moduleMapper.selectByExample(functionalCaseModuleExample); Map targetModuleMap = new HashMap<>(); List targetModuleParentIds = new ArrayList<>(); if (CollectionUtils.isNotEmpty(targetModuleIds)) { @@ -348,7 +353,7 @@ public class FunctionalCaseMinderService { if (CollectionUtils.isNotEmpty(targetModuleParentIds)) { functionalCaseModuleExample = new FunctionalCaseModuleExample(); functionalCaseModuleExample.createCriteria().andParentIdIn(targetModuleParentIds); - allChildrenInDB = functionalCaseModuleMapper.selectByExample(functionalCaseModuleExample); + allChildrenInDB = moduleMapper.selectByExample(functionalCaseModuleExample); } FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample(); @@ -377,14 +382,14 @@ public class FunctionalCaseMinderService { if (CollectionUtils.isNotEmpty(caseModuleIds)) { functionalCaseModuleExample = new FunctionalCaseModuleExample(); functionalCaseModuleExample.createCriteria().andParentIdIn(caseModuleIds); - allChildrenByCaseInDB = functionalCaseModuleMapper.selectByExample(functionalCaseModuleExample); + allChildrenByCaseInDB = moduleMapper.selectByExample(functionalCaseModuleExample); } allChildrenInDB.addAll(allChildrenByCaseInDB); MindAdditionalNodeExample mindAdditionalNodeExample = new MindAdditionalNodeExample(); mindAdditionalNodeExample.createCriteria().andIdIn(targetIds); - List mindAdditionalNodes = mindAdditionalNodeMapper.selectByExample(mindAdditionalNodeExample); + List mindAdditionalNodes = additionalNodeMapper.selectByExample(mindAdditionalNodeExample); Map targetTextMap = new HashMap<>(); List targetTextParentIds = new ArrayList<>(); if (CollectionUtils.isNotEmpty(mindAdditionalNodes)) { @@ -401,7 +406,7 @@ public class FunctionalCaseMinderService { if (CollectionUtils.isNotEmpty(targetTextParentNoRepeatIds)) { mindAdditionalNodeExample = new MindAdditionalNodeExample(); mindAdditionalNodeExample.createCriteria().andParentIdIn(targetTextParentNoRepeatIds); - allChildrenTextInDB = mindAdditionalNodeMapper.selectByExample(mindAdditionalNodeExample); + allChildrenTextInDB = additionalNodeMapper.selectByExample(mindAdditionalNodeExample); parentChildrenTextMap = allChildrenTextInDB.stream().collect(Collectors.groupingBy(MindAdditionalNode::getParentId)); } @@ -411,7 +416,7 @@ public class FunctionalCaseMinderService { if (CollectionUtils.isNotEmpty(textModuleIds)) { functionalCaseModuleExample = new FunctionalCaseModuleExample(); functionalCaseModuleExample.createCriteria().andParentIdIn(textModuleIds); - List allChildrenByTextInDB = functionalCaseModuleMapper.selectByExample(functionalCaseModuleExample); + List allChildrenByTextInDB = moduleMapper.selectByExample(functionalCaseModuleExample); allChildrenInDB.addAll(allChildrenByTextInDB); } List textModuleFilterCaseIds = targetTextParentIds.stream().filter(t -> !targetCaseParentIdsNoRepeat.contains(t)).distinct().toList(); diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java index cad5e1f068..361db41a1d 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java @@ -197,6 +197,21 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { caseChangeRequests.add(caseChangeRequest); request.setUpdateCaseList(caseChangeRequests); + caseChangeRequest = new FunctionalCaseChangeRequest(); + caseChangeRequest.setId("TEST_MINDER_MODULE_ID_GYQ_A"); + caseChangeRequest.setName("模块转用例"); + caseChangeRequest.setModuleId("TEST_MINDER_MODULE_ID_GYQ8"); + caseChangeRequest.setTemplateId("100001"); + caseChangeRequest.setMoveMode("BEFORE"); + caseChangeRequest.setTargetId("TEST_FUNCTIONAL_MINDER_CASE_ID_2"); + caseChangeRequest.setType("ADD"); + caseChangeRequest.setPrerequisite("前置条件"); + caseChangeRequest.setCaseEditType("TEXT"); + customFields = new ArrayList<>(); + caseChangeRequest.setCustomFields(customFields); + caseChangeRequests.add(caseChangeRequest); + request.setUpdateCaseList(caseChangeRequests); + List functionalCaseModuleEditRequests = new ArrayList<>(); FunctionalCaseModuleEditRequest functionalCaseModuleEditRequest = new FunctionalCaseModuleEditRequest(); functionalCaseModuleEditRequest.setId("uuuId"); @@ -226,7 +241,7 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { mindAdditionalNodeRequest = new MindAdditionalNodeRequest(); mindAdditionalNodeRequest.setId("additional2"); mindAdditionalNodeRequest.setType("UPDATE"); - mindAdditionalNodeRequest.setName("additional2"); + mindAdditionalNodeRequest.setName("additional2更新"); mindAdditionalNodeRequest.setParentId("TEST_MINDER_MODULE_ID_GYQ"); additionalNodeList.add(mindAdditionalNodeRequest); request.setAdditionalNodeList(additionalNodeList); @@ -255,12 +270,26 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { List functionalCaseCustomFields = functionalCaseCustomFieldMapper.selectByExample(customFieldExample); Assertions.assertTrue(StringUtils.equalsIgnoreCase(functionalCaseCustomFields.get(0).getValue(),"P0")); - MindAdditionalNode mindAdditionalNode = mindAdditionalNodeMapper.selectByPrimaryKey("additional2"); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(mindAdditionalNode.getParentId(),"TEST_MINDER_MODULE_ID_GYQ")); + FunctionalCaseModule functionalCaseModule = functionalCaseModuleMapper.selectByPrimaryKey("TEST_MINDER_MODULE_ID_GYQ7"); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(functionalCaseModule.getName(),"移动7")); + + FunctionalCaseModule functionalCaseModule1 = functionalCaseModuleMapper.selectByPrimaryKey("TEST_MINDER_MODULE_ID_GYQ_A"); + Assertions.assertNull(functionalCaseModule1); + FunctionalCaseExample functionalCaseExample = new FunctionalCaseExample(); - functionalCaseExample.createCriteria().andNameEqualTo("新增用例"); + functionalCaseExample.createCriteria().andNameEqualTo("模块转用例"); List functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample); Assertions.assertTrue(CollectionUtils.isNotEmpty(functionalCases)); + + MindAdditionalNode mindAdditionalNode = mindAdditionalNodeMapper.selectByPrimaryKey("additional2"); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(mindAdditionalNode.getName(),"additional2更新")); + + + Assertions.assertTrue(StringUtils.equalsIgnoreCase(mindAdditionalNode.getParentId(),"TEST_MINDER_MODULE_ID_GYQ")); + functionalCaseExample = new FunctionalCaseExample(); + functionalCaseExample.createCriteria().andNameEqualTo("新增用例"); + functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample); + Assertions.assertTrue(CollectionUtils.isNotEmpty(functionalCases)); Assertions.assertTrue(functionalCases.get(0).getPos() > 0L); Assertions.assertTrue(CollectionUtils.isNotEmpty(functionalCases)); diff --git a/backend/services/case-management/src/test/resources/dml/init_file_minder_test.sql b/backend/services/case-management/src/test/resources/dml/init_file_minder_test.sql index bd51b93686..e3b6ba0577 100644 --- a/backend/services/case-management/src/test/resources/dml/init_file_minder_test.sql +++ b/backend/services/case-management/src/test/resources/dml/init_file_minder_test.sql @@ -45,8 +45,9 @@ VALUES ('TEST_MINDER_MODULE_ID_GYQ7', 'project-case-minder-test', '测试所属模块7', 'TEST_MINDER_MODULE_ID_GYQ', 0, 1669174143999, 1669174143999, 'admin', 'admin'), ('TEST_MINDER_MODULE_ID_GYQ8', 'project-case-minder-test', '测试所属模块8', 'TEST_MINDER_MODULE_ID_GYQ', 0, 1669174143999, 1669174143999, 'admin', 'admin'), ('TEST_MINDER_MODULE_ID_GYQ6', 'project-case-minder-test-xx', '测试所属模块1', 'NONE', 0, 1669174143999, 1669174143999, 'admin', 'admin'), - ('TEST_MINDER_MODULE_ID_GYQ9', 'project-case-minder-test', '用来删除', 'NONE', 0, 1669174143999, 1669174143999, 'admin', 'admin'); -; + ('TEST_MINDER_MODULE_ID_GYQ9', 'project-case-minder-test', '用来删除', 'NONE', 0, 1669174143999, 1669174143999, 'admin', 'admin'), + ('TEST_MINDER_MODULE_ID_GYQ_A', 'project-case-minder-test', '模块转用例', 'TEST_MINDER_MODULE_ID_GYQ8', 0, 1669174143999, 1669174143999, 'admin', 'admin'); + INSERT INTO test_plan(id, num, project_id, group_id, module_id, name, status, type, tags, create_time, create_user, update_time, update_user, planned_start_time, planned_end_time, actual_start_time, actual_end_time, description)