refactor(工作台): 测试计划概览数据填充

This commit is contained in:
guoyuqi 2024-12-04 15:29:24 +08:00 committed by Craftsman
parent e1c14e77c7
commit 037fe2a3fb
3 changed files with 39 additions and 4 deletions

View File

@ -728,9 +728,15 @@ public class DashboardService {
List<TestPlanBugPageResponse> planBugs = extTestPlanBugMapper.countBugByIds(planIds); List<TestPlanBugPageResponse> planBugs = extTestPlanBugMapper.countBugByIds(planIds);
//获取卡片数据 //获取卡片数据
buildCountMap(planCount, planBugs, overViewCountDTO); buildCountMap(planCount, planBugs, overViewCountDTO);
Map<String, List<TestPlanFunctionalCase>> caseUserMap = planFunctionalCases.stream().collect(Collectors.groupingBy(TestPlanFunctionalCase::getExecuteUser)); List<TestPlanFunctionalCase> caseUserNullList = planFunctionalCases.stream().filter(t -> StringUtils.isBlank(t.getExecuteUser())).toList();
Map<String, List<TestPlanApiCase>> apiCaseUserMap = planApiCases.stream().collect(Collectors.groupingBy(TestPlanApiCase::getExecuteUser)); Map<String, List<TestPlanFunctionalCase>> caseUserMap = planFunctionalCases.stream().filter(t->StringUtils.isNotBlank(t.getExecuteUser())).collect(Collectors.groupingBy(TestPlanFunctionalCase::getExecuteUser));
Map<String, List<TestPlanApiScenario>> apiScenarioUserMap = planApiScenarios.stream().collect(Collectors.groupingBy(TestPlanApiScenario::getExecuteUser)); caseUserMap.put("NONE", caseUserNullList);
List<TestPlanApiCase> apiCaseUserNullList = planApiCases.stream().filter(t -> StringUtils.isBlank(t.getExecuteUser())).toList();
Map<String, List<TestPlanApiCase>> apiCaseUserMap = planApiCases.stream().filter(t->StringUtils.isNotBlank(t.getExecuteUser())).collect(Collectors.groupingBy(TestPlanApiCase::getExecuteUser));
apiCaseUserMap.put("NONE", apiCaseUserNullList);
List<TestPlanApiScenario> apiScenarioNullList = planApiScenarios.stream().filter(t -> StringUtils.isBlank(t.getExecuteUser())).toList();
Map<String, List<TestPlanApiScenario>> apiScenarioUserMap = planApiScenarios.stream().filter(t->StringUtils.isNotBlank(t.getExecuteUser())).collect(Collectors.groupingBy(TestPlanApiScenario::getExecuteUser));
apiScenarioUserMap.put("NONE", apiScenarioNullList);
Map<String, List<TestPlanBugPageResponse>> bugUserMap = planBugs.stream().collect(Collectors.groupingBy(TestPlanBugPageResponse::getCreateUser)); Map<String, List<TestPlanBugPageResponse>> bugUserMap = planBugs.stream().collect(Collectors.groupingBy(TestPlanBugPageResponse::getCreateUser));
List<User> users = getUsers(caseUserMap, apiCaseUserMap, apiScenarioUserMap, bugUserMap); List<User> users = getUsers(caseUserMap, apiCaseUserMap, apiScenarioUserMap, bugUserMap);
Map<String, String> userNameMap = users.stream().collect(Collectors.toMap(User::getId, User::getName)); Map<String, String> userNameMap = users.stream().collect(Collectors.toMap(User::getId, User::getName));
@ -739,6 +745,7 @@ public class DashboardService {
if (CollectionUtils.isEmpty(users)) { if (CollectionUtils.isEmpty(users)) {
if (totalCount > 0) { if (totalCount > 0) {
nameList = List.of(Translator.get("plan_executor")); nameList = List.of(Translator.get("plan_executor"));
userNameMap.put("NONE", Translator.get("plan_executor"));
} }
} else { } else {
nameList = userNameMap.values().stream().toList(); nameList = userNameMap.values().stream().toList();
@ -793,6 +800,9 @@ public class DashboardService {
closeBugCount.add(testPlanBugPageResponses.size()); closeBugCount.add(testPlanBugPageResponses.size());
} }
} else {
createBugCount.add(0);
closeBugCount.add(0);
} }
totalCaseCount.add(count); totalCaseCount.add(count);
finishCaseCount.add(finishCount); finishCaseCount.add(finishCount);
@ -823,6 +833,9 @@ public class DashboardService {
userSet.addAll(apiCaseUserMap.keySet()); userSet.addAll(apiCaseUserMap.keySet());
userSet.addAll(apiScenarioUserMap.keySet()); userSet.addAll(apiScenarioUserMap.keySet());
userSet.addAll(bugUserMap.keySet()); userSet.addAll(bugUserMap.keySet());
if (CollectionUtils.isEmpty(userSet)) {
return new ArrayList<>();
}
UserExample userExample = new UserExample(); UserExample userExample = new UserExample();
userExample.createCriteria().andIdIn(new ArrayList<>(userSet)); userExample.createCriteria().andIdIn(new ArrayList<>(userSet));
userExample.createCriteria().andEnableEqualTo(true); userExample.createCriteria().andEnableEqualTo(true);

View File

@ -184,7 +184,20 @@ public class DashboardFrontPageControllerTests extends BaseTest {
JSON.parseObject(mvcResultAll.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), JSON.parseObject(mvcResultAll.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
OverViewCountDTO.class); OverViewCountDTO.class);
Assertions.assertNotNull(moduleCountAll); Assertions.assertNotNull(moduleCountAll);
System.out.println(JSON.toJSONString(moduleCountAll));
dashboardFrontPageRequest.setPlanId("dashboard_group-plan");
mvcResultAll = this.requestPostWithOkAndReturn(PROJECT_PLAN_VIEW, dashboardFrontPageRequest);
moduleCountAll = JSON.parseObject(JSON.toJSONString(
JSON.parseObject(mvcResultAll.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
OverViewCountDTO.class);
Assertions.assertNotNull(moduleCountAll);
dashboardFrontPageRequest.setPlanId("dashboard_test-plan-id2");
mvcResultAll = this.requestPostWithOkAndReturn(PROJECT_PLAN_VIEW, dashboardFrontPageRequest);
moduleCountAll = JSON.parseObject(JSON.toJSONString(
JSON.parseObject(mvcResultAll.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
OverViewCountDTO.class);
Assertions.assertNotNull(moduleCountAll);
List<SelectOption> headerStatusOption = bugStatusService.getHeaderStatusOption(DEFAULT_PROJECT_ID); List<SelectOption> headerStatusOption = bugStatusService.getHeaderStatusOption(DEFAULT_PROJECT_ID);
buildBug(headerStatusOption); buildBug(headerStatusOption);

View File

@ -138,6 +138,15 @@ INSERT INTO test_plan_api_case(`id`, `test_plan_id`, `api_case_id`, `environment
INSERT INTO test_plan_api_scenario (id, test_plan_id, api_scenario_id, environment_id, execute_user, last_exec_result, last_exec_report_id, create_time, create_user, pos, test_plan_collection_id, grouped) VALUES INSERT INTO test_plan_api_scenario (id, test_plan_id, api_scenario_id, environment_id, execute_user, last_exec_result, last_exec_report_id, create_time, create_user, pos, test_plan_collection_id, grouped) VALUES
('dashboard_plan_api_scenario_1', 'dashboard_test-plan-id', 'dashboard_scenario_four', '1', 'admin', 'PASSED', NULL, 1716370415311, 'admin', 1, '123', false); ('dashboard_plan_api_scenario_1', 'dashboard_test-plan-id', 'dashboard_scenario_four', '1', 'admin', 'PASSED', NULL, 1716370415311, 'admin', 1, '123', false);
INSERT INTO test_plan_functional_case(id, test_plan_id, functional_case_id, create_time, create_user, execute_user, last_exec_time, last_exec_result, pos, test_plan_collection_id)
VALUES ('test_plan_functional_case_dashboard_id1', 'dashboard_group-plan', 'dashboard_TEST_FUNCTIONAL_CASE_ID_g', 1669174143999, 'admin', NULL, 1669174143999, 'SUCCESS', 5000, '123');
INSERT INTO test_plan_api_case(`id`, `test_plan_id`, `api_case_id`, `environment_id`, `last_exec_result`, `last_exec_report_id`, `execute_user`, `create_time`, `create_user`, `pos`, `test_plan_collection_id`) VALUES
('dashboard_plan_api_case_2', 'dashboard_group-plan', 'dashboard_ac_4', '1', 'PASSED', NULL, NULL, 1716370415311, 'admin', 1, '123');
INSERT INTO test_plan_api_scenario (id, test_plan_id, api_scenario_id, environment_id, execute_user, last_exec_result, last_exec_report_id, create_time, create_user, pos, test_plan_collection_id, grouped) VALUES
('dashboard_plan_api_scenario_3', 'dashboard_group-plan', 'dashboard_scenario_four', '1', NULL, 'PASSED', NULL, 1716370415311, 'admin', 1, '123', false);
INSERT INTO project_application (project_id, type, type_value) VALUES INSERT INTO project_application (project_id, type, type_value) VALUES
('100001100001', 'BUG_SYNC_BUG_PLATFORM_CONFIG', '{"jiraKey":"TES","jiraBugTypeId":"10009"}'), ('100001100001', 'BUG_SYNC_BUG_PLATFORM_CONFIG', '{"jiraKey":"TES","jiraBugTypeId":"10009"}'),