搜索员工列表中,管理者的UID
Set<Long> leaderSet = new HashSet<>();
List<StaffDto> allUserList = staffService.getByDepartId(xxx, true);
leaderSet = allUserList.stream().filter(staffDto -> {
//该语句块中返回true会添加到set集合中,返回false会继续执行下一条记录
try {
if (staffDto == null) {
return false;
}
StaffDto s = staffService.getByUserId(staffDto.getUserId(), "xxx");
if (s != null && s.getRankName() != null && s.getRankName().contains("M")) {
System.out.println(s.getChineseName());
return true;
}
return false;
} catch (Exception e) {
System.out.println("判断是否为管理层异常" + e);
return false;
}
}).map(udt -> udt.getUserId()).collect(Collectors.toSet());
本文介绍了一种使用Java Stream API从员工列表中筛选出管理者UID的方法。通过过滤并收集满足条件(职位名称包含M)的员工ID到Set集合中实现。有效解决了在大量员工数据中快速定位管理者的问题。
1035

被折叠的 条评论
为什么被折叠?



