Search in sources :

Example 1 with SysRole

use of com.hccake.ballcat.system.model.entity.SysRole in project ballcat by ballcat-projects.

the class SysUserServiceImpl method findUserInfo.

/**
 * 通过查用户的全部信息
 * @param sysUser 用户
 * @return 用户信息
 */
@Override
public UserInfoDTO findUserInfo(SysUser sysUser) {
    UserInfoDTO userInfoDTO = new UserInfoDTO();
    userInfoDTO.setSysUser(sysUser);
    // 超级管理员拥有所有角色
    List<SysRole> roleList;
    if (adminUserChecker.isAdminUser(sysUser)) {
        roleList = sysRoleService.list();
    } else {
        roleList = sysUserRoleService.listRoles(sysUser.getUserId());
    }
    // 设置角色标识
    Set<String> roleCodes = new HashSet<>();
    for (SysRole role : roleList) {
        roleCodes.add(role.getCode());
    }
    userInfoDTO.setRoles(new HashSet<>(roleList));
    userInfoDTO.setRoleCodes(roleCodes);
    // 设置权限列表(permission)
    Set<String> permissions = new HashSet<>();
    Set<SysMenu> menus = new HashSet<>();
    for (String roleCode : roleCodes) {
        List<SysMenu> sysMenuList = sysMenuService.listByRoleCode(roleCode);
        menus.addAll(sysMenuList);
        List<String> permissionList = sysMenuList.stream().map(SysMenu::getPermission).filter(StrUtil::isNotEmpty).collect(Collectors.toList());
        permissions.addAll(permissionList);
    }
    userInfoDTO.setMenus(menus);
    userInfoDTO.setPermissions(permissions);
    return userInfoDTO;
}
Also used : SysMenu(com.hccake.ballcat.system.model.entity.SysMenu) SysRole(com.hccake.ballcat.system.model.entity.SysRole) UserInfoDTO(com.hccake.ballcat.system.model.dto.UserInfoDTO)

Example 2 with SysRole

use of com.hccake.ballcat.system.model.entity.SysRole in project ballcat by ballcat-projects.

the class SysUserController method getUserRoleIds.

/**
 * 获取用户 所拥有的角色ID
 * @param userId userId
 */
@GetMapping("/scope/{userId}")
@PreAuthorize("@per.hasPermission('system:user:grant')")
public R<SysUserScope> getUserRoleIds(@PathVariable("userId") Integer userId) {
    List<SysRole> roleList = sysUserRoleService.listRoles(userId);
    List<String> roleCodes = new ArrayList<>();
    if (CollectionUtil.isNotEmpty(roleList)) {
        roleList.forEach(role -> roleCodes.add(role.getCode()));
    }
    SysUserScope sysUserScope = new SysUserScope();
    sysUserScope.setRoleCodes(roleCodes);
    return R.ok(sysUserScope);
}
Also used : SysUserScope(com.hccake.ballcat.system.model.dto.SysUserScope) SysRole(com.hccake.ballcat.system.model.entity.SysRole) ArrayList(java.util.ArrayList) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with SysRole

use of com.hccake.ballcat.system.model.entity.SysRole in project ballcat by ballcat-projects.

the class SysRoleServiceImpl method removeById.

/**
 * 通过角色ID,删除角色,并清空角色菜单缓存
 * @param id 角色ID
 * @return boolean
 */
@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeById(Serializable id) {
    SysRole role = getById(id);
    sysRoleMenuService.deleteByRoleCode(role.getCode());
    return SqlHelper.retBool(baseMapper.deleteById(id));
}
Also used : SysRole(com.hccake.ballcat.system.model.entity.SysRole) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SysRole (com.hccake.ballcat.system.model.entity.SysRole)3 SysUserScope (com.hccake.ballcat.system.model.dto.SysUserScope)1 UserInfoDTO (com.hccake.ballcat.system.model.dto.UserInfoDTO)1 SysMenu (com.hccake.ballcat.system.model.entity.SysMenu)1 ArrayList (java.util.ArrayList)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 Transactional (org.springframework.transaction.annotation.Transactional)1