From f0f3f69b7ad0bbfd82a1a68a5956481ba70bdf6f Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Fri, 21 Jun 2024 16:17:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E6=B8=B8=E7=A6=BB=E6=80=81=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E7=BB=84?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E5=8A=9F=E8=83=BD=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migration/3.1.0/dml/V3.1.0_2_1__data.sql | 43 +++ .../project/service/MoveNodeService.java | 6 + .../controller/TestPlanApiCaseController.java | 2 - .../TestPlanApiScenarioController.java | 2 - .../plan/controller/TestPlanController.java | 25 +- .../TestPlanFunctionalCaseController.java | 4 - .../TestPlanSingleOperationResponse.java | 14 + .../plan/mapper/ExtTestPlanMapper.java | 2 + .../plan/mapper/ExtTestPlanMapper.xml | 8 +- .../TestPlanApiCaseBatchRunService.java | 1 - .../plan/service/TestPlanApiCaseService.java | 1 - .../TestPlanApiScenarioBatchRunService.java | 1 - .../service/TestPlanApiScenarioService.java | 1 - .../service/TestPlanBaseUtilsService.java | 68 ----- .../TestPlanBatchOperationService.java | 10 +- .../plan/service/TestPlanCaseService.java | 110 -------- .../TestPlanCollectionMinderService.java | 2 - .../TestPlanExecuteSupportService.java | 7 - .../plan/service/TestPlanGroupService.java | 57 ++-- .../service/TestPlanManagementService.java | 4 +- .../plan/service/TestPlanService.java | 247 +++++++---------- .../plan/controller/TestPlanTests.java | 252 ++++++------------ .../plan/service/TestPlanTestService.java | 8 + 23 files changed, 299 insertions(+), 576 deletions(-) create mode 100644 backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanSingleOperationResponse.java delete mode 100644 backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanCaseService.java diff --git a/backend/framework/domain/src/main/resources/migration/3.1.0/dml/V3.1.0_2_1__data.sql b/backend/framework/domain/src/main/resources/migration/3.1.0/dml/V3.1.0_2_1__data.sql index 85112d68ab..2c2ff176d8 100644 --- a/backend/framework/domain/src/main/resources/migration/3.1.0/dml/V3.1.0_2_1__data.sql +++ b/backend/framework/domain/src/main/resources/migration/3.1.0/dml/V3.1.0_2_1__data.sql @@ -3,6 +3,49 @@ SET SESSION innodb_lock_wait_timeout = 7200; DROP TABLE IF EXISTS functional_minder_extra_node; +-- 清洗测试计划表的pos数据 +DROP PROCEDURE IF EXISTS UpdatePosForNoneGroup; +DELIMITER +$$ +CREATE PROCEDURE UpdatePosForNoneGroup() +BEGIN + #声明结束标识 + DECLARE done INT DEFAULT FALSE; + DECLARE testPlanUpdateId varchar(50); + DECLARE testPlanProjectId varchar(50); + DECLARE lastProjectId varchar(50) default ''; + DECLARE current_pos INT DEFAULT 4096; + DECLARE updateRow CURSOR FOR SELECT id, project_id + FROM test_plan + WHERE `group_id` = 'none' + ORDER BY project_id ASC, num ASC; + #设置终止标志 + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + #打开游标 + OPEN updateRow; + #获取当前游标指针记录,取出值赋给自定义的变量 + FETCH updateRow INTO testPlanUpdateId,testPlanProjectId; + #遍历游标 + REPEAT + #判断是否是同一个项目 + IF testPlanProjectId != lastProjectId THEN + SET current_pos = 4096; + SET lastProjectId = testPlanProjectId; + END IF; + #利用取到的值进行数据库的操作 + update test_plan set pos = current_pos where id = testPlanUpdateId; + # 将游标中的值再赋值给变量,供下次循环使用 + FETCH updateRow INTO testPlanUpdateId,testPlanProjectId; + SET current_pos = current_pos + 4096; + UNTIL done END REPEAT; + #关闭游标 + CLOSE updateRow; +END +$$ +DELIMITER ; +CALL UpdatePosForNoneGroup(); +DROP PROCEDURE IF EXISTS UpdatePosForNoneGroup; +-- 清洗测试计划表的pos数据结束 -- set innodb lock wait timeout to default SET SESSION innodb_lock_wait_timeout = DEFAULT; \ No newline at end of file diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/MoveNodeService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/MoveNodeService.java index 6c20f75369..91cd2ea5f1 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/MoveNodeService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/MoveNodeService.java @@ -91,6 +91,12 @@ public abstract class MoveNodeService { return new MoveNodeSortDTO(sortRangeId, dragNode, previousNode, nextNode); } + //判断是否存在需要提前排序的异常数据 + public boolean needRefreshBeforeSort(DropNode previousNode, DropNode nextNode) { + long previousPos = previousNode == null ? -1 : previousNode.getPos(); + long nextPos = nextNode == null ? -1 : nextNode.getPos(); + return nextPos - previousPos <= 1 || previousPos == 0 || nextPos == 0; + } //排序 public void sort(MoveNodeSortDTO sortDTO) { // 获取相邻节点 diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java index 99bf62b8eb..b89c568918 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java @@ -95,7 +95,6 @@ public class TestPlanApiCaseController { batchRequest.setTestPlanId(request.getTestPlanId()); batchRequest.setSelectIds(List.of(request.getId())); TestPlanAssociationResponse response = testPlanApiCaseService.disassociate(batchRequest, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/case/disassociate", HttpMethodConstants.POST.name())); - testPlanService.refreshTestPlanStatus(request.getTestPlanId()); return response; } @@ -109,7 +108,6 @@ public class TestPlanApiCaseController { return new TestPlanAssociationResponse(); } TestPlanAssociationResponse response = testPlanApiCaseService.disassociate(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/case/batch/disassociate", HttpMethodConstants.POST.name())); - testPlanService.refreshTestPlanStatus(request.getTestPlanId()); return response; } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiScenarioController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiScenarioController.java index 7a1e53a37f..f654e8551a 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiScenarioController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiScenarioController.java @@ -101,7 +101,6 @@ public class TestPlanApiScenarioController { batchRequest.setTestPlanId(request.getTestPlanId()); batchRequest.setSelectIds(List.of(request.getId())); TestPlanAssociationResponse response = testPlanApiScenarioService.disassociate(batchRequest, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/scenario/disassociate", HttpMethodConstants.POST.name())); - testPlanService.refreshTestPlanStatus(request.getTestPlanId()); return response; } @@ -112,7 +111,6 @@ public class TestPlanApiScenarioController { @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") public TestPlanAssociationResponse batchDisassociate(@Validated @RequestBody BasePlanCaseBatchRequest request) { TestPlanAssociationResponse response = testPlanApiScenarioService.disassociate(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/scenario/batch/disassociate", HttpMethodConstants.POST.name())); - testPlanService.refreshTestPlanStatus(request.getTestPlanId()); return response; } 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 2d1346c6b2..8fff6527be 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 @@ -6,10 +6,7 @@ import io.metersphere.plan.constants.TestPlanResourceConfig; import io.metersphere.plan.domain.TestPlan; import io.metersphere.plan.dto.TestPlanExecuteHisDTO; import io.metersphere.plan.dto.request.*; -import io.metersphere.plan.dto.response.TestPlanDetailResponse; -import io.metersphere.plan.dto.response.TestPlanOperationResponse; -import io.metersphere.plan.dto.response.TestPlanResponse; -import io.metersphere.plan.dto.response.TestPlanStatisticsResponse; +import io.metersphere.plan.dto.response.*; import io.metersphere.plan.service.*; import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.constants.PermissionConstants; @@ -168,11 +165,8 @@ public class TestPlanController { @Operation(summary = "测试计划-复制测试计划") @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ADD) @CheckOwner(resourceId = "#id", resourceType = "test_plan") - public TestPlanOperationResponse copy(@PathVariable String id) { - long copyCount = testPlanService.copy(id, SessionUtils.getUserId()); - //copy完成之后的刷新一下状态 - testPlanService.refreshTestPlanStatus(id); - return new TestPlanOperationResponse(copyCount); + public TestPlanSingleOperationResponse copy(@PathVariable String id) { + return new TestPlanSingleOperationResponse(testPlanService.copy(id, SessionUtils.getUserId())); } @PostMapping("/batch-copy") @@ -208,17 +202,6 @@ public class TestPlanController { testPlanService.batchArchived(request, SessionUtils.getUserId()); } - @PostMapping(value = "/association") - @Operation(summary = "测试计划功能用例-关联功能用例") - @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ASSOCIATION) - @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") - public void association(@Validated @RequestBody TestPlanAssociationRequest request) { - testPlanManagementService.checkModuleIsOpen(request.getTestPlanId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_FUNCTIONAL_CASE)); - testPlanService.checkTestPlanNotArchived(request.getTestPlanId()); - testPlanService.association(request, SessionUtils.getUserId()); - testPlanService.refreshTestPlanStatus(request.getTestPlanId()); - } - @PostMapping("/batch-edit") @Operation(summary = "测试计划-批量编辑") @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @@ -236,7 +219,7 @@ public class TestPlanController { @CheckOwner(resourceId = "#request.getMoveId()", resourceType = "test_plan") public TestPlanOperationResponse sortTestPlan(@Validated @RequestBody PosRequest request) { testPlanManagementService.checkModuleIsOpen(request.getMoveId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN)); - return testPlanService.sortInGroup(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/move", HttpMethodConstants.POST.name())); + return testPlanService.sort(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/sort", HttpMethodConstants.POST.name())); } @PostMapping(value = "/schedule-config") 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 09828fba42..dbf0b70b40 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 @@ -97,7 +97,6 @@ public class TestPlanFunctionalCaseController { batchRequest.setTestPlanId(request.getTestPlanId()); batchRequest.setSelectIds(List.of(request.getId())); TestPlanAssociationResponse response = testPlanFunctionalCaseService.disassociate(batchRequest, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/disassociate", HttpMethodConstants.POST.name())); - testPlanService.refreshTestPlanStatus(request.getTestPlanId()); return response; } @@ -108,7 +107,6 @@ public class TestPlanFunctionalCaseController { public TestPlanAssociationResponse batchDisassociate(@Validated @RequestBody BasePlanCaseBatchRequest request) { testPlanManagementService.checkModuleIsOpen(request.getTestPlanId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_FUNCTIONAL_CASE)); TestPlanAssociationResponse response = testPlanFunctionalCaseService.disassociate(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/batch/disassociate", HttpMethodConstants.POST.name())); - testPlanService.refreshTestPlanStatus(request.getTestPlanId()); return response; } @@ -144,7 +142,6 @@ public class TestPlanFunctionalCaseController { public void run(@Validated @RequestBody TestPlanCaseRunRequest request) { testPlanFunctionalCaseService.run(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/run", HttpMethodConstants.POST.name())); testPlanService.setActualStartTime(request.getTestPlanId()); - testPlanService.refreshTestPlanStatus(request.getTestPlanId()); } @PostMapping("/batch/run") @@ -154,7 +151,6 @@ public class TestPlanFunctionalCaseController { public void batchRun(@Validated @RequestBody TestPlanCaseBatchRunRequest request) { testPlanFunctionalCaseService.batchRun(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/batch/run", HttpMethodConstants.POST.name())); testPlanService.setActualStartTime(request.getTestPlanId()); - testPlanService.refreshTestPlanStatus(request.getTestPlanId()); } @PostMapping("/has/associate/bug/page") diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanSingleOperationResponse.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanSingleOperationResponse.java new file mode 100644 index 0000000000..0fb78ab928 --- /dev/null +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanSingleOperationResponse.java @@ -0,0 +1,14 @@ +package io.metersphere.plan.dto.response; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TestPlanSingleOperationResponse { + @Schema(description = "处理成功的ID") + private String operationId; +} diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.java index 585a1b838c..7eaaeb98b5 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.java @@ -57,6 +57,8 @@ public interface ExtTestPlanMapper { long selectMaxPosByGroupId(String groupId); + long selectMaxPosByProjectIdAndGroupId(@Param("projectId") String projectId, @Param("groupId") String groupId); + List selectByGroupIds(@Param("groupIds") List groupIds); List selectRightfulIdsForExecute(@Param("ids") List ids); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.xml index c7d0cc48c1..f2dec530c2 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.xml @@ -87,7 +87,7 @@ #{groupId} - ORDER BY t.pos ASC + ORDER BY t.pos DESC @@ -452,6 +452,12 @@ FROM test_plan WHERE group_id = #{0} +