根据代码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);” 代码2"@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; try { result = applicationServicePlatformClient.listUserProject(appId, companyId, designStatusList, pageSize, userId); } catch (Exception e) { log.error("调用IApplicationServicePlatformClient获取项目名称失败:", e); throw new BimdcException("调用IApplicationServicePlatformClient获取项目名称失败"); } if (result == null || result.getData() == null) { log.error("调用IApplicationServicePlatformClient获取项目名称失败:result={}", result); throw new BimdcException("调用IApplicationServicePlatformClient获取项目名称失败"); } 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()) { projectId = projectTaskEntry.getKey(); ProjectCountVO projectCountVO = new ProjectCountVO();
时间: 2023-12-03 21:42:08 浏览: 115
SpringBoot通过整合Dubbo解决@Reference注解问题
@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));
IApplicationServicePlatformClient applicationServicePlatformClient = Feign.builder()
.encoder(new JacksonEncoder())
.decoder(new JacksonDecoder())
.target(IApplicationServicePlatformClient.class, "http://localhost:8080");
for (Map.Entry<String, List<TaskTask>> projectTaskEntry : projectTaskMap.entrySet()) {
projectId = projectTaskEntry.getKey();
ProjectCountVO projectCountVO = new ProjectCountVO();
ResultWrapper<QueryAllProject> queryAllProjectResultWrapper = null;
try {
queryAllProjectResultWrapper = applicationServicePlatformClient.listUserProject("BSP_TOKEN", "BSP_USER_ID", "BSP_USER_ENV_ID", "BSP_USER_TENANT", new ProjectCondition(projectId));
} catch (Exception e) {
log.error("调用IApplicationServicePlatformClient获取项目名称失败:", e);
throw new BimdcException("调用IApplicationServicePlatformClient获取项目名称失败");
}
if (queryAllProjectResultWrapper == null || queryAllProjectResultWrapper.getData() == null) {
log.error("调用IApplicationServicePlatformClient获取项目名称失败:result={}", queryAllProjectResultWrapper);
throw new BimdcException("调用IApplicationServicePlatformClient获取项目名称失败");
}
QueryAllProject queryAllProject = queryAllProjectResultWrapper.getData();
if (queryAllProject == null) {
log.error("调用IApplicationServicePlatformClient获取项目名称失败:result={}", queryAllProjectResultWrapper);
throw new BimdcException("调用IApplicationServicePlatformClient获取项目名称失败");
}
String projectName = queryAllProject.getProjectName();
projectCountVO.setProjectName(projectName);
projectCountVO.setProjectId(projectId);
Integer totalCount = projectTaskEntry.getValue().size();
Integer finishCount = (int) projectTaskEntry.getValue().stream().filter(task -> task.getTaskStatus() == TaskStatusEnum.FINISH.getStatus()).count();
projectCountVO.setTotalCount(totalCount);
projectCountVO.setFinishCount(finishCount);
projectCountVO.setUnFinishCount(totalCount - finishCount);
result.add(projectCountVO);
}
return result;
}
```
在代码中,我使用了Feign来调用远程服务,获取项目名称。具体实现是在for循环中,对于每个项目,都调用一次远程服务获取项目名称。注意,这里的远程服务地址我写的是http://localhost:8080,需要根据实际情况进行修改。
阅读全文