| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.constant.UserConstants; |
| | | import com.ruoyi.common.core.utils.MapstructUtils; |
| | | import com.ruoyi.common.core.utils.StreamUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.mybatis.core.page.PageQuery; |
| | | import com.ruoyi.system.domain.SysRole; |
| | | import com.ruoyi.common.mybatis.core.page.TableDataInfo; |
| | |
| | | Set<String> permsSet = new HashSet<>(); |
| | | for (SysRoleVo perm : perms) { |
| | | if (ObjectUtil.isNotNull(perm)) { |
| | | permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(","))); |
| | | permsSet.addAll(StringUtils.splitList(perm.getRoleKey().trim())); |
| | | } |
| | | } |
| | | return permsSet; |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public String checkRoleNameUnique(SysRoleBo role) { |
| | | public boolean checkRoleNameUnique(SysRoleBo role) { |
| | | boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysRole>() |
| | | .eq(SysRole::getRoleName, role.getRoleName()) |
| | | .ne(ObjectUtil.isNotNull(role.getRoleId()), SysRole::getRoleId, role.getRoleId())); |
| | | if (exist) { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | return !exist; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public String checkRoleKeyUnique(SysRoleBo role) { |
| | | public boolean checkRoleKeyUnique(SysRoleBo role) { |
| | | boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysRole>() |
| | | .eq(SysRole::getRoleKey, role.getRoleKey()) |
| | | .ne(ObjectUtil.isNotNull(role.getRoleId()), SysRole::getRoleId, role.getRoleId())); |
| | | if (exist) { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | return !exist; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void checkRoleAllowed(SysRoleBo role) { |
| | | if (ObjectUtil.isNotNull(role.getRoleId()) && role.isAdmin()) { |
| | | if (ObjectUtil.isNotNull(role.getRoleId()) && role.isSuperAdmin()) { |
| | | throw new ServiceException("不允许操作超级管理员角色"); |
| | | } |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public void checkRoleDataScope(Long roleId) { |
| | | if (!LoginHelper.isAdmin()) { |
| | | if (!LoginHelper.isSuperAdmin()) { |
| | | SysRoleBo role = new SysRoleBo(); |
| | | role.setRoleId(roleId); |
| | | List<SysRoleVo> roles = this.selectRoleList(role); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int insertRole(SysRoleBo bo) { |
| | | SysRole role = BeanUtil.toBean(bo, SysRole.class); |
| | | SysRole role = MapstructUtils.convert(bo, SysRole.class); |
| | | // 新增角色信息 |
| | | baseMapper.insert(role); |
| | | return insertRoleMenu(role); |
| | | bo.setRoleId(role.getRoleId()); |
| | | return insertRoleMenu(bo); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int updateRole(SysRoleBo bo) { |
| | | SysRole role = BeanUtil.toBean(bo, SysRole.class); |
| | | SysRole role = MapstructUtils.convert(bo, SysRole.class); |
| | | // 修改角色信息 |
| | | baseMapper.updateById(role); |
| | | // 删除角色与菜单关联 |
| | | roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getRoleId, role.getRoleId())); |
| | | return insertRoleMenu(role); |
| | | return insertRoleMenu(bo); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public int updateRoleStatus(SysRoleBo bo) { |
| | | SysRole role = BeanUtil.toBean(bo, SysRole.class); |
| | | SysRole role = MapstructUtils.convert(bo, SysRole.class); |
| | | return baseMapper.updateById(role); |
| | | } |
| | | |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int authDataScope(SysRoleBo bo) { |
| | | SysRole role = BeanUtil.toBean(bo, SysRole.class); |
| | | SysRole role = MapstructUtils.convert(bo, SysRole.class); |
| | | // 修改角色信息 |
| | | baseMapper.updateById(role); |
| | | // 删除角色与部门关联 |
| | | roleDeptMapper.delete(new LambdaQueryWrapper<SysRoleDept>().eq(SysRoleDept::getRoleId, role.getRoleId())); |
| | | // 新增角色和部门信息(数据权限) |
| | | return insertRoleDept(role); |
| | | return insertRoleDept(bo); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param role 角色对象 |
| | | */ |
| | | public int insertRoleMenu(SysRole role) { |
| | | public int insertRoleMenu(SysRoleBo role) { |
| | | int rows = 1; |
| | | // 新增用户与角色管理 |
| | | List<SysRoleMenu> list = new ArrayList<SysRoleMenu>(); |
| | |
| | | * |
| | | * @param role 角色对象 |
| | | */ |
| | | public int insertRoleDept(SysRole role) { |
| | | public int insertRoleDept(SysRoleBo role) { |
| | | int rows = 1; |
| | | // 新增角色与部门(数据权限)管理 |
| | | List<SysRoleDept> list = new ArrayList<SysRoleDept>(); |