From 5c662aeb5c3d13780924bb7c6db9a07f5a35ae0d Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Wed, 10 Jul 2024 10:59:51 +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=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E5=A4=8D=E5=88=B6=E6=97=B6=E6=97=A5=E5=BF=97=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E8=AE=B0=E5=BD=95=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 --bug=1043150 --user=宋天阳 【测试计划】批量复制测试计划-日志生成的名称是复制前的名称 https://www.tapd.cn/55049933/s/1546084 --- .../controller/TestPlanExecuteController.java | 7 ++++- .../plan/job/TestPlanScheduleJob.java | 3 +- .../TestPlanBatchOperationService.java | 15 +++++----- .../plan/service/TestPlanExecuteService.java | 6 +--- .../plan/service/TestPlanGroupService.java | 30 +++++++++---------- .../plan/service/TestPlanLogService.java | 3 +- .../plan/service/TestPlanService.java | 19 ++++++------ .../plan/controller/TestPlanExecuteTests.java | 6 +--- 8 files changed, 43 insertions(+), 46 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 f23f02810a..c9946599b6 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 @@ -10,6 +10,7 @@ import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.security.CheckOwner; +import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.utils.SessionUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -41,7 +42,11 @@ public class TestPlanExecuteController { @Log(type = OperationLogType.EXECUTE, expression = "#msClass.executeLog(#request)", msClass = TestPlanLogService.class) public String startExecute(@Validated @RequestBody TestPlanExecuteRequest request) { testPlanManagementService.checkModuleIsOpen(request.getExecuteId(), TestPlanResourceConfig.CONFIG_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN)); - return testPlanExecuteService.singleExecuteTestPlan(request, SessionUtils.getUserId()); + String reportId = IDGenerator.nextStr(); + Thread.startVirtualThread(() -> + testPlanExecuteService.singleExecuteTestPlan(request, reportId, SessionUtils.getUserId()) + ); + return reportId; } @PostMapping("/batch") 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 cc62357d9c..b5664cacb6 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 @@ -8,6 +8,7 @@ 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 io.metersphere.system.uid.IDGenerator; import org.quartz.JobExecutionContext; import org.quartz.JobKey; import org.quartz.TriggerKey; @@ -28,7 +29,7 @@ public class TestPlanScheduleJob extends BaseScheduleJob { this.setExecuteId(resourceId); this.setRunMode(runMode); this.setExecutionSource(ApiExecuteRunMode.SCHEDULE.name()); - }}, userId) + }}, IDGenerator.nextStr(), 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 6b44bee46e..4daa7a965a 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 @@ -125,27 +125,26 @@ public class TestPlanBatchOperationService extends TestPlanBaseUtilsService { } - public long batchCopy(List copyPlanList, String targetId, String targetType, String userId) { - long copyCount = 0; + public List batchCopy(List originalPlanList, String targetId, String targetType, String userId) { + List copyPlanResult = new ArrayList<>(); long operatorTime = System.currentTimeMillis(); //如果目标ID是测试计划组, 需要进行容量校验 if (!StringUtils.equalsIgnoreCase(targetType, ModuleConstants.NODE_TYPE_DEFAULT)) { - testPlanGroupService.validateGroupCapacity(targetId, copyPlanList.size()); + testPlanGroupService.validateGroupCapacity(targetId, originalPlanList.size()); } /* 此处不进行批量处理,原因有两点: 1) 测试计划内(或者测试计划组内)数据量不可控,选择批量操作时更容易出现数据太多不走索引、数据太多内存溢出等问题。不批量操作可以减少这些问题出现的概率,代价是速度会变慢。 2) 作为数据量不可控的操作,如果数据量少,不采用批量处理也不会消耗太多时间。如果数据量多,就会容易出现1的问题。并且本人不建议针对不可控数据量的数据支持批量操作。 */ - for (TestPlan copyPlan : copyPlanList) { + for (TestPlan copyPlan : originalPlanList) { if (StringUtils.equalsIgnoreCase(copyPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { - this.copyPlanGroup(copyPlan, targetId, targetType, operatorTime, userId); + copyPlanResult.add(this.copyPlanGroup(copyPlan, targetId, targetType, operatorTime, userId)); } else { - this.copyPlan(copyPlan, targetId, targetType, operatorTime, userId); + copyPlanResult.add(this.copyPlan(copyPlan, targetId, targetType, operatorTime, userId)); } - copyCount++; } - return copyCount; + return copyPlanResult; } 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 7927b1652a..c2a0edce61 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 @@ -125,10 +125,7 @@ public class TestPlanExecuteService { * 这里涉及到嵌套查询,不使用事务。中间涉及到的报告生成、测试计划字段更改、测试报告汇总等操作会开启子事务处理。 */ @Transactional(rollbackFor = Exception.class, propagation = Propagation.NOT_SUPPORTED) - public String singleExecuteTestPlan(TestPlanExecuteRequest request, String userId) { - - String reportId = IDGenerator.nextStr(); - Thread.startVirtualThread(() -> { + public String singleExecuteTestPlan(TestPlanExecuteRequest request, String reportId, String userId) { String queueId = IDGenerator.nextStr(); TestPlanExecutionQueue singleExecuteRootQueue = new TestPlanExecutionQueue( 0, @@ -149,7 +146,6 @@ public class TestPlanExecuteService { TestPlanExecutionQueue nextQueue = testPlanExecuteSupportService.getNextQueue(queueId, QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE); LogUtils.info("测试计划(组)的单独执行start!计划报告[{}] , 资源ID[{}]", singleExecuteRootQueue.getPrepareReportId(), singleExecuteRootQueue.getSourceID()); executeTestPlanOrGroup(nextQueue); - }); return reportId; } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanGroupService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanGroupService.java index 2a5b5c5cb9..b7fa1c6387 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanGroupService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanGroupService.java @@ -107,24 +107,24 @@ public class TestPlanGroupService extends TestPlanSortService { } public TestPlan validateGroupCapacity(String groupId, int size) { - // 判断测试计划组是否存在 - TestPlan groupPlan = testPlanMapper.selectByPrimaryKey(groupId); - if (groupPlan == null) { - throw new MSException(Translator.get("test_plan.group.error")); - } + // 判断测试计划组是否存在 + TestPlan groupPlan = testPlanMapper.selectByPrimaryKey(groupId); + if (groupPlan == null) { + throw new MSException(Translator.get("test_plan.group.error")); + } if (!StringUtils.equalsIgnoreCase(groupPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) { throw new MSException(Translator.get("test_plan.group.error")); } - //判断并未归档 - if (StringUtils.equalsIgnoreCase(groupPlan.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED)) { - throw new MSException(Translator.get("test_plan.group.error")); - } - //判断测试计划组下的测试计划数量是否超过20 - TestPlanExample example = new TestPlanExample(); - example.createCriteria().andGroupIdEqualTo(groupId); - if (testPlanMapper.countByExample(example) + size > 20) { - throw new MSException(Translator.getWithArgs("test_plan.group.children.max", MAX_CHILDREN_COUNT)); - } + //判断并未归档 + if (StringUtils.equalsIgnoreCase(groupPlan.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED)) { + throw new MSException(Translator.get("test_plan.group.error")); + } + //判断测试计划组下的测试计划数量是否超过20 + TestPlanExample example = new TestPlanExample(); + example.createCriteria().andGroupIdEqualTo(groupId); + if (testPlanMapper.countByExample(example) + size > 20) { + throw new MSException(Translator.getWithArgs("test_plan.group.children.max", MAX_CHILDREN_COUNT)); + } return groupPlan; } } 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 216c976ffd..7d33ab9459 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 @@ -182,9 +182,8 @@ public class TestPlanLogService { * @param requestUrl 请求URL * @param requestMethod 请求方法 * @param requestType 请求类型 - * @param typeKey 类型Key */ - public void saveBatchLog(List plans, String operator, String requestUrl, String requestMethod, String requestType, String typeKey) { + public void saveBatchLog(List plans, String operator, String requestUrl, String requestMethod, String requestType) { if (CollectionUtils.isEmpty(plans)) { return; } 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 88dea33f66..46a25a6472 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 @@ -314,7 +314,7 @@ public class TestPlanService extends TestPlanBaseUtilsService { // 计划组的删除暂时预留 this.deleteGroupByList(testPlanGroupList); //记录日志 - testPlanLogService.saveBatchLog(deleteTestPlanList, operator, requestUrl, requestMethod, OperationLogType.DELETE.name(), "delete"); + testPlanLogService.saveBatchLog(deleteTestPlanList, operator, requestUrl, requestMethod, OperationLogType.DELETE.name()); } } } @@ -366,7 +366,7 @@ public class TestPlanService extends TestPlanBaseUtilsService { updateTestPlan.setPlannedEndTime(request.getPlannedEndTime()); updateTestPlan.setDescription(request.getDescription()); //判断有没有用户组的变化 - if (StringUtils.isNotBlank(request.getGroupId())) { + if (StringUtils.isNotBlank(request.getGroupId()) && !StringUtils.equalsIgnoreCase(request.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) { if (!StringUtils.equalsIgnoreCase(originalTestPlan.getGroupId(), request.getGroupId())) { //用户更换了测试计划组 TestPlan testPlanGroup = testPlanGroupService.validateGroupCapacity(request.getGroupId(), 1); @@ -518,7 +518,7 @@ public class TestPlanService extends TestPlanBaseUtilsService { } }); //日志 - testPlanLogService.saveBatchLog(archivedPlanGroupList, currentUser, "/test-plan/batch-archived", HttpMethodConstants.POST.name(), OperationLogType.ARCHIVED.name(), "archive"); + testPlanLogService.saveBatchLog(archivedPlanGroupList, currentUser, "/test-plan/batch-archived", HttpMethodConstants.POST.name(), OperationLogType.ARCHIVED.name()); } } @@ -666,15 +666,16 @@ public class TestPlanService extends TestPlanBaseUtilsService { if (CollectionUtils.isNotEmpty(copyIds)) { TestPlanExample example = new TestPlanExample(); example.createCriteria().andIdIn(copyIds); - List copyTestPlanList = testPlanMapper.selectByExample(example); + List originalTestPlanList = testPlanMapper.selectByExample(example); //批量复制时,不允许存在测试计划组下的测试计划。 - copyTestPlanList = copyTestPlanList.stream().filter(item -> StringUtils.equalsIgnoreCase(item.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) + originalTestPlanList = originalTestPlanList.stream().filter(item -> StringUtils.equalsIgnoreCase(item.getGroupId(), TestPlanConstants.TEST_PLAN_DEFAULT_GROUP_ID)) .collect(Collectors.toList()); //日志 - if (CollectionUtils.isNotEmpty(copyTestPlanList)) { - copyCount = testPlanBatchOperationService.batchCopy(copyTestPlanList, request.getTargetId(), request.getMoveType(), userId); - testPlanLogService.saveBatchLog(copyTestPlanList, userId, url, method, OperationLogType.ADD.name(), "copy"); + if (CollectionUtils.isNotEmpty(originalTestPlanList)) { + List copyPlanList = testPlanBatchOperationService.batchCopy(originalTestPlanList, request.getTargetId(), request.getMoveType(), userId); + copyCount = copyPlanList.size(); + testPlanLogService.saveBatchLog(copyPlanList, userId, url, method, OperationLogType.ADD.name()); } } @@ -713,7 +714,7 @@ public class TestPlanService extends TestPlanBaseUtilsService { } //日志 if (CollectionUtils.isNotEmpty(moveTestPlanList)) { - testPlanLogService.saveBatchLog(moveTestPlanList, userId, operationUrl, method, OperationLogType.UPDATE.name(), "update"); + testPlanLogService.saveBatchLog(moveTestPlanList, userId, operationUrl, method, OperationLogType.UPDATE.name()); } } return moveCount; 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 135fd74f93..7057da465b 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 @@ -48,8 +48,6 @@ public class TestPlanExecuteTests extends BaseTest { private static TestPlan allParallelGroup; private static TestPlan noGroupPlan; - private static final String URL_POST_TEST_PLAN_SINGLE_EXECUTE = "/test-plan-execute/single"; - @Resource private CommonProjectService commonProjectService; @Resource @@ -280,9 +278,7 @@ public class TestPlanExecuteTests extends BaseTest { executeRequest.setExecuteId(id); executeRequest.setRunMode(runMode); - this.requestPostWithOk(URL_POST_TEST_PLAN_SINGLE_EXECUTE, executeRequest); - - Thread.sleep(1000); + testPlanExecuteService.singleExecuteTestPlan(executeRequest, IDGenerator.nextStr(), "admin"); //检查队列 List allQueueIds = new ArrayList<>();