| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 角色 业务层处理 |
| | |
| | | List<SysRoleVo> userRoles = baseMapper.selectRolesByUserId(userId); |
| | | List<SysRoleVo> roles = selectRoleAll(); |
| | | // 使用HashSet提高查找效率 |
| | | Set<Long> userRoleIds = userRoles.stream().map(SysRoleVo::getRoleId).collect(Collectors.toSet()); |
| | | Set<Long> userRoleIds = StreamUtils.toSet(userRoles, SysRoleVo::getRoleId); |
| | | for (SysRoleVo role : roles) { |
| | | if (userRoleIds.contains(role.getRoleId())) { |
| | | role.setFlag(true); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int updateRole(SysRoleBo bo) { |
| | | SysRole role = MapstructUtils.convert(bo, SysRole.class); |
| | | |
| | | if (UserConstants.ROLE_DISABLE.equals(role.getStatus()) && this.countUserRoleByRoleId(role.getRoleId()) > 0) { |
| | | throw new ServiceException("角色已分配,不能禁用!"); |
| | | } |
| | | // 修改角色信息 |
| | | baseMapper.updateById(role); |
| | | // 删除角色与菜单关联 |