| | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.sandu.common.enums.RoleLevelStatus; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.execption.EntityExistException; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | |
| | | Role role = new Role(); |
| | | role.setName(param.getName()); |
| | | role.setRemark(param.getRemark()); |
| | | role.setLevel(2); |
| | | role.setLevel(RoleLevelStatus.COMMON.getCode()); |
| | | if(!save(role)){ |
| | | throw new BusinessException("添加角色失败"); |
| | | } |
| | |
| | | } |
| | | assertLevels(role.getLevel()); |
| | | Role update = new Role(); |
| | | update.setId(roleId); |
| | | update.setName(param.getName()); |
| | | update.setRemark(param.getRemark()); |
| | | if(!updateById(update)){ |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | private int assertLevels(Integer level) { |
| | | /** |
| | | * 判断当前角色能不能操作目标用户 不行的话直接抛出异常 |
| | | * @param roleLevel 目标用户的最大角色 |
| | | * @return |
| | | */ |
| | | public int assertLevels(Integer roleLevel) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | List<Role> roles = listByAdminId(userId); |
| | | if(CollectionUtil.isEmpty(roles)){ |
| | |
| | | } |
| | | List<Integer> levels = roles.stream().map(Role::getLevel).collect(Collectors.toList()); |
| | | int min = Collections.min(levels); |
| | | if (level != null) { |
| | | if (level < min) { |
| | | throw new BusinessException("权限不足,你的角色级别:" + min + ",低于操作的角色级别:" + level); |
| | | if (roleLevel != null) { |
| | | if (roleLevel < min) { |
| | | throw new BusinessException("权限不足,你的角色级别:" + min + ",低于操作的角色级别:" + roleLevel); |
| | | } |
| | | } |
| | | return min; |