| | |
| | | package com.se.system.service.impl; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.se.common.core.utils.StringUtils; |
| | | import com.se.system.domain.SysPost; |
| | | import com.se.system.mapper.SysPostMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | |
| | | import com.se.system.service.ISysPermissionService; |
| | | import com.se.system.service.ISysRoleService; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * 用户权限处理 |
| | | * |
| | | * @author admin |
| | | */ |
| | | @Service |
| | | public class SysPermissionServiceImpl implements ISysPermissionService |
| | | { |
| | | public class SysPermissionServiceImpl implements ISysPermissionService { |
| | | @Autowired |
| | | private ISysRoleService roleService; |
| | | |
| | | @Autowired |
| | | private ISysMenuService menuService; |
| | | |
| | | @Resource |
| | | private SysPostMapper postMapper; |
| | | |
| | | /** |
| | | * 获取角色数据权限 |
| | | * |
| | | * |
| | | * @param userId 用户Id |
| | | * @return 角色权限信息 |
| | | */ |
| | | @Override |
| | | public Set<String> getRolePermission(SysUser user) |
| | | { |
| | | public Set<String> getRolePermission(SysUser user) { |
| | | Set<String> roles = new HashSet<String>(); |
| | | // 管理员拥有所有权限 |
| | | if (user.isAdmin()) |
| | | { |
| | | if (user.isAdmin()) { |
| | | roles.add("admin"); |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | roles.addAll(roleService.selectRolePermissionByUserId(user.getUserId())); |
| | | } |
| | | return roles; |
| | |
| | | |
| | | /** |
| | | * 获取菜单数据权限 |
| | | * |
| | | * |
| | | * @param userId 用户Id |
| | | * @return 菜单权限信息 |
| | | */ |
| | | @Override |
| | | public Set<String> getMenuPermission(SysUser user) |
| | | { |
| | | public Set<String> getMenuPermission(SysUser user) { |
| | | Set<String> perms = new HashSet<String>(); |
| | | // 管理员拥有所有权限 |
| | | if (user.isAdmin()) |
| | | { |
| | | if (user.isAdmin()) { |
| | | perms.add("*:*:*"); |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | List<SysRole> roles = user.getRoles(); |
| | | if (!CollectionUtils.isEmpty(roles)) |
| | | { |
| | | if (!CollectionUtils.isEmpty(roles)) { |
| | | // 多角色设置permissions属性,以便数据权限匹配权限 |
| | | for (SysRole role : roles) |
| | | { |
| | | for (SysRole role : roles) { |
| | | Set<String> rolePerms = menuService.selectMenuPermsByRoleId(role.getRoleId()); |
| | | role.setPermissions(rolePerms); |
| | | perms.addAll(rolePerms); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | perms.addAll(menuService.selectMenuPermsByUserId(user.getUserId())); |
| | | } |
| | | } |
| | | return perms; |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getPostPermission(SysUser user) { |
| | | List<SysPost> list = postMapper.selectPostsByUserName(user.getUserName()); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return null; |
| | | } |
| | | |
| | | return list.stream().map(SysPost::getPostName).collect(Collectors.toList()); |
| | | } |
| | | } |