diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java index d52f58bd3f..1c3efeb79f 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java @@ -143,7 +143,7 @@ public class TestPlanFunctionalCaseController { @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") public void run(@Validated @RequestBody TestPlanCaseRunRequest request) { testPlanFunctionalCaseService.run(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/run", HttpMethodConstants.POST.name())); - extTestPlanMapper.setActualStartTime(request.getTestPlanId(), System.currentTimeMillis()); + testPlanService.setActualStartTime(request.getTestPlanId()); testPlanService.refreshTestPlanStatus(request.getTestPlanId()); } @@ -153,7 +153,7 @@ public class TestPlanFunctionalCaseController { @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") public void batchRun(@Validated @RequestBody TestPlanCaseBatchRunRequest request) { testPlanFunctionalCaseService.batchRun(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/batch/run", HttpMethodConstants.POST.name())); - extTestPlanMapper.setActualStartTime(request.getTestPlanId(), System.currentTimeMillis()); + testPlanService.setActualStartTime(request.getTestPlanId()); testPlanService.refreshTestPlanStatus(request.getTestPlanId()); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java index 92921025ee..36768360c1 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseBatchRunService.java @@ -26,6 +26,7 @@ import io.metersphere.sdk.constants.CommonConstants; import io.metersphere.sdk.dto.api.task.*; import io.metersphere.sdk.dto.queue.ExecutionQueue; import io.metersphere.sdk.dto.queue.ExecutionQueueDetail; +import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.SubListUtils; import jakarta.annotation.Resource; @@ -83,7 +84,9 @@ public class TestPlanApiCaseBatchRunService { * @param userId */ public void asyncBatchRun(TestPlanApiCaseBatchRunRequest request, String userId) { - extTestPlanMapper.setActualStartTime(request.getTestPlanId(), System.currentTimeMillis()); + TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class); + testPlanService.setTestPlanUnderway(request.getTestPlanId()); + testPlanService.setActualStartTime(request.getTestPlanId()); Thread.startVirtualThread(() -> batchRun(request, userId)); } 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 9b60e44024..82e07c49bb 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 @@ -34,6 +34,7 @@ import io.metersphere.sdk.dto.api.task.*; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.mapper.EnvironmentMapper; import io.metersphere.sdk.util.BeanUtils; +import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.Translator; import io.metersphere.system.dto.LogInsertModule; import io.metersphere.system.dto.sdk.BaseTreeNode; @@ -640,7 +641,9 @@ public class TestPlanApiCaseService extends TestPlanResourceService { public TaskRequestDTO run(String id, String reportId, String userId) { TestPlanApiCase testPlanApiCase = checkResourceExist(id); - extTestPlanMapper.setActualStartTime(testPlanApiCase.getTestPlanId(), System.currentTimeMillis()); + TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class); + testPlanService.setTestPlanUnderway(testPlanApiCase.getTestPlanId()); + testPlanService.setActualStartTime(testPlanApiCase.getTestPlanId()); ApiTestCase apiTestCase = apiTestCaseService.checkResourceExist(testPlanApiCase.getApiCaseId()); ApiRunModeConfigDTO runModeConfig = testPlanApiBatchRunBaseService.getApiRunModeConfig(testPlanApiCase.getTestPlanCollectionId()); runModeConfig.setEnvironmentId(apiBatchRunBaseService.getEnvId(runModeConfig, testPlanApiCase.getEnvironmentId())); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java index c6df549add..ed4c56fec4 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioBatchRunService.java @@ -25,6 +25,7 @@ import io.metersphere.sdk.constants.TaskTriggerMode; import io.metersphere.sdk.dto.api.task.*; import io.metersphere.sdk.dto.queue.ExecutionQueue; import io.metersphere.sdk.dto.queue.ExecutionQueueDetail; +import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.DateUtils; import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.SubListUtils; @@ -82,7 +83,9 @@ public class TestPlanApiScenarioBatchRunService { * @param userId */ public void asyncBatchRun(TestPlanApiScenarioBatchRunRequest request, String userId) { - extTestPlanMapper.setActualStartTime(request.getTestPlanId(), System.currentTimeMillis()); + TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class); + testPlanService.setActualStartTime(request.getTestPlanId()); + testPlanService.setTestPlanUnderway(request.getTestPlanId()); Thread.startVirtualThread(() -> batchRun(request, userId)); } 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 af8d916028..50bf168f47 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 @@ -36,6 +36,7 @@ import io.metersphere.sdk.dto.api.task.*; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.mapper.EnvironmentMapper; import io.metersphere.sdk.util.BeanUtils; +import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.Translator; import io.metersphere.system.dto.LogInsertModule; import io.metersphere.system.dto.sdk.BaseTreeNode; @@ -292,7 +293,9 @@ public class TestPlanApiScenarioService extends TestPlanResourceService { public TaskRequestDTO run(String id, String reportId, String userId) { TestPlanApiScenario testPlanApiScenario = checkResourceExist(id); - extTestPlanMapper.setActualStartTime(testPlanApiScenario.getTestPlanId(), System.currentTimeMillis()); + TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class); + testPlanService.setTestPlanUnderway(testPlanApiScenario.getTestPlanId()); + testPlanService.setActualStartTime(testPlanApiScenario.getTestPlanId()); ApiScenario apiScenario = apiScenarioService.checkResourceExist(testPlanApiScenario.getApiScenarioId()); ApiRunModeConfigDTO runModeConfig = testPlanApiBatchRunBaseService.getApiRunModeConfig(testPlanApiScenario.getTestPlanCollectionId()); runModeConfig.setEnvironmentId(apiBatchRunBaseService.getEnvId(runModeConfig, testPlanApiScenario.getEnvironmentId())); 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 420a41bd8c..52fe4a0446 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 @@ -7,11 +7,7 @@ import io.metersphere.plan.dto.request.TestPlanBatchExecuteRequest; import io.metersphere.plan.dto.request.TestPlanExecuteRequest; import io.metersphere.plan.dto.request.TestPlanReportGenRequest; import io.metersphere.plan.mapper.*; -import io.metersphere.sdk.constants.ApiBatchRunMode; -import io.metersphere.sdk.constants.CaseType; -import io.metersphere.sdk.constants.ExecStatus; -import io.metersphere.sdk.constants.TaskTriggerMode; -import io.metersphere.sdk.constants.TestPlanConstants; +import io.metersphere.sdk.constants.*; import io.metersphere.sdk.dto.queue.TestPlanExecutionQueue; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.JSON; @@ -221,6 +217,10 @@ public class TestPlanExecuteService { genReportRequest.setTestPlanId(executionQueue.getSourceID()); genReportRequest.setProjectId(testPlan.getProjectId()); if (StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { + + testPlanService.setActualStartTime(executionQueue.getSourceID()); + testPlanService.setTestPlanUnderway(executionQueue.getSourceID()); + List children = testPlanService.selectNotArchivedChildren(testPlan.getId()); // 预生成计划组报告 Map reportMap = testPlanReportService.genReportByExecution(executionQueue.getPrepareReportId(), genReportRequest, executionQueue.getCreateUser()); @@ -279,7 +279,8 @@ public class TestPlanExecuteService { //执行测试计划里不同类型的用例 回调:caseTypeExecuteQueueFinish public void executeTestPlan(TestPlanExecutionQueue executionQueue) { - extTestPlanMapper.setActualStartTime(executionQueue.getSourceID(), System.currentTimeMillis()); + testPlanService.setActualStartTime(executionQueue.getSourceID()); + testPlanService.setTestPlanUnderway(executionQueue.getSourceID()); TestPlan testPlan = testPlanMapper.selectByPrimaryKey(executionQueue.getSourceID()); TestPlanCollectionExample testPlanCollectionExample = new TestPlanCollectionExample(); testPlanCollectionExample.createCriteria().andTestPlanIdEqualTo(testPlan.getId()).andParentIdEqualTo("NONE"); 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 d589d94cc3..c3ed3ac371 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 @@ -753,6 +753,48 @@ public class TestPlanService extends TestPlanBaseUtilsService { @Autowired private ApplicationContext applicationContext; + public void setTestPlanUnderway(String testPlanId) { + this.updateTestPlanStatusAndGroupStatus(testPlanId, TestPlanConstants.TEST_PLAN_STATUS_UNDERWAY); + } + + public void setActualStartTime(String testPlanId) { + long actualStartTime = System.currentTimeMillis(); + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(testPlanId); + if (testPlan != null) { + extTestPlanMapper.setActualStartTime(testPlan.getId(), actualStartTime); + if (!StringUtils.equalsIgnoreCase(testPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { + extTestPlanMapper.setActualStartTime(testPlan.getGroupId(), actualStartTime); + } + } + } + + private void updateTestPlanStatusAndGroupStatus(String testPlanId, String testPlanStatus) { + TestPlan testPlan = new TestPlan(); + testPlan.setId(testPlanId); + testPlan.setStatus(testPlanStatus); + testPlanMapper.updateByPrimaryKeySelective(testPlan); + + testPlan = testPlanMapper.selectByPrimaryKey(testPlanId); + if (!StringUtils.equalsIgnoreCase(testPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { + //该测试计划是测试计划组内的子计划, 要同步计算测试计划组的状态 + List childPlan = this.selectNotArchivedChildren(testPlan.getGroupId()); + if (CollectionUtils.isNotEmpty(childPlan)) { + TestPlan updateGroupPlan = new TestPlan(); + updateGroupPlan.setId(testPlan.getGroupId()); + if (childPlan.stream().allMatch(item -> StringUtils.equals(item.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_COMPLETED))) { + updateGroupPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_COMPLETED); + } else { + updateGroupPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_UNDERWAY); + } + testPlanMapper.updateByPrimaryKeySelective(updateGroupPlan); + + if (StringUtils.equalsIgnoreCase(updateGroupPlan.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_COMPLETED)) { + extTestPlanMapper.setActualEndTime(testPlan.getGroupId(), System.currentTimeMillis()); + } + } + } + } + public void refreshTestPlanStatus(String testPlanId) { Map caseExecResultCount = new HashMap<>(); Map beansOfType = applicationContext.getBeansOfType(TestPlanResourceService.class); @@ -779,28 +821,8 @@ public class TestPlanService extends TestPlanBaseUtilsService { testPlanFinalStatus = TestPlanConstants.TEST_PLAN_STATUS_COMPLETED; extTestPlanMapper.setActualEndTime(testPlanId, System.currentTimeMillis()); } - TestPlan testPlan = new TestPlan(); - testPlan.setId(testPlanId); - testPlan.setStatus(testPlanFinalStatus); - testPlanMapper.updateByPrimaryKeySelective(testPlan); - testPlan = testPlanMapper.selectByPrimaryKey(testPlanId); - - if (!StringUtils.equalsIgnoreCase(testPlan.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { - //该测试计划是测试计划组内的子计划, 要同步计算测试计划组的状态 - - List childPlan = this.selectNotArchivedChildren(testPlan.getGroupId()); - if (CollectionUtils.isNotEmpty(childPlan)) { - TestPlan updateGroupPlan = new TestPlan(); - updateGroupPlan.setId(testPlan.getGroupId()); - if (childPlan.stream().allMatch(item -> StringUtils.equals(item.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_COMPLETED))) { - updateGroupPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_COMPLETED); - } else { - updateGroupPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_UNDERWAY); - } - testPlanMapper.updateByPrimaryKeySelective(updateGroupPlan); - } - } + this.updateTestPlanStatusAndGroupStatus(testPlanId, testPlanFinalStatus); } public TestPlanOperationResponse sortInGroup(PosRequest request, LogInsertModule logInsertModule) {