提交 432b8cb5 authored 作者: hzh's avatar hzh

代码优化

上级 07346019
......@@ -73,6 +73,24 @@ public class SysUserServiceImpl implements ISysUserService {
@Override
public TableDataInfo<SysUserVo> selectPageUserList(SysUserBo user, PageQuery pageQuery) {
Page<SysUserVo> page = baseMapper.selectPageUserList(pageQuery.build(), this.buildQueryWrapper(user));
List<Long> userIds = StreamUtils.toList(page.getRecords(), SysUserVo::getUserId);
userIds = CollectionUtils.isEmpty(userIds) ? List.of(-1L) : userIds;
//获取角色信息
List<SysUserRole> surList = userRoleMapper.selectList(new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getUserId, userIds));
List<SysRole> roleList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(surList)) {
List<Long> roleIds = StreamUtils.toList(surList, SysUserRole::getRoleId);
roleList = roleMapper.selectByIds(roleIds);
}
for (SysUserVo record : page.getRecords()) {
//设置角色信息
List<SysUserRole> roles = StreamUtils.filter(surList, sur -> Objects.equals(sur.getUserId(), record.getUserId()));
if (CollectionUtils.isNotEmpty(roles)) {
List<Long> rIds = StreamUtils.toList(roles, SysUserRole::getRoleId);
List<SysRole> finalRoleList = roleList;
record.setRoles(StreamUtils.toList(rIds, roleId -> BeanUtil.copyProperties(StreamUtils.findFirst(finalRoleList, r -> Objects.equals(r.getRoleId(), roleId)), SysRoleVo.class)));
}
}
return TableDataInfo.build(page);
}
......@@ -115,7 +133,7 @@ public class SysUserServiceImpl implements ISysUserService {
//获取角色信息
List<SysUserRole> surList = userRoleMapper.selectList(new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getUserId, userIds));
List<SysRole> roleList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(supList)) {
if (CollectionUtils.isNotEmpty(surList)) {
List<Long> roleIds = StreamUtils.toList(surList, SysUserRole::getRoleId);
roleList = roleMapper.selectByIds(roleIds);
}
......@@ -141,9 +159,7 @@ public class SysUserServiceImpl implements ISysUserService {
List<SysUserPost> posts = StreamUtils.filter(supList, sup -> Objects.equals(sup.getUserId(), export.getUserId()));
if (CollectionUtils.isNotEmpty(posts)) {
List<Long> pIds = StreamUtils.toList(posts, SysUserPost::getPostId);
export.setPostName(pIds.stream().map(pid -> {
return Optional.ofNullable(StreamUtils.findFirst(finalPostList, p -> Objects.equals(p.getPostId(), pid))).map(SysPost::getPostName).orElse(null);
}).filter(Objects::nonNull).collect(Collectors.joining("/")));
export.setPostName(pIds.stream().map(pid -> Optional.ofNullable(StreamUtils.findFirst(finalPostList, p -> Objects.equals(p.getPostId(), pid))).map(SysPost::getPostName).orElse(null)).filter(Objects::nonNull).collect(Collectors.joining("/")));
}
//设置角色信息
List<SysUserRole> roles = StreamUtils.filter(surList, sur -> Objects.equals(sur.getUserId(), export.getUserId()));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论