Search in sources :

Example 1 with UserInfo

use of com.albedo.java.modules.sys.domain.vo.UserInfo in project albedo by somowhere.

the class UserServiceImpl method getInfo.

/**
 * 通过查用户的全部信息
 *
 * @param userVo 用户
 * @return
 */
@Override
@Transactional(readOnly = true, rollbackFor = Exception.class)
public UserInfo getInfo(UserVo userVo) {
    UserInfo userInfo = new UserInfo();
    userInfo.setUser(userVo);
    List<RoleDo> roleDos = roleService.findListByUserId(userVo.getId());
    // 设置角色列表 (ID)
    List<Long> roleIds = roleDos.stream().map(RoleDo::getId).collect(Collectors.toList());
    userInfo.setRoles(ArrayUtil.toArray(roleIds, Long.class));
    // 设置权限列表(menu.permission)
    Set<String> permissions = new HashSet<>();
    roleIds.forEach(roleId -> {
        List<String> permissionList = menuService.findListByRoleId(roleId).stream().filter(menuVo -> StringUtil.isNotEmpty(menuVo.getPermission())).map(MenuVo::getPermission).collect(Collectors.toList());
        permissions.addAll(permissionList);
    });
    userInfo.setPermissions(ArrayUtil.toArray(permissions, String.class));
    return userInfo;
}
Also used : UserInfo(com.albedo.java.modules.sys.domain.vo.UserInfo) UserRoleDo(com.albedo.java.modules.sys.domain.UserRoleDo) RoleDo(com.albedo.java.modules.sys.domain.RoleDo) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RoleDo (com.albedo.java.modules.sys.domain.RoleDo)1 UserRoleDo (com.albedo.java.modules.sys.domain.UserRoleDo)1 UserInfo (com.albedo.java.modules.sys.domain.vo.UserInfo)1 HashSet (java.util.HashSet)1 Transactional (org.springframework.transaction.annotation.Transactional)1