如何将代码1“String bspToken = RequestHeaderHolder.getBspToken(); String bspUserId = RequestHeaderHolder.getUserId(); String bspUserEnvId = RequestHeaderHolder.getCompanyId(); String bspUserTenant = RequestHeaderHolder.getCompanyId(); String companyId = RequestHeaderHolder.getCompanyId(); ProjectCondition queryProjectDto = new ProjectCondition(); queryProjectDto.setAppId(queryProjectDto.getAppId()); queryProjectDto.setCompanyId(companyId); queryProjectDto.setDesignStatusList(Arrays.asList(2,3)); queryProjectDto.setPageSize(-1); queryProjectDto.setUserId(bspUserId); List<QueryAllProject> queryAllProject = applicationServicePlatformClientProxy.listUserProject(bspToken, bspUserId, bspUserEnvId, bspUserTenant, queryProjectDto);”,合并到代码2“@Component @Slf4j public class ApplicationServicePlatformClientProxy { @Autowired private IApplicationServicePlatformClient applicationServicePlatformClient; public List<QueryAllProject> listUserProject(String bspToken, String bspUserId, String bspUserEnvId, String bspUserTenant, ProjectCondition queryProjectDto) { QueryOut<Page<QueryAllProject>> result = null; try { result = applicationServicePlatformClient.listUserProject(bspToken, bspUserId, bspUserEnvId, bspUserTenant, queryProjectDto); log.info("result={}", JSON.toJSONString(result)); } 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().getData(); } }”
时间: 2024-02-18 13:01:40 浏览: 61
将代码1中的内容放到代码2中的方法中,即在方法中添加以下代码:
```
String companyId = queryProjectDto.getCompanyId();
queryProjectDto.setCompanyId(companyId);
List<QueryAllProject> queryAllProject = null;
try {
queryAllProject = listUserProject(bspToken, bspUserId, bspUserEnvId, bspUserTenant, queryProjectDto);
} catch (Exception e) {
log.error("调用ApplicationServicePlatformClientProxy获取项目名称失败:", e);
throw new BimdcException("调用ApplicationServicePlatformClientProxy获取项目名称失败");
}
```
这样就可以在代码2中调用代码1中的内容了。
相关问题
检查下面代码并打印正确代码: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; }
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.getEnvId();
String bspUserTenant = RequestHeaderHolder.getTenant();
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.getProjects().stream()
.filter(project -> project.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;
}
阅读全文