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 167996aad8..b765b69d70 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 @@ -54,6 +54,15 @@ public class TestPlanController { return testPlanManagementService.page(request); } + @GetMapping("/list-in-group/{groupId}") + @Operation(summary = "测试计划-表格分页查询") + @RequiresPermissions(PermissionConstants.TEST_PLAN_READ) + @CheckOwner(resourceId = "#groupId", resourceType = "test_plan") + public List listInGroup(@NotBlank @PathVariable String groupId) { + testPlanManagementService.checkModuleIsOpen(groupId, TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN)); + return testPlanManagementService.selectByGroupId(groupId); + } + @PostMapping("/statistics") @Operation(summary = "测试计划-获取计划详情统计{通过率, 执行进度}") @RequiresPermissions(PermissionConstants.TEST_PLAN_READ) diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanResponse.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanResponse.java index 051fe3af33..5c6783ae02 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanResponse.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/response/TestPlanResponse.java @@ -41,4 +41,6 @@ public class TestPlanResponse extends TestPlanStatisticsResponse { @Schema(description = "描述") private String description; + + private long pos; } 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 c776d1e403..71c8145926 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 @@ -13,11 +13,11 @@ import org.apache.ibatis.annotations.Param; import java.util.List; public interface ExtTestPlanMapper { - List selectByGroupId(String parentId); + List selectIdByGroupId(String parentId); List selectByGroupIdList(@Param("list") List parentTestPlanId); - List selectByConditions(@Param("request") TestPlanTableRequest request,@Param("groupIds") List groupIds); + List selectByConditions(@Param("request") TestPlanTableRequest request); List selectIdByConditions(@Param("request") TestPlanBatchProcessRequest request); @@ -48,4 +48,6 @@ public interface ExtTestPlanMapper { DropNode selectNodeByPosOperator(NodeSortQueryParam nodeSortQueryParam); long selectMaxPosByGroupId(String groupId); + + List selectByGroupIds(@Param("groupIds") List groupIds); } 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 773d501ce0..60037fd661 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 @@ -32,7 +32,7 @@ - SELECT id FROM test_plan WHERE group_id = #{parentId} + + - - - and t.module_id in - - #{moduleId} - - + + and ( t.name like concat('%', #{request.keyword},'%') @@ -96,9 +105,6 @@ - - - AND @@ -109,6 +115,10 @@ ) + + + + @@ -249,7 +259,7 @@ FROM test_plan t INNER JOIN user createUser ON t.create_user = createUser.id WHERE t.project_id = #{request.projectId} - + GROUP BY t.module_id - - + and t.module_id in #{moduleId} - - and ( - t.name like concat('%', #{request.condition.keyword},'%') - or t.num like concat('%', #{request.condition.keyword},'%') - or t.tags like concat('%', #{request.condition.keyword}, '%') - ) - @@ -287,13 +289,20 @@ and t.group_id = 'NONE' - and t.type = 'GTOUP' + and t.type = 'GROUP' - - - + + + + + and ( + t.name like concat('%', #{request.condition.keyword},'%') + or t.num like concat('%', #{request.condition.keyword},'%') + or t.tags like concat('%', #{request.condition.keyword}, '%') + ) + AND @@ -304,6 +313,9 @@ ) + + + diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanManagementService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanManagementService.java index 1aa2d1efcd..c1623cfbca 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanManagementService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanManagementService.java @@ -17,6 +17,7 @@ import io.metersphere.sdk.util.Translator; import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.Pager; import jakarta.annotation.Resource; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -63,8 +64,8 @@ public class TestPlanManagementService { } private List getTableList(TestPlanTableRequest request) { - List testPlanResponses = extTestPlanMapper.selectByConditions(request, null); - handChildren(testPlanResponses, request.getProjectId()); + List testPlanResponses = extTestPlanMapper.selectByConditions(request); + handChildren(testPlanResponses,request.getProjectId()); return testPlanResponses; } @@ -73,20 +74,20 @@ public class TestPlanManagementService { */ private void handChildren(List testPlanResponses, String projectId) { List groupIds = testPlanResponses.stream().filter(item -> StringUtils.equals(item.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)).map(TestPlanResponse::getId).toList(); - TestPlanTableRequest request = new TestPlanTableRequest(); - request.setProjectId(projectId); - List childrenList = extTestPlanMapper.selectByConditions(request, groupIds); - Map> collect = childrenList.stream().collect(Collectors.groupingBy(TestPlanResponse::getGroupId)); - testPlanResponses.forEach(item -> { - if (collect.containsKey(item.getId())) { - //存在子节点 - List list = collect.get(item.getId()); - testPlanStatisticsService.calculateCaseCount(list); - item.setChildren(list); - item.setChildrenCount(list.size()); - } - testPlanStatisticsService.calculateCaseCount(List.of(item)); - }); + if (CollectionUtils.isNotEmpty(groupIds)) { + List childrenList = extTestPlanMapper.selectByGroupIds(groupIds); + Map> collect = childrenList.stream().collect(Collectors.groupingBy(TestPlanResponse::getGroupId)); + testPlanResponses.forEach(item -> { + if (collect.containsKey(item.getId())) { + //存在子节点 + List list = collect.get(item.getId()); + testPlanStatisticsService.calculateCaseCount(list); + item.setChildren(list); + item.setChildrenCount(list.size()); + } + testPlanStatisticsService.calculateCaseCount(List.of(item)); + }); + } } public void checkModuleIsOpen(String resourceId, String resourceType, List moduleMenus) { @@ -111,6 +112,10 @@ public class TestPlanManagementService { } } + public List selectByGroupId(String groupId) { + return extTestPlanMapper.selectByGroupIds(List.of(groupId)); + } + /** * 根据项目id检查模块是否开启 diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java index 0757af9288..1f8c4baca2 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java @@ -7,6 +7,7 @@ import io.metersphere.plan.constants.TestPlanResourceConfig; import io.metersphere.plan.domain.*; import io.metersphere.plan.dto.request.*; import io.metersphere.plan.dto.response.TestPlanResourceSortResponse; +import io.metersphere.plan.dto.response.TestPlanResponse; import io.metersphere.plan.mapper.ExtTestPlanMapper; import io.metersphere.plan.mapper.TestPlanMapper; import io.metersphere.plan.mapper.TestPlanReportMapper; @@ -15,6 +16,7 @@ import io.metersphere.plan.utils.TestPlanTestUtils; import io.metersphere.project.domain.Project; import io.metersphere.project.dto.filemanagement.request.FileModuleCreateRequest; import io.metersphere.project.dto.filemanagement.request.FileModuleUpdateRequest; +import io.metersphere.project.utils.NodeSortUtils; import io.metersphere.sdk.constants.*; import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.CommonBeanFactory; @@ -107,6 +109,7 @@ public class TestPlanTests extends BaseTest { private static final String URL_POST_TEST_PLAN_PAGE = "/test-plan/page"; private static final String URL_POST_TEST_PLAN_STATISTICS = "/test-plan/statistics"; private static final String URL_POST_TEST_PLAN_MODULE_COUNT = "/test-plan/module/count"; + private static final String URL_GET_TEST_PLAN_LIST_IN_GROUP = "/test-plan/list-in-group/%s"; private static final String URL_POST_TEST_PLAN_ADD = "/test-plan/add"; private static final String URL_POST_TEST_PLAN_SORT = "/test-plan/sort"; private static final String URL_POST_TEST_PLAN_UPDATE = "/test-plan/update"; @@ -687,7 +690,16 @@ public class TestPlanTests extends BaseTest { this.checkTestPlanSortInGroup(groupTestPlanId7); } - protected void checkTestPlanSortInGroup(String groupTestPlanId7) throws Exception { + private List selectByGroupId(String groupId) throws Exception { + return JSON.parseArray( + JSON.toJSONString( + JSON.parseObject( + this.requestGetWithOkAndReturn(String.format(URL_GET_TEST_PLAN_LIST_IN_GROUP, groupId)) + .getResponse().getContentAsString(), ResultHolder.class).getData()), + TestPlanResponse.class); + } + + protected void checkTestPlanSortInGroup(String groupId) throws Exception { /* 排序校验用例设计: 1.第一个移动到最后一个。 @@ -695,13 +707,9 @@ public class TestPlanTests extends BaseTest { 3.第三个移动到第二个 4.修改第一个和第二个之间的pos差小于2,将第三个移动到第二个(还原为原来的顺序),并检查pos有没有初始化 */ - - TestPlanExample example = new TestPlanExample(); - example.createCriteria().andGroupIdEqualTo(groupTestPlanId7); - example.setOrderByClause("pos asc"); - List defaultTestPlanInGroup = testPlanMapper.selectByExample(example); - List lastTestPlanInGroup = defaultTestPlanInGroup; - TestPlan movePlan, targetPlan = null; + List defaultTestPlanInGroup = this.selectByGroupId(groupId); + List lastTestPlanInGroup = defaultTestPlanInGroup; + TestPlanResponse movePlan, targetPlan = null; PosRequest posRequest = null; TestPlanResourceSortResponse response = null; @@ -716,7 +724,7 @@ public class TestPlanTests extends BaseTest { .getResponse().getContentAsString(), ResultHolder.class).getData()), TestPlanResourceSortResponse.class); //位置校验 - List newTestPlanInGroup = testPlanMapper.selectByExample(example); + List newTestPlanInGroup = this.selectByGroupId(groupId); Assertions.assertEquals(response.getSortNodeNum(), 1); Assertions.assertEquals(newTestPlanInGroup.size(), lastTestPlanInGroup.size()); for (int newListIndex = 0; newListIndex < newTestPlanInGroup.size(); newListIndex++) { @@ -736,7 +744,7 @@ public class TestPlanTests extends BaseTest { .getResponse().getContentAsString(), ResultHolder.class).getData()), TestPlanResourceSortResponse.class); //位置校验 - newTestPlanInGroup = testPlanMapper.selectByExample(example); + newTestPlanInGroup = this.selectByGroupId(groupId); Assertions.assertEquals(response.getSortNodeNum(), 1); Assertions.assertEquals(newTestPlanInGroup.size(), lastTestPlanInGroup.size()); for (int newListIndex = 0; newListIndex < newTestPlanInGroup.size(); newListIndex++) { @@ -755,7 +763,7 @@ public class TestPlanTests extends BaseTest { .getResponse().getContentAsString(), ResultHolder.class).getData()), TestPlanResourceSortResponse.class); //位置校验 - newTestPlanInGroup = testPlanMapper.selectByExample(example); + newTestPlanInGroup = this.selectByGroupId(groupId); Assertions.assertEquals(response.getSortNodeNum(), 1); Assertions.assertEquals(newTestPlanInGroup.size(), lastTestPlanInGroup.size()); for (int newListIndex = 0; newListIndex < newTestPlanInGroup.size(); newListIndex++) { @@ -772,8 +780,10 @@ public class TestPlanTests extends BaseTest { // 修改第一个和第二个之间的pos差为2(拖拽的最小pos差),将第三个移动到第二个(换回来),然后检查pos有没有变化 movePlan = lastTestPlanInGroup.get(2); targetPlan = lastTestPlanInGroup.get(1); - targetPlan.setPos(lastTestPlanInGroup.get(0).getPos() + 2); - testPlanMapper.updateByPrimaryKey(targetPlan); + TestPlan updatePlan = new TestPlan(); + updatePlan.setId(targetPlan.getId()); + updatePlan.setPos(lastTestPlanInGroup.get(0).getPos() + 2); + testPlanMapper.updateByPrimaryKeySelective(updatePlan); posRequest = new PosRequest(project.getId(), movePlan.getId(), targetPlan.getId(), MoveTypeEnum.BEFORE.name()); response = JSON.parseObject( @@ -783,13 +793,13 @@ public class TestPlanTests extends BaseTest { .getResponse().getContentAsString(), ResultHolder.class).getData()), TestPlanResourceSortResponse.class); //位置校验 - newTestPlanInGroup = testPlanMapper.selectByExample(example); + newTestPlanInGroup = this.selectByGroupId(groupId); Assertions.assertEquals(response.getSortNodeNum(), 1); Assertions.assertEquals(newTestPlanInGroup.size(), lastTestPlanInGroup.size()); long lastPos = 0; for (int newListIndex = 0; newListIndex < newTestPlanInGroup.size(); newListIndex++) { Assertions.assertEquals(newTestPlanInGroup.get(newListIndex).getId(), defaultTestPlanInGroup.get(newListIndex).getId()); - Assertions.assertTrue(newTestPlanInGroup.get(newListIndex).getPos() > (lastPos + 1)); + Assertions.assertTrue(newTestPlanInGroup.get(newListIndex).getPos() == (lastPos + NodeSortUtils.DEFAULT_NODE_INTERVAL_POS)); lastPos = newTestPlanInGroup.get(newListIndex).getPos(); } } @@ -847,11 +857,13 @@ public class TestPlanTests extends BaseTest { dataRequest.getCurrent(), dataRequest.getPageSize(), 1010); + //只查询组 testPlanTestService.checkTestPlanPage(this.requestPostWithOkAndReturn( URL_POST_TEST_PLAN_PAGE, groupRequest).getResponse().getContentAsString(StandardCharsets.UTF_8), dataRequest.getCurrent(), dataRequest.getPageSize(), 2); + //只查询计划 testPlanTestService.checkTestPlanPage(this.requestPostWithOkAndReturn( URL_POST_TEST_PLAN_PAGE, onlyPlanRequest).getResponse().getContentAsString(StandardCharsets.UTF_8), dataRequest.getCurrent(),