根据接口“”@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);和代码“@Component @Slf4j public class ApplicationServicePlatformClientProxy { @Autowired private IApplicationServicePlatformClient applicationServicePlatformClient; public QueryAllProject listUserProject(String appId, String companyId, String designStatusList, String pageSize, ProjectCondition userId) { ResultWrapper<QueryAllProject> result = null; return result.getData(); } }”,修改下面代码:@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()) { String currentProjectId = projectTaskEntry.getKey(); ProjectCountVO projectCountVO = new ProjectCountVO(); projectCountVO.setId(currentProjectId); // 查询项目名称 QueryAllProject queryAllProject = applicationServicePlatformClient.listUserProject(); 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; }
时间: 2023-12-10 21:40:41 浏览: 64
根据你提供的代码,我们可以看出,在方法中调用了接口中的listUserProject方法来获取项目名称,但是在调用该方法时需要传入一个参数,即ProjectCondition类型的参数queryProjectDto,而在代码中并没有传入该参数,因此需要在调用该方法时传入该参数,例如:
```
QueryAllProject queryAllProject = applicationServicePlatformClient.listUserProject(bspToken, bspUserId, bspUserEnvId, bspUserTenant, queryProjectDto);
String projectName = queryAllProject.getProjectName();
```
其中,bspToken、bspUserId、bspUserEnvId、bspUserTenant是请求头中的参数,queryProjectDto是一个实例化后的ProjectCondition对象。
相关问题
根据代码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; }
代码修改如下:
```
@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. 修改了统计任务数和问题数的逻辑,将其移动到遍历项目列表的循环中。
阅读全文