public List<TaskTask> listStatisticsTask(String beginTime, String endTime, Integer forceType, String projectId){ List<TaskTask> taskList = taskTaskService.listStatisticsTask(beginTime, endTime, forceType, projectId); if(CollectionUtil.isEmpty(taskList)){ return Collections.emptyList(); } if(ConstantUtils.ONE.equals(forceType)){ List<RuleContent> forceRuleContentList = modelCheckRuleClientProxy.getForceRuleContentList(); if (CollectionUtil.isEmpty(forceRuleContentList)){ return Collections.emptyList(); } return this.filterTaskIdOfForceRuleContent(taskList, forceRuleContentList.stream().map(RuleContent::getRuleContentId).collect(Collectors.toList())); } return taskList; }
时间: 2024-04-28 21:19:50 浏览: 58
这段代码是一个Java方法,名为`listStatisticsTask`,接受四个参数:`beginTime`、`endTime`、`forceType`和`projectId`。该方法返回一个`List`类型的结果,其中泛型为`TaskTask`。
方法内部首先调用了`taskTaskService`服务的`listStatisticsTask`方法,获取了一个包含`TaskTask`对象的列表。然后判断列表是否为空,如果是,则返回一个空的`Collections.emptyList()`。
如果`forceType`等于1,表示需要进行强制规则检查,那么就调用`modelCheckRuleClientProxy`服务的`getForceRuleContentList`方法获取强制规则列表。如果强制规则列表为空,则返回一个空的`Collections.emptyList()`。
最后,调用`this`对象的`filterTaskIdOfForceRuleContent`方法,将`taskList`和强制规则列表中的规则ID进行筛选,返回筛选后的`TaskTask`对象列表。如果`forceType`不等于1,则直接返回`taskList`。
相关问题
通过接口“applicationServicePlatformClient”在下面代码中调用projectname并打印代码: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); //查询项目名称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; }
您可以这样调用projectname并打印代码:
```java
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);
// 查询项目名称
String projectName = applicationServicePlatformClient.getProjectName(projectId);
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);
}
System.out.println("projectname: " + projectId);
return result;
}
```
在for循环中,我们使用项目ID调用`applicationServicePlatformClient`的`getProjectName`方法,获取项目名称并设置到`ProjectCountVO`对象中。最后,在方法结束前打印`projectId`的值。
检查并修改下面代码:@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); //查询项目名称 String projectName = Optional.ofNullable(applicationServicePlatformClientProxy.queryProjectName(projectId)); 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; }
@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);
//查询项目名称
String projectName = Optional.ofNullable(applicationServicePlatformClientProxy.queryProjectName(projectId)).orElse("");
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;
}
```
修改说明:
1. 在查询项目名称时,应该在 Optional.ofNullable() 后面加上 orElse(""),以避免 projectName 为空时出现 NullPointerException。
2. 对于 Optional.ofNullable(task.getProblemNum()).orElse(0) 这一行代码,建议加上括号以提高可读性。
阅读全文