From 4b218f2baf73dc7a4e1eed7a3180715f87f6cba6 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Sun, 23 Jun 2024 18:23:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97=E4=B8=AD=E5=AF=B9=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E8=AE=A1=E5=88=92=E7=BB=84=E6=88=96=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E5=AF=B9=E5=BA=94=E6=89=80=E5=B1=9E=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=88=A4=E6=96=AD=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/controller/TestPlanExecuteController.java | 4 +++- .../metersphere/plan/job/TestPlanScheduleJob.java | 8 +++++--- .../plan/service/TestPlanBatchOperationService.java | 13 ++++++++++--- .../plan/service/TestPlanLogService.java | 2 +- .../plan/controller/TestPlanExecuteTests.java | 4 +--- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanExecuteController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanExecuteController.java index 54e1450961..246d464f5b 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanExecuteController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanExecuteController.java @@ -51,7 +51,9 @@ public class TestPlanExecuteController { @Log(type = OperationLogType.EXECUTE, expression = "#msClass.batchExecuteLog(#request)", msClass = TestPlanLogService.class) public void startExecute(@Validated @RequestBody TestPlanBatchExecuteRequest request) { testPlanManagementService.checkModuleIsOpen(request.getProjectId(), TestPlanResourceConfig.CHECK_TYPE_PROJECT, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN)); - testPlanExecuteService.batchExecuteTestPlan(request, SessionUtils.getUserId()); + Thread.startVirtualThread(() -> + testPlanExecuteService.batchExecuteTestPlan(request, SessionUtils.getUserId()) + ); } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/job/TestPlanScheduleJob.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/job/TestPlanScheduleJob.java index 40262c5869..cc62357d9c 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/job/TestPlanScheduleJob.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/job/TestPlanScheduleJob.java @@ -6,6 +6,7 @@ import io.metersphere.sdk.constants.ApiBatchRunMode; import io.metersphere.sdk.constants.ApiExecuteRunMode; import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.JSON; +import io.metersphere.sdk.util.LogUtils; import io.metersphere.system.schedule.BaseScheduleJob; import org.quartz.JobExecutionContext; import org.quartz.JobKey; @@ -21,13 +22,14 @@ public class TestPlanScheduleJob extends BaseScheduleJob { assert testPlanExecuteService != null; Map runConfig = JSON.parseObject(context.getJobDetail().getJobDataMap().get("config").toString(), Map.class); String runMode = runConfig.containsKey("runMode") ? runConfig.get("runMode") : ApiBatchRunMode.SERIAL.name(); - Thread.startVirtualThread(() -> { + LogUtils.info("开始执行测试计划的定时任务. ID:" + resourceId); + Thread.startVirtualThread(() -> testPlanExecuteService.singleExecuteTestPlan(new TestPlanExecuteRequest() {{ this.setExecuteId(resourceId); this.setRunMode(runMode); this.setExecutionSource(ApiExecuteRunMode.SCHEDULE.name()); - }}, userId); - }); + }}, userId) + ); } 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 a0e3f6aed9..d1740fa7fe 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 @@ -86,10 +86,13 @@ public class TestPlanBatchOperationService extends TestPlanBaseUtilsService { List movePlanIds = new ArrayList<>(); for (TestPlan testPlan : testPlanList) { + // 已归档的测试计划无法操作 + if (StringUtils.equalsIgnoreCase(testPlan.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED)) { + throw new MSException(Translator.get("test_plan.is.archived")); + } // 已归档的测试计划无法操作 测试计划组无法操作 - if (StringUtils.equalsIgnoreCase(testPlan.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED) - || StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { - continue; + if (StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { + throw new MSException(Translator.get("test_plan.group.error")); } movePlanIds.add(testPlan.getId()); } @@ -195,6 +198,8 @@ public class TestPlanBatchOperationService extends TestPlanBaseUtilsService { testPlan.setModuleId(moduleId); testPlan.setGroupId(groupId); testPlan.setPos(pos); + testPlan.setActualEndTime(null); + testPlan.setActualStartTime(null); testPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_PREPARED); testPlanMapper.insert(testPlan); @@ -282,6 +287,8 @@ public class TestPlanBatchOperationService extends TestPlanBaseUtilsService { testPlanGroup.setUpdateUser(operator); testPlanGroup.setUpdateTime(operatorTime); testPlanGroup.setModuleId(moduleId); + testPlanGroup.setActualEndTime(null); + testPlanGroup.setActualStartTime(null); testPlanGroup.setStatus(TestPlanConstants.TEST_PLAN_STATUS_PREPARED); testPlanMapper.insert(testPlanGroup); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanLogService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanLogService.java index 4338951ba2..4153187b64 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanLogService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanLogService.java @@ -257,7 +257,7 @@ public class TestPlanLogService { } private String getLogModule(TestPlan testPlan) { - if (StringUtils.equalsIgnoreCase(testPlan.getStatus(), TestPlanConstants.TEST_PLAN_TYPE_PLAN)) { + if (StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_PLAN)) { return OperationLogModule.TEST_PLAN_TEST_PLAN; } else { return OperationLogModule.TEST_PLAN_TEST_PLAN_GROUP; diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanExecuteTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanExecuteTests.java index 6912a33ce4..083c4feafe 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanExecuteTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanExecuteTests.java @@ -45,7 +45,6 @@ public class TestPlanExecuteTests extends BaseTest { private static TestPlan noGroupPlan; private static final String URL_POST_TEST_PLAN_SINGLE_EXECUTE = "/test-plan-execute/single"; - private static final String URL_POST_TEST_PLAN_BATCH_EXECUTE = "/test-plan-execute/batch"; @Resource private CommonProjectService commonProjectService; @@ -242,8 +241,7 @@ public class TestPlanExecuteTests extends BaseTest { batchExecuteRequest.setExecuteIds(execIds); batchExecuteRequest.setProjectId(project.getId()); batchExecuteRequest.setRunMode(runMode); - - this.requestPostWithOk(URL_POST_TEST_PLAN_BATCH_EXECUTE, batchExecuteRequest); + testPlanExecuteService.batchExecuteTestPlan(batchExecuteRequest, "admin"); //检查队列 List allQueueIds = new ArrayList<>();