diff --git a/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardService.java b/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardService.java index 379943116d..b39e0bd661 100644 --- a/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardService.java +++ b/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardService.java @@ -33,6 +33,7 @@ import io.metersphere.functional.request.CaseReviewPageRequest; import io.metersphere.functional.service.CaseReviewService; import io.metersphere.plan.domain.*; import io.metersphere.plan.dto.TestPlanAndGroupInfoDTO; +import io.metersphere.plan.dto.TestPlanBugCaseDTO; import io.metersphere.plan.dto.response.TestPlanBugPageResponse; import io.metersphere.plan.dto.response.TestPlanStatisticsResponse; import io.metersphere.plan.mapper.*; @@ -162,7 +163,7 @@ public class DashboardService { public static final String TEST_PLAN_MODULE = "testPlan"; public static final String FUNCTIONAL_CASE_MODULE = "caseManagement"; public static final String BUG_MODULE = "bugManagement"; - + public static final String NONE = "NONE"; @@ -804,7 +805,7 @@ public class DashboardService { List planApiScenarios = extTestPlanApiScenarioMapper.selectByTestPlanIdAndNotDeleted(planId); TestPlanStatisticsResponse statisticsResponse = buildStatisticsResponse(planId, planFunctionalCases, planApiCases, planApiScenarios); // 计划-缺陷的关联数据 - List planBugs = extTestPlanBugMapper.selectBugCountByPlanId(planId); + List planBugs = extTestPlanBugMapper.selectPlanRelationBug(planId); //获取卡片数据 buildCountMap(statisticsResponse, planBugs, overViewCountDTO); Map> caseUserMap = planFunctionalCases.stream().collect(Collectors.groupingBy(t -> StringUtils.isEmpty(t.getExecuteUser()) ? NONE : t.getExecuteUser())); @@ -812,8 +813,8 @@ public class DashboardService { Map> apiScenarioUserMap = planApiScenarios.stream().collect(Collectors.groupingBy(t -> StringUtils.isEmpty(t.getExecuteUser()) ? NONE : t.getExecuteUser())); Map> bugUserMap = planBugs.stream().collect(Collectors.groupingBy(TestPlanBugPageResponse::getCreateUser)); int totalCount = planFunctionalCases.size() + planApiCases.size() + planApiScenarios.size() + planBugs.size(); - List users = getUsers(caseUserMap, apiCaseUserMap, apiScenarioUserMap, bugUserMap, totalCount); - List nameList =users.stream().map(User::getName).toList(); + List users = getUsers(caseUserMap, apiCaseUserMap, apiScenarioUserMap, totalCount); + List nameList = users.stream().map(User::getName).toList(); overViewCountDTO.setXAxis(nameList); //获取柱状图数据 List nameArrayDTOList = getNameArrayDTOS(projectId, users, caseUserMap, apiCaseUserMap, apiScenarioUserMap, bugUserMap); @@ -836,29 +837,47 @@ public class DashboardService { int count = 0; int finishCount = 0; List testPlanFunctionalCases = caseUserMap.get(userId); + List currentUserCaseIds = new ArrayList<>(); if (CollectionUtils.isNotEmpty(testPlanFunctionalCases)) { + List functionalCaseIds = testPlanFunctionalCases.stream().map(TestPlanFunctionalCase::getFunctionalCaseId).toList(); + currentUserCaseIds.addAll(functionalCaseIds); count += testPlanFunctionalCases.size(); List list = testPlanFunctionalCases.stream().filter(t -> !StringUtils.equalsIgnoreCase(t.getLastExecResult(), ExecStatus.PENDING.name())).toList(); finishCount += list.size(); } List testPlanApiCases = apiCaseUserMap.get(userId); if (CollectionUtils.isNotEmpty(testPlanApiCases)) { + List apiCaseIds = testPlanApiCases.stream().map(TestPlanApiCase::getApiCaseId).toList(); + currentUserCaseIds.addAll(apiCaseIds); count += testPlanApiCases.size(); List list = testPlanApiCases.stream().filter(t -> !StringUtils.equalsIgnoreCase(t.getLastExecResult(), ExecStatus.PENDING.name())).toList(); finishCount += list.size(); } List testPlanApiScenarios = apiScenarioUserMap.get(userId); if (CollectionUtils.isNotEmpty(testPlanApiScenarios)) { + List apiScenarioIds = testPlanApiScenarios.stream().map(TestPlanApiScenario::getApiScenarioId).toList(); + currentUserCaseIds.addAll(apiScenarioIds); count += testPlanApiScenarios.size(); List list = testPlanApiScenarios.stream().filter(t -> !StringUtils.equalsIgnoreCase(t.getLastExecResult(), ExecStatus.PENDING.name())).toList(); finishCount += list.size(); } List testPlanBugPageResponses = bugUserMap.get(userId); if (CollectionUtils.isNotEmpty(testPlanBugPageResponses)) { - createBugCount.add(testPlanBugPageResponses.size()); + List createBugIds = testPlanBugPageResponses.stream().map(TestPlanBugPageResponse::getId).toList(); + if (CollectionUtils.isNotEmpty(currentUserCaseIds)) { + List bugRelatedCases = extTestPlanBugMapper.getBugRelatedCaseByCaseIds(createBugIds, currentUserCaseIds, testPlanBugPageResponses.getFirst().getTestPlanId()); + createBugCount.add(bugRelatedCases.size()); + } else { + createBugCount.add(0); + } if (CollectionUtils.isNotEmpty(statusList)) { - List list = testPlanBugPageResponses.stream().filter(t -> statusList.contains(t.getStatus())).toList(); - closeBugCount.add(list.size()); + List bugIds = testPlanBugPageResponses.stream().filter(t -> statusList.contains(t.getStatus())).map(TestPlanBugPageResponse::getId).toList(); + if (CollectionUtils.isNotEmpty(bugIds) && CollectionUtils.isNotEmpty(currentUserCaseIds)) { + List bugRelatedCases = extTestPlanBugMapper.getBugRelatedCaseByCaseIds(bugIds, currentUserCaseIds, testPlanBugPageResponses.getFirst().getTestPlanId()); + closeBugCount.add(bugRelatedCases.size()); + } else { + closeBugCount.add(0); + } } else { closeBugCount.add(testPlanBugPageResponses.size()); } @@ -890,7 +909,7 @@ public class DashboardService { return nameArrayDTOList; } - private List getUsers(Map> caseUserMap, Map> apiCaseUserMap, Map> apiScenarioUserMap, Map> bugUserMap, int totalCount) { + private List getUsers(Map> caseUserMap, Map> apiCaseUserMap, Map> apiScenarioUserMap, int totalCount) { Set caseUserIds = caseUserMap.keySet(); boolean addDefaultUser = caseUserIds.contains(NONE); Set userSet = new HashSet<>(caseUserIds); @@ -904,10 +923,9 @@ public class DashboardService { if (apiScenarioIds.contains(NONE)) { addDefaultUser = true; } - userSet.addAll(bugUserMap.keySet()); List users = new ArrayList<>(); if (CollectionUtils.isEmpty(userSet)) { - if (totalCount>0) { + if (totalCount > 0) { addDefaultUser(users); } } else { diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanBugMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanBugMapper.java index f1a3f04292..d76213e33f 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanBugMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanBugMapper.java @@ -14,32 +14,38 @@ import java.util.List; */ public interface ExtTestPlanBugMapper { - /** - * 查询计划-关联缺陷列表 - * @param request 请求参数 - * @return 缺陷列表 - */ - @BaseConditionFilter - List list(@Param("request") TestPlanBugPageRequest request); + /** + * 查询计划-关联缺陷列表 + * + * @param request 请求参数 + * @return 缺陷列表 + */ + @BaseConditionFilter + List list(@Param("request") TestPlanBugPageRequest request); - /** - * 根据缺陷ID集合获取计划下缺陷关联的用例集合 - * @param bugIds 缺陷ID集合 - * @param planId 计划ID - * @return 用例集合 - */ - List getBugRelatedCase(@Param("ids") List bugIds, @Param("planId") String planId); + /** + * 根据缺陷ID集合获取计划下缺陷关联的用例集合 + * + * @param bugIds 缺陷ID集合 + * @param planId 计划ID + * @return 用例集合 + */ + List getBugRelatedCase(@Param("ids") List bugIds, @Param("planId") String planId); + + List getBugRelatedCaseByCaseIds(@Param("ids") List bugIds, @Param("caseIds") List caseIds, @Param("planId") String planId); - List countBugByIds(@Param("planIds") List planIds); + List countBugByIds(@Param("planIds") List planIds); - List selectBugCountByPlanId(@Param("planId") String planId); + List selectBugCountByPlanId(@Param("planId") String planId); + List selectPlanRelationBug(@Param("planId") String planId); - /** - * 根据用例关系ID集合获取计划下用例关联的缺陷集合 - * @param caseIds 用例ID集合 - * @return 缺陷集合 - */ - List getCaseRelatedBug(@Param("ids") List caseIds); + /** + * 根据用例关系ID集合获取计划下用例关联的缺陷集合 + * + * @param caseIds 用例ID集合 + * @return 缺陷集合 + */ + List getCaseRelatedBug(@Param("ids") List caseIds); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanBugMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanBugMapper.xml index 6f1a514c62..b9eb7dc8d3 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanBugMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanBugMapper.xml @@ -50,6 +50,17 @@ group by brc.bug_id + + + + +