diff --git a/backend/services/dashboard/src/main/java/io/metersphere/dashboard/controller/ToDoController.java b/backend/services/dashboard/src/main/java/io/metersphere/dashboard/controller/ToDoController.java index 2e8c5b3ff4..e5d52dc73d 100644 --- a/backend/services/dashboard/src/main/java/io/metersphere/dashboard/controller/ToDoController.java +++ b/backend/services/dashboard/src/main/java/io/metersphere/dashboard/controller/ToDoController.java @@ -8,6 +8,9 @@ import io.metersphere.bug.service.BugService; import io.metersphere.functional.dto.CaseReviewDTO; import io.metersphere.functional.request.CaseReviewPageRequest; import io.metersphere.functional.service.CaseReviewService; +import io.metersphere.plan.dto.request.TestPlanTableRequest; +import io.metersphere.plan.dto.response.TestPlanResponse; +import io.metersphere.plan.service.TestPlanManagementService; import io.metersphere.system.security.CheckOwner; import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.Pager; @@ -37,6 +40,17 @@ public class ToDoController { private CaseReviewService caseReviewService; @Resource private BugService bugService; + @Resource + private TestPlanManagementService testPlanManagementService; + + @PostMapping("/plan/page") + @Operation(summary = "我的待办-测试计划-列表分页查询") + @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") + public Pager> planPage(@Validated @RequestBody TestPlanTableRequest request) { + request.setMyTodo(true); + request.setMyTodoUserId(SessionUtils.getUserId()); + return testPlanManagementService.page(request); + } @PostMapping("/review/page") @Operation(summary = "我的待办-用例评审-列表分页查询") diff --git a/backend/services/dashboard/src/test/java/io/metersphere/dashboard/controller/ToDoControllerTests.java b/backend/services/dashboard/src/test/java/io/metersphere/dashboard/controller/ToDoControllerTests.java index 8bbc291d9e..02c8d12f67 100644 --- a/backend/services/dashboard/src/test/java/io/metersphere/dashboard/controller/ToDoControllerTests.java +++ b/backend/services/dashboard/src/test/java/io/metersphere/dashboard/controller/ToDoControllerTests.java @@ -2,6 +2,7 @@ package io.metersphere.dashboard.controller; import io.metersphere.bug.dto.request.BugPageRequest; import io.metersphere.functional.request.CaseReviewPageRequest; +import io.metersphere.plan.dto.request.TestPlanTableRequest; import io.metersphere.system.base.BaseTest; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; @@ -17,6 +18,7 @@ import java.util.Map; @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class ToDoControllerTests extends BaseTest { + private static final String PLAN_PAGE = "/plan/page"; private static final String REVIEW_PAGE = "/review/page"; private static final String BUG_PAGE = "/bug/page"; @@ -25,6 +27,19 @@ public class ToDoControllerTests extends BaseTest { return "/dashboard/todo"; } + @Test + @Order(0) + void plan() throws Exception{ + TestPlanTableRequest request = new TestPlanTableRequest(); + request.setProjectId(DEFAULT_PROJECT_ID); + request.setCurrent(1); + request.setPageSize(10); + request.setType("ALL"); + this.requestPostWithOk(PLAN_PAGE, request); + request.setSort(Map.of("id", "desc")); + this.requestPostWithOk(PLAN_PAGE, request); + } + @Test @Order(1) void review() throws Exception{ diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanTableRequest.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanTableRequest.java index 12abdb2bdd..c739547dbd 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanTableRequest.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanTableRequest.java @@ -30,6 +30,15 @@ public class TestPlanTableRequest extends BasePageRequest { private List innerIds; private List combineInnerIds; + @Schema(description = "是否我的待办, 默认查询全部") + private boolean myTodo = false; + + @Schema(description = "我的待办用户ID, 组合使用: myTodo=true, myTodoUserId=xxx") + private String myTodoUserId; + + @Schema(description = "已办的测试计划ID集合 (用作待办排除)") + private List doneExcludeIds; + public String getSortString() { if (StringUtils.isEmpty(super.getSortString())) { return "t.update_time desc"; 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 a51742f79e..92b5fe7f15 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 @@ -91,7 +91,20 @@ - + + + and t.type = 'TEST_PLAN' + and t.create_user = #{request.myTodoUserId} + + and t.id not in + + #{id} + + + + + + and ( 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 dd4d6dcbb2..83665bfc2d 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 @@ -9,6 +9,7 @@ import io.metersphere.plan.dto.TestPlanGroupCountDTO; import io.metersphere.plan.dto.TestPlanResourceExecResultDTO; import io.metersphere.plan.dto.request.TestPlanTableRequest; import io.metersphere.plan.dto.response.TestPlanResponse; +import io.metersphere.plan.dto.response.TestPlanStatisticsResponse; import io.metersphere.plan.mapper.ExtTestPlanFunctionalCaseMapper; import io.metersphere.plan.mapper.ExtTestPlanMapper; import io.metersphere.plan.mapper.ExtTestPlanModuleMapper; @@ -73,6 +74,9 @@ public class TestPlanManagementService { * 测试计划列表查询 */ public Pager> page(TestPlanTableRequest request) { + if (request.isMyTodo()) { + request.setDoneExcludeIds(this.getDoneIds(request.getProjectId())); + } this.initDefaultFilter(request); Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), MapUtils.isEmpty(request.getSort()) ? "t.pos desc, t.id desc" : request.getSortString("id", "t")); @@ -311,4 +315,22 @@ public class TestPlanManagementService { } return false; } + + /** + * 获取已完成且阈值达标的计划ID集合 (作为排除条件) + * + * @param projectId 项目ID + * @return 已办计划ID集合 + */ + private List getDoneIds(String projectId) { + List completePlanOrGroupIds = selectTestPlanIdByProjectIdAndStatus(projectId, List.of((TestPlanConstants.TEST_PLAN_SHOW_STATUS_COMPLETED))); + if (CollectionUtils.isEmpty(completePlanOrGroupIds)) { + return null; + } + + List completePlanOrGroupWithStatistics = testPlanStatisticsService.calculateRate(completePlanOrGroupIds); + return completePlanOrGroupWithStatistics.stream() + .filter(plan -> plan.getPassRate() >= plan.getPassThreshold()) + .map(TestPlanStatisticsResponse::getId).collect(Collectors.toList()); + } }