| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.PageQuery; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | |
| | | private SysRoleDeptMapper roleDeptMapper; |
| | | |
| | | @Override |
| | | @DataScope(deptAlias = "d") |
| | | public TableDataInfo<SysRole> selectPageRoleList(SysRole role) { |
| | | return PageUtils.buildDataInfo(baseMapper.selectPageRoleList(PageUtils.buildPage(), role)); |
| | | public TableDataInfo<SysRole> selectPageRoleList(SysRole role, PageQuery pageQuery) { |
| | | Page<SysRole> page = baseMapper.selectPageRoleList(pageQuery.build(), role); |
| | | return TableDataInfo.build(page); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 角色数据集合信息 |
| | | */ |
| | | @Override |
| | | @DataScope(deptAlias = "d") |
| | | public List<SysRole> selectRoleList(SysRole role) { |
| | | return baseMapper.selectRoleList(role); |
| | | } |
| | |
| | | * @return 选中角色ID列表 |
| | | */ |
| | | @Override |
| | | public List<Integer> selectRoleListByUserId(Long userId) { |
| | | public List<Long> selectRoleListByUserId(Long userId) { |
| | | return baseMapper.selectRoleListByUserId(userId); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public String checkRoleNameUnique(SysRole role) { |
| | | Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); |
| | | SysRole info = getOne(new LambdaQueryWrapper<SysRole>() |
| | | .eq(SysRole::getRoleName, role.getRoleName()).last("limit 1")); |
| | | if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) { |
| | | long count = count(new LambdaQueryWrapper<SysRole>() |
| | | .eq(SysRole::getRoleName, role.getRoleName()) |
| | | .ne(SysRole::getRoleId, roleId)); |
| | | if (count > 0) { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | |
| | | @Override |
| | | public String checkRoleKeyUnique(SysRole role) { |
| | | Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); |
| | | SysRole info = getOne(new LambdaQueryWrapper<SysRole>() |
| | | .eq(SysRole::getRoleKey, role.getRoleKey()).last("limit 1")); |
| | | if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) { |
| | | long count = count(new LambdaQueryWrapper<SysRole>() |
| | | .eq(SysRole::getRoleKey, role.getRoleKey()) |
| | | .ne(SysRole::getRoleId, roleId)); |
| | | if (count > 0) { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int insertRole(SysRole role) { |
| | | // 新增角色信息 |
| | | baseMapper.insert(role); |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int updateRole(SysRole role) { |
| | | // 修改角色信息 |
| | | baseMapper.updateById(role); |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int authDataScope(SysRole role) { |
| | | // 修改角色信息 |
| | | baseMapper.updateById(role); |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int deleteRoleById(Long roleId) { |
| | | // 删除角色与菜单关联 |
| | | roleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getRoleId, roleId)); |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int deleteRoleByIds(Long[] roleIds) { |
| | | for (Long roleId : roleIds) { |
| | | checkRoleAllowed(new SysRole(roleId)); |