根据代码1“@FeignClient(name = "UserUgsApi", url = "${newbim.login-domain}") public interface IApplicationServicePlatformClient {@PostMapping("/ums/v1/feign/omp/project/search") ResultWrapper<QueryAllProject> listUserProject(@RequestHeader("BSP_TOKEN") String bspToken, @RequestHeader("BSP_USER_ID") String bspUserId, @RequestHeader("BSP_USER_ENV_ID") String bspUserEnvId, @RequestHeader("BSP_USER_TENANT") String bspUserTenant, @RequestBody ProjectCondition queryProjectDto);” 修改下面代码:@Override public List<ProjectCountVO> projectCount(String beginTime, String endTime, Integer forceType, String projectId) { List<TaskTask> taskTaskList = this.listStatisticsTask(beginTime, endTime, forceType, projectId); if(CollectionUtil.isEmpty(taskTaskList)){ return Collections.emptyList(); } List<ProjectCountVO> result = new ArrayList<>(); Map<String, List<TaskTask>> projectTaskMap = taskTaskList.stream().collect(Collectors.groupingBy(TaskTask::getProjectId)); for (Map.Entry<String, List<TaskTask>> projectTaskEntry : projectTaskMap.entrySet()) { projectId = projectTaskEntry.getKey(); ProjectCountVO projectCountVO = new ProjectCountVO(); projectCountVO.setId(projectId); //查询项目名称 projectCountVO.setName("todo"); List<TaskTask> taskList = projectTaskEntry.getValue(); projectCountVO.setTaskCount(taskList.size()); Integer problemCount = CollectionUtil.isEmpty(taskList) ? 0 : taskList.stream().collect(Collectors.summingInt(task-> Optional.ofNullable(task.getProblemNum()).orElse(0))); projectCountVO.setProblemCount(problemCount); result.add(projectCountVO); } return result; }
时间: 2023-08-02 12:07:44 浏览: 131
代码修改如下:
```
@Override
public List<ProjectCountVO> projectCount(String beginTime, String endTime, Integer forceType, String projectId) {
ResultWrapper<QueryAllProject> projectWrapper = applicationServicePlatformClient.listUserProject(bspToken, bspUserId, bspUserEnvId, bspUserTenant, new ProjectCondition());
List<ProjectDTO> projectList = Optional.ofNullable(projectWrapper).map(ResultWrapper::getData).map(QueryAllProject::getProjectList).orElse(Collections.emptyList());
if(CollectionUtil.isEmpty(projectList)){
log.warn("No projects found for user: {}", bspUserId);
return Collections.emptyList();
}
List<TaskTask> taskTaskList = this.listStatisticsTask(beginTime, endTime, forceType, projectId);
if(CollectionUtil.isEmpty(taskTaskList)){
return Collections.emptyList();
}
Map<String, List<TaskTask>> projectTaskMap = taskTaskList.stream().collect(Collectors.groupingBy(TaskTask::getProjectId));
List<ProjectCountVO> result = new ArrayList<>();
for (ProjectDTO projectDTO : projectList) {
projectId = projectDTO.getId();
ProjectCountVO projectCountVO = new ProjectCountVO();
projectCountVO.setId(projectId);
projectCountVO.setName(projectDTO.getName());
List<TaskTask> taskList = projectTaskMap.get(projectId);
Integer taskCount = CollectionUtil.isEmpty(taskList) ? 0 : taskList.size();
Integer problemCount = CollectionUtil.isEmpty(taskList) ? 0 : taskList.stream().collect(Collectors.summingInt(task-> Optional.ofNullable(task.getProblemNum()).orElse(0)));
projectCountVO.setTaskCount(taskCount);
projectCountVO.setProblemCount(problemCount);
result.add(projectCountVO);
}
return result;
}
```
主要修改内容如下:
1. 加入了通过 Feign 调用 IApplicationServicePlatformClient 接口获取用户有权限的项目列表的逻辑。
2. 修改了遍历项目列表的方式,使用 for 循环而不是 Map.Entry 遍历,方便获取项目名称。
3. 修改了统计任务数和问题数的逻辑,将其移动到遍历项目列表的循环中。
阅读全文