refactor(工作台): 调整项目概览和我的创建数据结果

This commit is contained in:
guoyuqi 2024-11-26 15:11:49 +08:00 committed by 刘瑞斌
parent 910ed2232c
commit bde39eb0c5
1 changed files with 93 additions and 81 deletions

View File

@ -180,139 +180,151 @@ public class DashboardService {
@NotNull @NotNull
private OverViewCountDTO getModuleCountMap(Map<String, Set<String>> permissionModuleProjectIdMap, List<Project> projects, Long toStartTime, Long toEndTime, String userId) { private OverViewCountDTO getModuleCountMap(Map<String, Set<String>> permissionModuleProjectIdMap, List<Project> projects, Long toStartTime, Long toEndTime, String userId) {
Map<String, Integer> map = new HashMap<>(); Map<String, String> projectNameMap = projects.stream().collect(Collectors.toMap(Project::getId, Project::getName));
List<String> xaxis = new ArrayList<>();
List<NameArrayDTO> nameArrayDTOList = new ArrayList<>(); Map<String, Integer> projectCaseCountMap;
Map<String, Integer> projectReviewCountMap;
Map<String, Integer> projectApiCountMap;
Map<String, Integer> projectApiScenarioCountMap;
Map<String, Integer> projectApiCaseCountMap;
Map<String, Integer> projectPlanCountMap;
Map<String, Integer> projectBugCountMap;
//功能用例 //功能用例
Map<String, ProjectCountDTO> caseProjectCount = new HashMap<>();
Set<String> caseProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.FUNCTIONAL_CASE_READ); Set<String> caseProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.FUNCTIONAL_CASE_READ);
if (CollectionUtils.isNotEmpty(caseProjectIds)) { if (CollectionUtils.isNotEmpty(caseProjectIds)) {
//有权限 //有权限
List<ProjectCountDTO> projectCaseCount = extFunctionalCaseMapper.projectCaseCount(caseProjectIds, toStartTime, toEndTime, userId); List<ProjectCountDTO> projectCaseCount = extFunctionalCaseMapper.projectCaseCount(caseProjectIds, toStartTime, toEndTime, userId);
int caseCount = projectCaseCount.stream().mapToInt(ProjectCountDTO::getCount).sum(); projectCaseCountMap = projectCaseCount.stream().collect(Collectors.toMap(ProjectCountDTO::getProjectId, ProjectCountDTO::getCount));
map.put(FUNCTIONAL, caseCount); } else {
xaxis.add(FUNCTIONAL); projectCaseCountMap = new HashMap<>();
caseProjectCount = projectCaseCount.stream().collect(Collectors.toMap(ProjectCountDTO::getProjectId, t -> t));
} }
//用例评审 //用例评审
Map<String, ProjectCountDTO> reviewProjectCount = new HashMap<>();
Set<String> reviewProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.CASE_REVIEW_READ); Set<String> reviewProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.CASE_REVIEW_READ);
if (CollectionUtils.isNotEmpty(reviewProjectIds)) { if (CollectionUtils.isNotEmpty(reviewProjectIds)) {
List<ProjectCountDTO> projectReviewCount = extCaseReviewMapper.projectReviewCount(reviewProjectIds, toStartTime, toEndTime, userId); List<ProjectCountDTO> projectReviewCount = extCaseReviewMapper.projectReviewCount(reviewProjectIds, toStartTime, toEndTime, userId);
int reviewCount = projectReviewCount.stream().mapToInt(ProjectCountDTO::getCount).sum(); projectReviewCountMap = projectReviewCount.stream().collect(Collectors.toMap(ProjectCountDTO::getProjectId, ProjectCountDTO::getCount));
map.put(CASE_REVIEW, reviewCount); } else {
xaxis.add(CASE_REVIEW); projectReviewCountMap = new HashMap<>();
reviewProjectCount = projectReviewCount.stream().collect(Collectors.toMap(ProjectCountDTO::getProjectId, t -> t));
} }
//接口 //接口
Map<String, ProjectCountDTO> apiProjectCount = new HashMap<>();
Set<String> apiProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.PROJECT_API_DEFINITION_READ); Set<String> apiProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.PROJECT_API_DEFINITION_READ);
if (CollectionUtils.isNotEmpty(apiProjectIds)) { if (CollectionUtils.isNotEmpty(apiProjectIds)) {
List<ProjectCountDTO> projectApiCount = extApiDefinitionMapper.projectApiCount(apiProjectIds, toStartTime, toEndTime, userId); List<ProjectCountDTO> projectApiCount = extApiDefinitionMapper.projectApiCount(apiProjectIds, toStartTime, toEndTime, userId);
int apiCount = projectApiCount.stream().mapToInt(ProjectCountDTO::getCount).sum(); projectApiCountMap = projectApiCount.stream().collect(Collectors.toMap(ProjectCountDTO::getProjectId, ProjectCountDTO::getCount));
map.put(API, apiCount); } else {
xaxis.add(API); projectApiCountMap = new HashMap<>();
apiProjectCount = projectApiCount.stream().collect(Collectors.toMap(ProjectCountDTO::getProjectId, t -> t));
} }
//接口用例 //接口用例
Map<String, ProjectCountDTO> apiCaseProjectCount = new HashMap<>();
Set<String> apiCaseProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.PROJECT_API_DEFINITION_CASE_READ); Set<String> apiCaseProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.PROJECT_API_DEFINITION_CASE_READ);
if (CollectionUtils.isNotEmpty(apiCaseProjectIds)) { if (CollectionUtils.isNotEmpty(apiCaseProjectIds)) {
List<ProjectCountDTO> projectApiCaseCount = extApiTestCaseMapper.projectApiCaseCount(apiCaseProjectIds, toStartTime, toEndTime, userId); List<ProjectCountDTO> projectApiCaseCount = extApiTestCaseMapper.projectApiCaseCount(apiCaseProjectIds, toStartTime, toEndTime, userId);
int apiCaseCount = projectApiCaseCount.stream().mapToInt(ProjectCountDTO::getCount).sum(); projectApiCaseCountMap = projectApiCaseCount.stream().collect(Collectors.toMap(ProjectCountDTO::getProjectId, ProjectCountDTO::getCount));
map.put(API_CASE, apiCaseCount); } else {
xaxis.add(API_CASE); projectApiCaseCountMap = new HashMap<>();
apiCaseProjectCount = projectApiCaseCount.stream().collect(Collectors.toMap(ProjectCountDTO::getProjectId, t -> t));
} }
//接口场景 //接口场景
Map<String, ProjectCountDTO> apiScenarioProjectCount = new HashMap<>();
Set<String> scenarioProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.PROJECT_API_SCENARIO_READ); Set<String> scenarioProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.PROJECT_API_SCENARIO_READ);
if (CollectionUtils.isNotEmpty(scenarioProjectIds)) { if (CollectionUtils.isNotEmpty(scenarioProjectIds)) {
List<ProjectCountDTO> projectApiScenarioCount = extApiScenarioMapper.projectApiScenarioCount(scenarioProjectIds, toStartTime, toEndTime, userId); List<ProjectCountDTO> projectApiScenarioCount = extApiScenarioMapper.projectApiScenarioCount(scenarioProjectIds, toStartTime, toEndTime, userId);
int apiScenarioCount = projectApiScenarioCount.stream().mapToInt(ProjectCountDTO::getCount).sum(); projectApiScenarioCountMap = projectApiScenarioCount.stream().collect(Collectors.toMap(ProjectCountDTO::getProjectId, ProjectCountDTO::getCount));
map.put(API_SCENARIO, apiScenarioCount); } else {
xaxis.add(API_SCENARIO); projectApiScenarioCountMap = new HashMap<>();
apiScenarioProjectCount = projectApiScenarioCount.stream().collect(Collectors.toMap(ProjectCountDTO::getProjectId, t -> t));
} }
//测试计划 //测试计划
Map<String, ProjectCountDTO> testPlanProjectCount = new HashMap<>();
Set<String> planProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.TEST_PLAN_READ); Set<String> planProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.TEST_PLAN_READ);
if (CollectionUtils.isNotEmpty(planProjectIds)) { if (CollectionUtils.isNotEmpty(planProjectIds)) {
List<ProjectCountDTO> projectPlanCount = extTestPlanMapper.projectPlanCount(planProjectIds, toStartTime, toEndTime, userId); List<ProjectCountDTO> projectPlanCount = extTestPlanMapper.projectPlanCount(planProjectIds, toStartTime, toEndTime, userId);
int testPlanCount = projectPlanCount.stream().mapToInt(ProjectCountDTO::getCount).sum(); projectPlanCountMap = projectPlanCount.stream().collect(Collectors.toMap(ProjectCountDTO::getProjectId, ProjectCountDTO::getCount));
map.put(TEST_PLAN, testPlanCount); } else {
xaxis.add(TEST_PLAN); projectPlanCountMap = new HashMap<>();
testPlanProjectCount = projectPlanCount.stream().collect(Collectors.toMap(ProjectCountDTO::getProjectId, t -> t));
} }
//缺陷管理 //缺陷管理
Map<String, ProjectCountDTO> bugProjectCount = new HashMap<>();
Set<String> bugProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.PROJECT_BUG_READ); Set<String> bugProjectIds = permissionModuleProjectIdMap.get(PermissionConstants.PROJECT_BUG_READ);
if (CollectionUtils.isNotEmpty(bugProjectIds)) { if (CollectionUtils.isNotEmpty(bugProjectIds)) {
List<ProjectCountDTO> projectBugCount = extBugMapper.projectBugCount(bugProjectIds, toStartTime, toEndTime, userId); List<ProjectCountDTO> projectBugCount = extBugMapper.projectBugCount(bugProjectIds, toStartTime, toEndTime, userId);
int bugCount = projectBugCount.stream().mapToInt(ProjectCountDTO::getCount).sum(); projectBugCountMap = projectBugCount.stream().collect(Collectors.toMap(ProjectCountDTO::getProjectId, ProjectCountDTO::getCount));
map.put(BUG_COUNT, bugCount);
xaxis.add(BUG_COUNT); }else {
bugProjectCount = projectBugCount.stream().collect(Collectors.toMap(ProjectCountDTO::getProjectId, t -> t)); projectBugCountMap = new HashMap<>();
} }
for (Project project : projects) { List<Integer> projectCaseCount = new ArrayList<>();
String projectId = project.getId(); List<Integer> projectReviewCount = new ArrayList<>();
String projectName = project.getName(); List<Integer> projectApiCount = new ArrayList<>();
NameArrayDTO nameArrayDTO = new NameArrayDTO(); List<Integer> projectApiCaseCount = new ArrayList<>();
nameArrayDTO.setId(projectId); List<Integer> projectApiScenarioCount = new ArrayList<>();
nameArrayDTO.setName(projectName); List<Integer> projectPlanCount = new ArrayList<>();
List<Integer> count = new ArrayList<>(); List<Integer> projectBugCount = new ArrayList<>();
ProjectCountDTO projectCountDTO = caseProjectCount.get(projectId);
if (projectCountDTO != null) { projectNameMap.forEach((id, userName) -> {
count.add(projectCountDTO.getCount()); if (projectCaseCountMap.get(id) != null) {
projectCaseCount.add(projectCaseCountMap.get(id));
} else { } else {
count.add(0); projectCaseCount.add(0);
} }
ProjectCountDTO reviewDTO = reviewProjectCount.get(projectId); if (projectReviewCountMap.get(id) != null) {
if (reviewDTO != null) { projectReviewCount.add(projectReviewCountMap.get(id));
count.add(reviewDTO.getCount());
} else { } else {
count.add(0); projectReviewCount.add(0);
} }
ProjectCountDTO apiDTO = apiProjectCount.get(projectId); if (projectApiCountMap.get(id) != null) {
if (apiDTO != null) { projectApiCount.add(projectApiCountMap.get(id));
count.add(apiDTO.getCount());
} else { } else {
count.add(0); projectApiCount.add(0);
} }
ProjectCountDTO apiCaseDTO = apiCaseProjectCount.get(projectId); if (projectApiCaseCountMap.get(id) != null) {
if (apiCaseDTO != null) { projectApiCaseCount.add(projectApiCaseCountMap.get(id));
count.add(apiCaseDTO.getCount());
} else { } else {
count.add(0); projectApiCaseCount.add(0);
} }
ProjectCountDTO apiScenarioDTO = apiScenarioProjectCount.get(projectId); if (projectApiScenarioCountMap.get(id) != null) {
if (apiScenarioDTO != null) { projectApiScenarioCount.add(projectApiScenarioCountMap.get(id));
count.add(apiScenarioDTO.getCount());
} else { } else {
count.add(0); projectApiScenarioCount.add(0);
} }
ProjectCountDTO testPlanDTO = testPlanProjectCount.get(projectId); if (projectPlanCountMap.get(id) != null) {
if (testPlanDTO != null) { projectPlanCount.add(projectPlanCountMap.get(id));
count.add(testPlanDTO.getCount());
} else { } else {
count.add(0); projectPlanCount.add(0);
} }
ProjectCountDTO bugDTO = bugProjectCount.get(projectId); if (projectBugCountMap.get(id) != null) {
if (bugDTO != null) { projectBugCount.add(projectBugCountMap.get(id));
count.add(bugDTO.getCount());
} else { } else {
count.add(0); projectBugCount.add(0);
} }
nameArrayDTO.setCount(count); });
nameArrayDTOList.add(nameArrayDTO); List<String> xaxis = new ArrayList<>(projectNameMap.values());
}
List<NameArrayDTO> nameArrayDTOList = new ArrayList<>();
NameArrayDTO userCaseArray = new NameArrayDTO();
userCaseArray.setCount(projectCaseCount);
nameArrayDTOList.add(userCaseArray);
NameArrayDTO userReviewArray = new NameArrayDTO();
userReviewArray.setCount(projectReviewCount);
nameArrayDTOList.add(userReviewArray);
NameArrayDTO userApiArray = new NameArrayDTO();
userApiArray.setCount(projectApiCount);
nameArrayDTOList.add(userApiArray);
NameArrayDTO userApiCaseArray = new NameArrayDTO();
userApiCaseArray.setCount(projectApiCaseCount);
nameArrayDTOList.add(userApiCaseArray);
NameArrayDTO userApiScenarioArray = new NameArrayDTO();
userApiScenarioArray.setCount(projectApiScenarioCount);
nameArrayDTOList.add(userApiScenarioArray);
NameArrayDTO userPlanArray = new NameArrayDTO();
userPlanArray.setCount(projectPlanCount);
nameArrayDTOList.add(userPlanArray);
NameArrayDTO userBugArray = new NameArrayDTO();
userBugArray.setCount(projectBugCount);
nameArrayDTOList.add(userBugArray);
OverViewCountDTO overViewCountDTO = new OverViewCountDTO(); OverViewCountDTO overViewCountDTO = new OverViewCountDTO();
overViewCountDTO.setCaseCountMap(map);
overViewCountDTO.setXAxis(xaxis); overViewCountDTO.setXAxis(xaxis);
overViewCountDTO.setProjectCountList(nameArrayDTOList); overViewCountDTO.setProjectCountList(nameArrayDTOList);
if (CollectionUtils.isEmpty(xaxis)) { if (CollectionUtils.isEmpty(xaxis)) {