From 29ca3d27c67a6c64214a6a8aac3a3ab7543cee48 Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Thu, 20 Jun 2024 12:16:05 +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=E5=8D=95=E7=8B=AC=E6=89=A7=E8=A1=8C=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E8=AE=A1=E5=88=92=E7=BB=84=E6=97=B6=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E5=AF=B9=E7=BB=84=E5=86=85=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E8=BF=9B=E8=A1=8C=E4=B8=B2=E8=A1=8C/?= =?UTF-8?q?=E5=B9=B6=E8=A1=8C=E6=89=A7=E8=A1=8C=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/controller/TestPlanController.java | 7 +-- .../plan/service/TestPlanExecuteService.java | 44 +++++++------------ .../plan/service/TestPlanReportService.java | 5 ++- .../plan/service/TestPlanService.java | 11 +++-- 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanController.java index 8c2a9a05b7..902892f534 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanController.java @@ -168,9 +168,10 @@ public class TestPlanController { @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ADD) @CheckOwner(resourceId = "#id", resourceType = "test_plan") public TestPlanOperationResponse copy(@PathVariable String id) { - return new TestPlanOperationResponse( - testPlanService.copy(id, SessionUtils.getUserId()) - ); + long copyCount = testPlanService.copy(id, SessionUtils.getUserId()); + //copy完成之后的刷新一下状态 + testPlanService.refreshTestPlanStatus(id); + return new TestPlanOperationResponse(copyCount); } @PostMapping("/batch-copy") 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 0c1547a41c..d34755de00 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 @@ -29,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.concurrent.TimeUnit; import static io.metersphere.plan.service.TestPlanExecuteSupportService.*; @@ -138,37 +137,27 @@ public class TestPlanExecuteService { */ @Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED) public String singleExecuteTestPlan(TestPlanExecuteRequest request, String userId) { - TestPlanExecutionQueue executionQueue = new TestPlanExecutionQueue(); - executionQueue.setSourceID(request.getExecuteId()); - executionQueue.setRunMode(ApiBatchRunMode.PARALLEL.name()); - executionQueue.setExecutionSource(request.getExecutionSource()); - executionQueue.setQueueId(IDGenerator.nextStr()); - executionQueue.setQueueType(QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE); - executionQueue.setCreateUser(userId); - executionQueue.setPrepareReportId(IDGenerator.nextStr()); + String queueId = IDGenerator.nextStr(); TestPlanExecutionQueue singleExecuteRootQueue = new TestPlanExecutionQueue( 0, userId, System.currentTimeMillis(), - executionQueue.getQueueId(), + queueId, QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE, - executionQueue.getQueueId(), - executionQueue.getQueueType(), + null, + null, request.getExecuteId(), - executionQueue.getRunMode(), - executionQueue.getExecutionSource(), + request.getRunMode(), + request.getExecutionSource(), IDGenerator.nextStr() ); - String redisKey = testPlanExecuteSupportService.genQueueKey(executionQueue.getQueueId(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE); - redisTemplate.opsForList().rightPush(redisKey, JSON.toJSONString(singleExecuteRootQueue)); - redisTemplate.expire(redisKey, 1, TimeUnit.DAYS); - + testPlanExecuteSupportService.setRedisForList( + testPlanExecuteSupportService.genQueueKey(queueId, QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE), List.of(JSON.toJSONString(singleExecuteRootQueue))); + TestPlanExecutionQueue nextQueue = testPlanExecuteSupportService.getNextQueue(queueId, QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE); LogUtils.info("测试计划(组)的单独执行start!计划报告[{}] , 资源ID[{}]", singleExecuteRootQueue.getPrepareReportId(), singleExecuteRootQueue.getSourceID()); - - String returnId = executeTestPlanOrGroup(executionQueue); - return returnId; + return executeTestPlanOrGroup(nextQueue); } /** @@ -235,7 +224,6 @@ public class TestPlanExecuteService { genReportRequest.setProjectId(testPlan.getProjectId()); if (StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { //更改测试计划组的状态 - testPlanService.setExecuteConfig(executionQueue.getSourceID()); List children = testPlanService.selectNotArchivedChildren(testPlan.getId()); // 预生成计划组报告 Map reportMap = testPlanReportService.genReportByExecution(executionQueue.getPrepareReportId(), genReportRequest, executionQueue.getCreateUser()); @@ -264,6 +252,7 @@ public class TestPlanExecuteService { LogUtils.info("计划组的执行节点 --- 队列ID[{}],队列类型[{}],父队列ID[{}],父队列类型[{}]", queueId, queueType, executionQueue.getParentQueueId(), executionQueue.getParentQueueType()); + testPlanService.setExecuteConfig(executionQueue.getSourceID(), executionQueue.getPrepareReportId()); if (CollectionUtils.isEmpty(childrenQueue)) { //本次的测试计划组执行完成 this.testPlanGroupQueueFinish(executionQueue.getQueueId(), executionQueue.getQueueType()); @@ -273,14 +262,12 @@ public class TestPlanExecuteService { if (StringUtils.equalsIgnoreCase(executionQueue.getRunMode(), ApiBatchRunMode.SERIAL.name())) { //串行 TestPlanExecutionQueue nextQueue = testPlanExecuteSupportService.getNextQueue(queueId, queueType); - testPlanReportService.updateExecuteTimeAndStatus(nextQueue.getPrepareReportId()); - testPlanService.setExecuteConfig(nextQueue.getSourceID()); + testPlanService.setExecuteConfig(nextQueue.getSourceID(), nextQueue.getPrepareReportId()); executeTestPlan(nextQueue); } else { //并行 childrenQueue.forEach(childQueue -> { - testPlanReportService.updateExecuteTimeAndStatus(childQueue.getPrepareReportId()); - testPlanService.setExecuteConfig(childQueue.getSourceID()); + testPlanService.setExecuteConfig(childQueue.getSourceID(), childQueue.getPrepareReportId()); executeTestPlan(childQueue); }); } @@ -290,8 +277,7 @@ public class TestPlanExecuteService { } else { Map reportMap = testPlanReportService.genReportByExecution(executionQueue.getPrepareReportId(), genReportRequest, executionQueue.getCreateUser()); executionQueue.setPrepareReportId(reportMap.get(executionQueue.getSourceID())); - testPlanReportService.updateExecuteTimeAndStatus(executionQueue.getPrepareReportId()); - testPlanService.setExecuteConfig(executionQueue.getSourceID()); + testPlanService.setExecuteConfig(executionQueue.getSourceID(), executionQueue.getPrepareReportId()); this.executeTestPlan(executionQueue); return executionQueue.getPrepareReportId(); } @@ -570,6 +556,8 @@ public class TestPlanExecuteService { if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE)) { this.executeTestPlanOrGroup(queue); } else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_GROUP_EXECUTE)) { + //执行下一个测试计划之前,将要修改的数据修改一下 + testPlanService.setExecuteConfig(queue.getSourceID(), queue.getPrepareReportId()); this.executeTestPlan(queue); } else if (StringUtils.equalsIgnoreCase(queue.getQueueType(), QUEUE_PREFIX_TEST_PLAN_CASE_TYPE)) { this.executeByTestPlanCollection(queue); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index 504717a2a8..f5bd667b89 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -254,6 +254,10 @@ public class TestPlanReportService { plans.forEach(plan -> { request.setTestPlanId(plan.getId()); TestPlanReportGenPreParam genPreParam = buildReportGenParam(request, plan, prepareReportId); + if (!manual) { + //不是手动保存的测试计划报告,不存储startTime + genPreParam.setStartTime(null); + } genPreParam.setUseManual(manual); //如果是测试计划的独立报告,使用参数中的预生成的报告id。否则只有测试计划组报告使用该id String prepareItemReportId = isGroupReports ? IDGenerator.nextStr() : prepareReportId; @@ -983,7 +987,6 @@ public class TestPlanReportService { return extTestPlanReportMapper.getPlanReportListById(request); } - @Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED) public void updateExecuteTimeAndStatus(String prepareReportId) { extTestPlanReportMapper.batchUpdateExecuteTimeAndStatus(System.currentTimeMillis(), Collections.singletonList(prepareReportId)); } 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 c770182b1f..ee81ab47c6 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 @@ -103,6 +103,8 @@ public class TestPlanService extends TestPlanBaseUtilsService { private static final int MAX_TAG_SIZE = 10; private static final int MAX_CHILDREN_COUNT = 20; + @Autowired + private TestPlanReportService testPlanReportService; /** * 创建测试计划 @@ -1060,8 +1062,11 @@ public class TestPlanService extends TestPlanBaseUtilsService { } @Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED) - public void setExecuteConfig(String sourceID) { - this.setActualStartTime(sourceID); - this.setTestPlanUnderway(sourceID); + public void setExecuteConfig(String testPlanId, String testPlanReportId) { + this.setActualStartTime(testPlanId); + this.setTestPlanUnderway(testPlanId); + if (StringUtils.isNotBlank(testPlanReportId)) { + testPlanReportService.updateExecuteTimeAndStatus(testPlanReportId); + } } }