检查下面内容并输出正确代码: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<>(); // 将任务按照项目ID分组 Map<String, List<TaskTask>> projectTaskMap = taskTaskList.stream().collect(Collectors.groupingBy(TaskTask::getProjectId)); //查询项目名称 String bspToken = RequestHeaderHolder.getBspToken(); String bspUserId = RequestHeaderHolder.getUserId(); String bspUserEnvId = RequestHeaderHolder.getCompanyId(); String bspUserTenant = RequestHeaderHolder.getCompanyId(); String companyId = RequestHeaderHolder.getCompanyId(); ProjectCondition projectCondition = new ProjectCondition(); projectCondition.setAppId("23031408164321600"); projectCondition.setCompanyId(companyId); projectCondition.setDesignStatusList(Arrays.asList(2,3)); projectCondition.setPageSize(-1); projectCondition.setUserId(bspUserId); QueryAllProject queryAllProject = applicationServicePlatformClientProxy.listUserProject( bspToken, bspUserId, bspUserEnvId, bspUserTenant, projectCondition); // 遍历项目及对应的任务列表 for (Map.Entry<String, List<TaskTask>> projectTaskEntry : projectTaskMap.entrySet()) { projectId = projectTaskEntry.getKey(); ProjectCountVO projectCountVO = new ProjectCountVO(); projectCountVO.setId(projectId); String projectName = queryAllProject.getName(); projectCountVO.setName(projectName); 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; }
时间: 2024-01-22 21:19:22 浏览: 66
以下是正确代码:
```
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<>();
// 将任务按照项目ID分组
Map<String, List<TaskTask>> projectTaskMap = taskTaskList.stream().collect(Collectors.groupingBy(TaskTask::getProjectId));
//查询项目名称
String bspToken = RequestHeaderHolder.getBspToken();
String bspUserId = RequestHeaderHolder.getUserId();
String bspUserEnvId = RequestHeaderHolder.getCompanyId();
String bspUserTenant = RequestHeaderHolder.getCompanyId();
String companyId = RequestHeaderHolder.getCompanyId();
ProjectCondition projectCondition = new ProjectCondition();
projectCondition.setAppId("23031408164321600");
projectCondition.setCompanyId(companyId);
projectCondition.setDesignStatusList(Arrays.asList(2,3));
projectCondition.setPageSize(-1);
projectCondition.setUserId(bspUserId);
QueryAllProject queryAllProject = applicationServicePlatformClientProxy.listUserProject(bspToken, bspUserId, bspUserEnvId, bspUserTenant, projectCondition);
// 遍历项目及对应的任务列表
for (Map.Entry<String, List<TaskTask>> projectTaskEntry : projectTaskMap.entrySet()) {
projectId = projectTaskEntry.getKey();
ProjectCountVO projectCountVO = new ProjectCountVO();
projectCountVO.setId(projectId);
String projectName = queryAllProject.getRecords().stream().filter(p -> p.getId().equals(projectId)).findFirst().orElse(new QueryAllProject.Project()).getName();
projectCountVO.setName(projectName);
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;
}
```
需要注意的是,上述代码中对项目名称的查询有误,已经进行了修正。在查询项目名称时,可以通过查询到的所有项目中找到对应的项目名称。
阅读全文