| | |
| | | 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.conditions.update.LambdaUpdateWrapper; |
| | | 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.exception.ServiceException; |
| | | 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; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.satoken.utils.LoginHelper; |
| | | import com.ruoyi.system.domain.SysRole; |
| | | import com.ruoyi.system.domain.SysRoleDept; |
| | | import com.ruoyi.system.domain.SysRoleMenu; |
| | | import com.ruoyi.system.domain.SysUserRole; |
| | |
| | | .like(StringUtils.isNotBlank(bo.getRoleKey()), "r.role_key", bo.getRoleKey()) |
| | | .between(params.get("beginTime") != null && params.get("endTime") != null, |
| | | "r.create_time", params.get("beginTime"), params.get("endTime")) |
| | | .orderByAsc("r.role_sort"); |
| | | .orderByAsc("r.role_sort").orderByAsc("r.create_time");; |
| | | return wrapper; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public SysRoleVo selectRoleById(Long roleId) { |
| | | return baseMapper.selectVoById(roleId); |
| | | return baseMapper.selectRoleById(roleId); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | | * 校验角色是否允许操作 |
| | | * |
| | | * @param role 角色信息 |
| | | * @param roleId 角色ID |
| | | */ |
| | | @Override |
| | | public void checkRoleAllowed(SysRoleBo role) { |
| | | if (ObjectUtil.isNotNull(role.getRoleId()) && role.isSuperAdmin()) { |
| | | public void checkRoleAllowed(Long roleId) { |
| | | if (ObjectUtil.isNotNull(roleId) && LoginHelper.isSuperAdmin(roleId)) { |
| | | throw new ServiceException("不允许操作超级管理员角色"); |
| | | } |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public void checkRoleDataScope(Long roleId) { |
| | | if (!LoginHelper.isSuperAdmin()) { |
| | | SysRoleBo role = new SysRoleBo(); |
| | | role.setRoleId(roleId); |
| | | List<SysRoleVo> roles = this.selectRoleList(role); |
| | | if (CollUtil.isEmpty(roles)) { |
| | | throw new ServiceException("没有权限访问角色数据!"); |
| | | } |
| | | if (ObjectUtil.isNull(roleId)) { |
| | | return; |
| | | } |
| | | if (LoginHelper.isSuperAdmin()) { |
| | | return; |
| | | } |
| | | List<SysRoleVo> roles = this.selectRoleList(new SysRoleBo(roleId)); |
| | | if (CollUtil.isEmpty(roles)) { |
| | | throw new ServiceException("没有权限访问角色数据!"); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | @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); |
| | | 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); |
| | | // 删除角色与菜单关联 |
| | |
| | | /** |
| | | * 修改角色状态 |
| | | * |
| | | * @param bo 角色信息 |
| | | * @param roleId 角色ID |
| | | * @param status 角色状态 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateRoleStatus(SysRoleBo bo) { |
| | | SysRole role = BeanUtil.toBean(bo, SysRole.class); |
| | | return baseMapper.updateById(role); |
| | | public int updateRoleStatus(Long roleId, String status) { |
| | | return baseMapper.update(null, |
| | | new LambdaUpdateWrapper<SysRole>() |
| | | .set(SysRole::getStatus, status) |
| | | .eq(SysRole::getRoleId, roleId)); |
| | | } |
| | | |
| | | /** |
| | |
| | | @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); |
| | | // 删除角色与部门关联 |
| | |
| | | * |
| | | * @param role 角色对象 |
| | | */ |
| | | public int insertRoleMenu(SysRoleBo role) { |
| | | private int insertRoleMenu(SysRoleBo role) { |
| | | int rows = 1; |
| | | // 新增用户与角色管理 |
| | | List<SysRoleMenu> list = new ArrayList<SysRoleMenu>(); |
| | |
| | | * |
| | | * @param role 角色对象 |
| | | */ |
| | | public int insertRoleDept(SysRoleBo role) { |
| | | private int insertRoleDept(SysRoleBo role) { |
| | | int rows = 1; |
| | | // 新增角色与部门(数据权限)管理 |
| | | List<SysRoleDept> list = new ArrayList<SysRoleDept>(); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int deleteRoleByIds(Long[] roleIds) { |
| | | for (Long roleId : roleIds) { |
| | | checkRoleAllowed(new SysRoleBo(roleId)); |
| | | checkRoleAllowed(roleId); |
| | | checkRoleDataScope(roleId); |
| | | SysRole role = baseMapper.selectById(roleId); |
| | | if (countUserRoleByRoleId(roleId) > 0) { |