use of com.hb0730.boot.admin.project.system.permission.model.entity.PermissionEntity in project boot-admin by hb0730.
the class MenuEventListener method findMenuByUser.
private List<TreeMenuDTO> findMenuByUser(UserDTO user) {
if (null == user) {
return null;
}
if (user.getIsAdmin() == 1) {
MenuParams params = new MenuParams();
params.setSortType(SortTypeEnum.ASC.getValue());
params.setSortColumn(Collections.singletonList(MenuEntity.SORT));
QueryWrapper<MenuEntity> query = QueryWrapperUtils.getQuery(params);
List<MenuEntity> entities = menuService.list(query);
return BeanUtil.copyToList(entities, TreeMenuDTO.class);
}
Collection<Long> permissionIds = user.getPermissionIds();
if (CollectionUtils.isEmpty(permissionIds)) {
return Lists.newArrayList();
}
LambdaQueryWrapper<PermissionEntity> queryWrapper = Wrappers.lambdaQuery(PermissionEntity.class).in(PermissionEntity::getId, permissionIds).select(PermissionEntity::getMenuId, PermissionEntity::getPermission);
// 权限
List<PermissionEntity> permissionEntities = ((UserInfoServiceImpl) userInfoService.getThis()).getPermissionService().list(queryWrapper);
if (CollectionUtils.isEmpty(permissionEntities)) {
return Lists.newArrayList();
}
Map<Long, List<String>> permissionMapping = permissionEntities.stream().collect(Collectors.groupingBy(PermissionEntity::getMenuId, Collectors.mapping(PermissionEntity::getPermission, Collectors.toList())));
// 菜单
List<Long> menuIds = permissionEntities.parallelStream().map(PermissionEntity::getMenuId).collect(Collectors.toList());
Set<MenuEntity> entities = Sets.newHashSet();
for (Long menuId : menuIds) {
entities.addAll(menuService.getSuperior(menuId, Lists.newArrayList()));
}
List<MenuEntity> menuEntities = entities.stream().sorted(Comparator.comparing(MenuEntity::getSort)).collect(Collectors.toList());
List<TreeMenuDTO> treeMenu = BeanUtil.copyToList(menuEntities, TreeMenuDTO.class);
for (TreeMenuDTO menu : treeMenu) {
menu.setAuthority(permissionMapping.get(menu.getId()));
}
return treeMenu;
}
use of com.hb0730.boot.admin.project.system.permission.model.entity.PermissionEntity in project boot-admin by hb0730.
the class RolePermissionServiceImpl method savePermissionIdByRoleId.
@Override
@Transactional(rollbackFor = Exception.class)
public boolean savePermissionIdByRoleId(@Nonnull Long id, @Nonnull Collection<Long> permissionIds) {
Assert.notNull(id, "角色id为空");
Assert.notEmpty(permissionIds, "权限id为空");
LambdaQueryWrapper<PermissionEntity> queryWrapper = Wrappers.lambdaQuery(PermissionEntity.class).in(PermissionEntity::getId, permissionIds).select(PermissionEntity::getId);
List<PermissionEntity> entities = permissionMapper.selectList(queryWrapper);
if (CollectionUtils.isEmpty(entities)) {
throw new BusinessException("请传入正确的权限id");
}
Set<Long> ids = entities.parallelStream().map(PermissionEntity::getId).collect(Collectors.toSet());
List<RolePermissionEntity> rolePermissionEntities = new ArrayList<>(ids.size());
for (Long permissionId : ids) {
RolePermissionEntity entity = new RolePermissionEntity();
entity.setPermissionId(permissionId);
entity.setRoleId(id);
rolePermissionEntities.add(entity);
}
return super.saveBatch(rolePermissionEntities);
}
use of com.hb0730.boot.admin.project.system.permission.model.entity.PermissionEntity in project boot-admin by hb0730.
the class UserInfoServiceImpl method loadUserByUsername.
@Override
public UserDTO loadUserByUsername(String username) {
UserAccountEntity accountEntity = accountService.findUserAccountByUsername(username);
if (null == accountEntity) {
return null;
}
Long userId = accountEntity.getUserId();
UserInfoEntity entity = super.getById(userId);
UserDTO user = BeanUtil.toBean(entity, UserDTO.class);
assert user != null;
user.setUsername(accountEntity.getUsername());
user.setPassword(accountEntity.getPassword());
// 用户角色
Collection<Long> roleIds = userRoleService.findRoleByUserId(userId);
if (CollectionUtils.isEmpty(roleIds)) {
return user;
}
List<RoleEntity> roles = roleService.findEnabledRoleByIds(roleIds);
if (CollectionUtils.isEmpty(roles)) {
return user;
}
Map<Long, String> roleMap = roles.parallelStream().collect(Collectors.toMap(RoleEntity::getId, RoleEntity::getCode));
user.setRoleIds(roleMap.keySet());
user.setRole(roleMap.values());
// 权限
Map<Long, List<Long>> permission = rolePermissionService.findPermissionIdByRoleId(roleIds);
if (CollectionUtils.isEmpty(permission)) {
return user;
}
Set<Long> permissionIds = permission.values().stream().flatMap(List::stream).collect(Collectors.toSet());
List<PermissionEntity> permissionEntities = permissionService.findEnabledPermissionByIds(permissionIds);
if (CollectionUtils.isEmpty(permissionEntities)) {
return user;
}
Map<Long, String> permissionMap = permissionEntities.parallelStream().collect(Collectors.toMap(PermissionEntity::getId, PermissionEntity::getPermission));
user.setPermission(permissionMap.values());
user.setPermissionIds(permissionMap.keySet());
// 岗位
List<Long> postIds = userPostService.findPostIdByUserIds(Collections.singletonList(userId));
user.setPostIds(postIds);
return user;
}
use of com.hb0730.boot.admin.project.system.permission.model.entity.PermissionEntity in project boot-admin by hb0730.
the class MenuServiceImpl method queryMenuPermissionTree.
@Override
public List<MenuPermissionVO> queryMenuPermissionTree() {
List<PermissionEntity> permissionEntities = permissionMapper.selectList(null);
List<MenuEntity> entities = super.list();
List<MenuPermissionVO> trees = new ArrayList<>();
for (MenuEntity menuEntity : entities) {
MenuPermissionVO menuPermission = new MenuPermissionVO();
if (menuEntity.getParentId() == null || menuEntity.getParentId() == -1) {
menuPermission.setId(menuEntity.getId());
menuPermission.setName(menuEntity.getTitle());
menuPermission.setIsPermission(false);
trees.add(menuPermission);
}
for (MenuEntity entity : entities) {
if (menuEntity.getId().equals(entity.getParentId())) {
if (menuPermission.getChildren() == null) {
menuPermission.setChildren(new ArrayList<>());
}
MenuPermissionVO menuPermissionInfo = new MenuPermissionVO();
menuPermissionInfo.setName(entity.getTitle());
menuPermissionInfo.setId(entity.getId());
menuPermissionInfo.setIsPermission(false);
menuPermission.getChildren().add(menuPermissionInfo);
// 权限
List<PermissionEntity> permissionList = permissionEntities.stream().filter(e -> e.getMenuId().equals(entity.getId())).collect(Collectors.toList());
for (PermissionEntity permissionEntity : permissionList) {
MenuPermissionVO permission = new MenuPermissionVO();
permission.setIsPermission(true);
permission.setId(permissionEntity.getId());
permission.setName(permissionEntity.getName());
if (menuPermissionInfo.getChildren() == null) {
menuPermissionInfo.setChildren(new ArrayList<>());
}
menuPermissionInfo.getChildren().add(permission);
}
}
}
}
return trees;
}
Aggregations