From dff929003040f7a01e870cc5ee0ae37d31853dce Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Tue, 19 Nov 2024 15:15:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=B7=A5=E4=BD=9C=E5=8F=B0):=20=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E9=A1=B9=E7=9B=AE=E5=A4=9A=E9=80=89=E6=B8=85=E7=A9=BA?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=98=BE=E7=A4=BA=E6=97=A0=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/response/OverViewCountDTO.java | 3 ++ .../dashboard/service/DashboardService.java | 47 ++++++++++++++----- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/backend/services/dashboard/src/main/java/io/metersphere/dashboard/response/OverViewCountDTO.java b/backend/services/dashboard/src/main/java/io/metersphere/dashboard/response/OverViewCountDTO.java index 32c5bb23c1..152388fd5a 100644 --- a/backend/services/dashboard/src/main/java/io/metersphere/dashboard/response/OverViewCountDTO.java +++ b/backend/services/dashboard/src/main/java/io/metersphere/dashboard/response/OverViewCountDTO.java @@ -23,4 +23,7 @@ public class OverViewCountDTO { @Schema(description = "项目模块数量DTO") private List projectCountList; + @Schema(description = "错误码") + private int errorCode; + } 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 34d698bd41..b1da80fc65 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 @@ -69,6 +69,7 @@ import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -143,9 +144,8 @@ public class DashboardService { public OverViewCountDTO createByMeCount(DashboardFrontPageRequest request, String userId) { - if (!request.isSelectAll() && CollectionUtils.isEmpty(request.getProjectIds())) { - return new OverViewCountDTO(new HashMap<>(), new ArrayList<>(), new ArrayList<>()); - } + OverViewCountDTO map = getNoProjectData(request); + if (map != null) return map; List projects; if (CollectionUtils.isNotEmpty(request.getProjectIds())) { projects = extProjectMapper.getProjectNameModule(null, request.getProjectIds()); @@ -158,6 +158,22 @@ public class DashboardService { return getModuleCountMap(permissionModuleProjectIdMap, projects, toStartTime, toEndTime, userId); } + @Nullable + private static OverViewCountDTO getNoProjectData(DashboardFrontPageRequest request) { + if (!request.isSelectAll() && CollectionUtils.isEmpty(request.getProjectIds())) { + Map map = new HashMap<>(); + map.put(FUNCTIONAL, 0); + map.put(CASE_REVIEW, 0); + map.put(API, 0); + map.put(API_CASE, 0); + map.put(API_SCENARIO, 0); + map.put(TEST_PLAN, 0); + map.put(BUG_COUNT, 0); + return new OverViewCountDTO(map, new ArrayList<>(), new ArrayList<>(), 0); + } + return null; + } + @NotNull private OverViewCountDTO getModuleCountMap(Map> permissionModuleProjectIdMap, List projects, Long toStartTime, Long toEndTime, String userId) { Map map = new HashMap<>(); @@ -295,13 +311,15 @@ public class DashboardService { overViewCountDTO.setCaseCountMap(map); overViewCountDTO.setXAxis(xaxis); overViewCountDTO.setProjectCountList(nameArrayDTOList); + if (CollectionUtils.isEmpty(xaxis)) { + overViewCountDTO.setErrorCode(NO_PROJECT_PERMISSION.getCode()); + } return overViewCountDTO; } public OverViewCountDTO projectViewCount(DashboardFrontPageRequest request, String userId) { - if (!request.isSelectAll() && CollectionUtils.isEmpty(request.getProjectIds())) { - return new OverViewCountDTO(new HashMap<>(), new ArrayList<>(), new ArrayList<>()); - } + OverViewCountDTO map = getNoProjectData(request); + if (map != null) return map; List collect = getHasPermissionProjects(request, userId); Map> permissionModuleProjectIdMap = dashboardProjectService.getModuleProjectIds(collect); Long toStartTime = request.getToStartTime(); @@ -379,11 +397,15 @@ public class DashboardService { private void rebuildLayouts(List layoutDTOS, List allPermissionProjects, List orgProjectMemberList, Map> permissionModuleProjectIdMap) { for (LayoutDTO layoutDTO : layoutDTOS) { if (StringUtils.equalsIgnoreCase(layoutDTO.getKey(), DashboardUserLayoutKeys.PROJECT_VIEW.toString()) || StringUtils.equalsIgnoreCase(layoutDTO.getKey(), DashboardUserLayoutKeys.CREATE_BY_ME.toString())) { - List list = allPermissionProjects.stream().filter(t -> layoutDTO.getProjectIds().contains(t.getId())).toList(); - if (CollectionUtils.isNotEmpty(list)) { - layoutDTO.setProjectIds(list.stream().map(Project::getId).toList()); + if (CollectionUtils.isEmpty(layoutDTO.getProjectIds())) { + layoutDTO.setProjectIds(new ArrayList<>()); } else { - layoutDTO.setProjectIds(allPermissionProjects.stream().map(Project::getId).toList()); + List list = allPermissionProjects.stream().filter(t -> layoutDTO.getProjectIds().contains(t.getId())).toList(); + if (CollectionUtils.isNotEmpty(list)) { + layoutDTO.setProjectIds(list.stream().map(Project::getId).toList()); + } else { + layoutDTO.setProjectIds(allPermissionProjects.stream().map(Project::getId).toList()); + } } } else if (StringUtils.equalsIgnoreCase(layoutDTO.getKey(), DashboardUserLayoutKeys.PROJECT_MEMBER_VIEW.toString())) { List list = orgProjectMemberList.stream().filter(t -> layoutDTO.getHandleUsers().contains(t.getId())).toList(); @@ -610,6 +632,9 @@ public class DashboardService { OverViewCountDTO overViewCountDTO = new OverViewCountDTO(); overViewCountDTO.setXAxis(xaxis); overViewCountDTO.setProjectCountList(nameArrayDTOList); + if (CollectionUtils.isEmpty(xaxis)) { + overViewCountDTO.setErrorCode(NO_PROJECT_PERMISSION.getCode()); + } return overViewCountDTO; } @@ -738,7 +763,7 @@ public class DashboardService { public OverViewCountDTO projectBugHandleUser(DashboardFrontPageRequest request, String userId) { String projectId = request.getProjectIds().getFirst(); if (Boolean.FALSE.equals(permissionCheckService.checkModule(projectId, BUG_MODULE, userId, PermissionConstants.PROJECT_BUG_READ))) - return new OverViewCountDTO(null, new ArrayList<>(), new ArrayList<>()); + return new OverViewCountDTO(null, new ArrayList<>(), new ArrayList<>(), NO_PROJECT_PERMISSION.getCode()); Long toStartTime = request.getToStartTime(); Long toEndTime = request.getToEndTime(); List headerHandlerOption = getHandlerOption(request.getHandleUsers(), projectId);