fix(工作台): 首页项目多选清空项目显示无数据

This commit is contained in:
guoyuqi 2024-11-19 15:15:25 +08:00 committed by Craftsman
parent e95b31da74
commit dff9290030
2 changed files with 39 additions and 11 deletions

View File

@ -23,4 +23,7 @@ public class OverViewCountDTO {
@Schema(description = "项目模块数量DTO")
private List<NameArrayDTO> projectCountList;
@Schema(description = "错误码")
private int errorCode;
}

View File

@ -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<Project> 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<String, Integer> 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<String, Set<String>> permissionModuleProjectIdMap, List<Project> projects, Long toStartTime, Long toEndTime, String userId) {
Map<String, Integer> 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<Project> collect = getHasPermissionProjects(request, userId);
Map<String, Set<String>> permissionModuleProjectIdMap = dashboardProjectService.getModuleProjectIds(collect);
Long toStartTime = request.getToStartTime();
@ -379,11 +397,15 @@ public class DashboardService {
private void rebuildLayouts(List<LayoutDTO> layoutDTOS, List<Project> allPermissionProjects, List<ProjectUserMemberDTO> orgProjectMemberList, Map<String, Set<String>> permissionModuleProjectIdMap) {
for (LayoutDTO layoutDTO : layoutDTOS) {
if (StringUtils.equalsIgnoreCase(layoutDTO.getKey(), DashboardUserLayoutKeys.PROJECT_VIEW.toString()) || StringUtils.equalsIgnoreCase(layoutDTO.getKey(), DashboardUserLayoutKeys.CREATE_BY_ME.toString())) {
List<Project> 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<Project> 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<ProjectUserMemberDTO> 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<SelectOption> headerHandlerOption = getHandlerOption(request.getHandleUsers(), projectId);