diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.java index db386cb125..5c88d104d6 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.java @@ -13,4 +13,6 @@ public interface ExtTestPlanCollectionMapper { List selectSecondCollectionEnv(@Param("type") String type, @Param("parentId") String parentId, @Param("testPlanId") String testPlanId); TestPlanCollectionEnvDTO selectFirstCollectionEnv(@Param("type") String type, @Param("parentId") String parentId, @Param("testPlanId") String testPlanId); + + String selectDefaultCollectionId(@Param("testPlanId")String newTestPlanId,@Param("type") String key); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.xml index 67ad22879b..ccd6b711d1 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanCollectionMapper.xml @@ -52,4 +52,7 @@ and tpc.parent_id = #{parentId} and tpc.test_plan_id = #{testPlanId} + \ No newline at end of file diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java index dad9a79b69..97da1aea43 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java @@ -148,8 +148,9 @@ public class TestPlanApiCaseService extends TestPlanResourceService { } @Override - public long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime) { + public long copyResource(String originalTestPlanId, String newTestPlanId, Map oldCollectionIdToNewCollectionId, String operator, long operatorTime) { List copyList = new ArrayList<>(); + String defaultCollectionId = extTestPlanCollectionMapper.selectDefaultCollectionId(newTestPlanId, CaseType.SCENARIO_CASE.getKey()); extTestPlanApiCaseMapper.selectByTestPlanIdAndNotDeleted(originalTestPlanId).forEach(originalCase -> { TestPlanApiCase newCase = new TestPlanApiCase(); BeanUtils.copyBean(newCase, originalCase); @@ -158,6 +159,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService { newCase.setCreateTime(operatorTime); newCase.setCreateUser(operator); newCase.setLastExecTime(0L); + newCase.setTestPlanCollectionId(oldCollectionIdToNewCollectionId.get(newCase.getTestPlanCollectionId()) == null ? defaultCollectionId : oldCollectionIdToNewCollectionId.get(newCase.getTestPlanCollectionId())); newCase.setLastExecResult(ExecStatus.PENDING.name()); newCase.setLastExecReportId(null); copyList.add(newCase); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java index 4db312616d..08fb1f79c9 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java @@ -139,8 +139,9 @@ public class TestPlanApiScenarioService extends TestPlanResourceService { } @Override - public long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime) { + public long copyResource(String originalTestPlanId, String newTestPlanId, Map oldCollectionIdToNewCollectionId, String operator, long operatorTime) { List copyList = new ArrayList<>(); + String defaultCollectionId = extTestPlanCollectionMapper.selectDefaultCollectionId(newTestPlanId,CaseType.SCENARIO_CASE.getKey()); extTestPlanApiScenarioMapper.selectByTestPlanIdAndNotDeleted(originalTestPlanId).forEach(originalCase -> { TestPlanApiScenario newCase = new TestPlanApiScenario(); BeanUtils.copyBean(newCase, originalCase); @@ -149,6 +150,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService { newCase.setCreateTime(operatorTime); newCase.setCreateUser(operator); newCase.setLastExecTime(0L); + newCase.setTestPlanCollectionId(oldCollectionIdToNewCollectionId.get(newCase.getTestPlanCollectionId()) == null ? defaultCollectionId : oldCollectionIdToNewCollectionId.get(newCase.getTestPlanCollectionId())); newCase.setLastExecResult(ExecStatus.PENDING.name()); newCase.setLastExecReportId(null); copyList.add(newCase); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBatchOperationService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBatchOperationService.java index 5e74466f8f..fcaa55b79f 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBatchOperationService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBatchOperationService.java @@ -198,6 +198,7 @@ public class TestPlanBatchOperationService extends TestPlanBaseUtilsService { TestPlanCollectionExample parentCollectionExample = new TestPlanCollectionExample(); parentCollectionExample.createCriteria().andTestPlanIdEqualTo(originalTestPlan.getId()).andParentIdEqualTo(TestPlanConstants.DEFAULT_PARENT_ID); List testPlanCollectionList = testPlanCollectionMapper.selectByExample(parentCollectionExample); + Map oldCollectionIdToNewCollectionId = new HashMap<>(); if (CollectionUtils.isEmpty(testPlanCollectionList)) { //自动生成测试规划 Objects.requireNonNull(CommonBeanFactory.getBean(TestPlanService.class)).initDefaultPlanCollection(testPlan.getId(), operator); @@ -225,6 +226,7 @@ public class TestPlanBatchOperationService extends TestPlanBaseUtilsService { childCollection.setCreateUser(operator); childCollection.setCreateTime(operatorTime); newTestPlanCollectionList.add(childCollection); + oldCollectionIdToNewCollectionId.put(child.getId(), childCollection.getId()); } } testPlanCollectionMapper.batchInsert(newTestPlanCollectionList); @@ -233,7 +235,7 @@ public class TestPlanBatchOperationService extends TestPlanBaseUtilsService { //测试用例信息 Map beansOfType = applicationContext.getBeansOfType(TestPlanResourceService.class); beansOfType.forEach((k, v) -> { - v.copyResource(originalTestPlan.getId(), testPlan.getId(), operator, operatorTime); + v.copyResource(originalTestPlan.getId(), testPlan.getId(), oldCollectionIdToNewCollectionId, operator, operatorTime); }); return testPlan; } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBugService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBugService.java index f1e0a0fcd6..0bb0c550ec 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBugService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBugService.java @@ -58,7 +58,7 @@ public class TestPlanBugService extends TestPlanResourceService { } @Override - public long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime) { + public long copyResource(String originalTestPlanId, String newTestPlanId, Map oldCollectionIdToNewCollectionId, String operator, long operatorTime) { return 0; } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java index eca14eaabd..0c1547a41c 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanExecuteService.java @@ -371,7 +371,7 @@ public class TestPlanExecuteService { String queueId = executionQueue.getPrepareReportId() + "_" + parentCollection.getId(); String queueType = QUEUE_PREFIX_TEST_PLAN_COLLECTION; - String runMode = executionQueue.getRunMode(); + String runMode = parentCollection.getExecuteMethod(); for (TestPlanCollection collection : childrenList) { childrenQueue.add( new TestPlanExecutionQueue( diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java index 55c5a8d5e7..0291a1eeca 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java @@ -124,10 +124,13 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { private OperationLogService operationLogService; @Resource private ExtFunctionalCaseModuleMapper extFunctionalCaseModuleMapper; + @Resource + private ExtTestPlanCollectionMapper extTestPlanCollectionMapper; @Override - public long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime) { + public long copyResource(String originalTestPlanId, String newTestPlanId, Map oldCollectionIdToNewCollectionId, String operator, long operatorTime) { List copyList = new ArrayList<>(); + String defaultCollectionId = extTestPlanCollectionMapper.selectDefaultCollectionId(newTestPlanId,CaseType.SCENARIO_CASE.getKey()); extTestPlanFunctionalCaseMapper.selectByTestPlanIdAndNotDeleted(originalTestPlanId).forEach(originalCase -> { TestPlanFunctionalCase newCase = new TestPlanFunctionalCase(); BeanUtils.copyBean(newCase, originalCase); @@ -136,6 +139,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { newCase.setCreateTime(operatorTime); newCase.setCreateUser(operator); newCase.setLastExecTime(0L); + newCase.setTestPlanCollectionId(oldCollectionIdToNewCollectionId.get(newCase.getTestPlanCollectionId()) == null ? defaultCollectionId : oldCollectionIdToNewCollectionId.get(newCase.getTestPlanCollectionId())); newCase.setLastExecResult(ExecStatus.PENDING.name()); copyList.add(newCase); }); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java index 9c4ee259bd..67d5ea7ebe 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java @@ -55,7 +55,7 @@ public abstract class TestPlanResourceService extends TestPlanSortService { return response; } - public abstract long copyResource(String originalTestPlanId, String newTestPlanId, String operator, long operatorTime); + public abstract long copyResource(String originalTestPlanId, String newTestPlanId, Map oldCollectionIdToNewCollectionId, String operator, long operatorTime); /** * 关联用例 diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java index 0b46e67190..c770182b1f 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -938,8 +938,22 @@ public class TestPlanService extends TestPlanBaseUtilsService { return hisList; } + //只查找未归档的测试计划组以及游离态测试计划 public List selectRightfulIds(List executeIds) { - return extTestPlanMapper.selectNotArchivedIds(executeIds); + TestPlanExample testPlanExample = new TestPlanExample(); + testPlanExample.createCriteria().andIdIn(executeIds).andStatusNotEqualTo(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED); + Map testPlanIdMap = testPlanMapper.selectByExample(testPlanExample) + .stream().collect(Collectors.toMap(TestPlan::getId, v -> v)); + List returnIds = new ArrayList<>(); + for (String executeId : executeIds) { + TestPlan testPlan = testPlanIdMap.get(executeId); + if (testPlan != null && + (StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP) + || StringUtils.equalsIgnoreCase(testPlan.getGroupId(), TestPlanConstants.DEFAULT_PARENT_ID))) { + returnIds.add(executeId); + } + } + return returnIds; } public List selectNotArchivedChildren(String testPlanGroupId) {