根据代码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 17:07:17 浏览: 166
代码修改如下:
```
@Override
public List<ProjectCountVO> projectCount(String beginTime, String endTime, Integer forceType, String projectId) {
// 调用远程 Feign 接口获取统计数据
ProjectCondition queryProjectDto = new ProjectCondition();
queryProjectDto.setBeginTime(beginTime);
queryProjectDto.setEndTime(endTime);
queryProjectDto.setForceType(forceType);
queryProjectDto.setProjectId(projectId);
ResultWrapper<QueryAllProject> resultWrapper = iApplicationServicePlatformClient.listUserProject("bspToken", "bspUserId", "bspUserEnvId", "bspUserTenant", queryProjectDto);
List<TaskTask> taskTaskList = resultWrapper.getData().getList();
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;
}
```
修改后的代码中,我们通过调用 Feign 接口,从远程服务获取数据。在调用 Feign 接口时,我们需要传递一些请求头参数,比如 `BSP_TOKEN`、`BSP_USER_ID` 等,这些参数可以根据实际情况进行修改。获取到数据后,我们再按照原来的逻辑进行统计和计算,最终返回结果。
阅读全文