| | |
| | | import org.dromara.common.mybatis.core.page.TableDataInfo; |
| | | import org.dromara.common.mybatis.helper.DataBaseHelper; |
| | | import org.dromara.common.satoken.utils.LoginHelper; |
| | | import org.dromara.system.domain.SysDept; |
| | | import org.dromara.system.domain.SysUser; |
| | | import org.dromara.system.domain.SysUserPost; |
| | | import org.dromara.system.domain.SysUserRole; |
| | | import org.dromara.system.domain.*; |
| | | import org.dromara.system.domain.bo.SysUserBo; |
| | | import org.dromara.system.domain.vo.SysPostVo; |
| | | import org.dromara.system.domain.vo.SysRoleVo; |
| | |
| | | */ |
| | | private void insertUserRole(Long userId, Long[] roleIds, boolean clear) { |
| | | if (ArrayUtil.isNotEmpty(roleIds)) { |
| | | // 判断是否具有此角色的操作权限 |
| | | List<SysRoleVo> roles = roleMapper.selectRoleList(new LambdaQueryWrapper<>()); |
| | | if (CollUtil.isEmpty(roles)) { |
| | | throw new ServiceException("没有权限访问角色的数据"); |
| | | } |
| | | List<Long> roleList = StreamUtils.toList(roles, SysRoleVo::getRoleId); |
| | | List<Long> roleList = new ArrayList<>(List.of(roleIds)); |
| | | if (!LoginHelper.isSuperAdmin(userId)) { |
| | | roleList.remove(UserConstants.SUPER_ADMIN_ID); |
| | | } |
| | | List<Long> canDoRoleList = StreamUtils.filter(List.of(roleIds), roleList::contains); |
| | | if (CollUtil.isEmpty(canDoRoleList)) { |
| | | // 判断是否具有此角色的操作权限 |
| | | List<SysRoleVo> roles = roleMapper.selectRoleList( |
| | | new QueryWrapper<SysRole>().in("r.role_id", roleList)); |
| | | if (CollUtil.isEmpty(roles)) { |
| | | throw new ServiceException("没有权限访问角色的数据"); |
| | | } |
| | | if (clear) { |
| | |
| | | userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, userId)); |
| | | } |
| | | // 新增用户与角色管理 |
| | | List<SysUserRole> list = StreamUtils.toList(canDoRoleList, roleId -> { |
| | | List<SysUserRole> list = StreamUtils.toList(roleList, roleId -> { |
| | | SysUserRole ur = new SysUserRole(); |
| | | ur.setUserId(userId); |
| | | ur.setRoleId(roleId); |