refactor(system): 优化工作日志中部门信息获取逻辑

- 增加对 childDeptIds 是否为空的判断,提高代码健壮性
- 优化部门信息获取逻辑,提高代码可读性和性能
This commit is contained in:
furongxin 2024-11-12 22:29:46 +08:00
parent 83b5f9a27c
commit c3f2b8f9f5

View File

@ -336,12 +336,22 @@ public class LogInstanceServiceImpl implements LogInstanceService {
List<Long> startUserIds = convertList(logInstanceIds, LogReadDO::getStartUserId); List<Long> startUserIds = convertList(logInstanceIds, LogReadDO::getStartUserId);
List<AdminUserDO> adminUserDOS = adminUserService.getUserList(startUserIds); List<AdminUserDO> adminUserDOS = adminUserService.getUserList(startUserIds);
// 获得部门信息 List<Long> deptIds;
List<Long> deptIds = adminUserDOS.stream() if (CollectionUtil.isNotEmpty(childDeptIds)) {
.map(AdminUserDO::getDeptId)
.filter(deptId -> CollectionUtil.isNotEmpty(childDeptIds) && childDeptIds.contains(deptId)) // 获得部门信息
.distinct() deptIds = adminUserDOS.stream()
.collect(Collectors.toList()); .map(AdminUserDO::getDeptId)
.filter(childDeptIds::contains)
.distinct()
.collect(Collectors.toList());
}else {
// 获得部门信息
deptIds = adminUserDOS.stream()
.map(AdminUserDO::getDeptId)
.distinct()
.collect(Collectors.toList());
}
List<DeptDO> deptDOS = deptService.getDeptList(deptIds); List<DeptDO> deptDOS = deptService.getDeptList(deptIds);
return BeanUtils.toBean(deptDOS, DeptRespVO.class); return BeanUtils.toBean(deptDOS, DeptRespVO.class);