【7.6.0】【sys】【permission】封装获取所有叶子菜单方法

pull/55/MERGE
fengshuonan 2023-06-13 16:59:36 +08:00
parent 65b58f1f66
commit c8a2e3800e
2 changed files with 116 additions and 0 deletions

View File

@ -0,0 +1,69 @@
package cn.stylefeng.roses.kernel.sys.modular.role.factory;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu;
import cn.stylefeng.roses.kernel.sys.modular.role.enums.PermissionNodeTypeEnum;
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.response.RoleBindPermissionItem;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
*
*
* @author fengshuonan
* @since 2023/6/13 16:30
*/
public class PermissionAssignFactory {
/**
*
* <p>
*
*
* @author fengshuonan
* @since 2023/6/13 16:32
*/
public static List<RoleBindPermissionItem> createPermissionMenus(List<SysMenu> sysMenus) {
if (ObjectUtil.isEmpty(sysMenus)) {
return new ArrayList<>();
}
// 搜集所有的父级菜单id
Set<Long> totalParentMenuId = sysMenus.stream().map(SysMenu::getMenuParentId).collect(Collectors.toSet());
// 通过父级菜单,筛选出来所有的叶子节点(如果菜单不存在父级菜单里,则代表是叶子节点)
Set<SysMenu> leafMenus = sysMenus.stream().filter(item -> !totalParentMenuId.contains(item)).collect(Collectors.toSet());
// 叶子节点转化为RoleBindPermissionItem结构
ArrayList<RoleBindPermissionItem> roleBindPermissionItems = new ArrayList<>();
for (SysMenu leafMenu : leafMenus) {
RoleBindPermissionItem roleBindPermissionItem = new RoleBindPermissionItem();
// 设置节点id和名称为菜单id和菜单名称
roleBindPermissionItem.setNodeId(leafMenu.getMenuId());
roleBindPermissionItem.setNodeName(leafMenu.getMenuName());
// 设置节点类型为2-菜单
roleBindPermissionItem.setPermissionNodeType(PermissionNodeTypeEnum.MENU.getCode());
// 父级id是应用id
roleBindPermissionItem.setNodeParentId(leafMenu.getAppId());
// 默认未选中
roleBindPermissionItem.setChecked(false);
// 设置空子集
roleBindPermissionItem.setChildren(new ArrayList<>());
roleBindPermissionItems.add(roleBindPermissionItem);
}
return roleBindPermissionItems;
}
}

View File

@ -1,8 +1,20 @@
package cn.stylefeng.roses.kernel.sys.modular.role.service.impl;
import cn.stylefeng.roses.kernel.sys.modular.app.entity.SysApp;
import cn.stylefeng.roses.kernel.sys.modular.app.service.SysAppService;
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu;
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuService;
import cn.stylefeng.roses.kernel.sys.modular.role.factory.PermissionAssignFactory;
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.RoleBindPermissionRequest;
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.response.RoleBindPermissionItem;
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.response.RoleBindPermissionResponse;
import cn.stylefeng.roses.kernel.sys.modular.role.service.PermissionAssignService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
*
@ -12,6 +24,11 @@ import cn.stylefeng.roses.kernel.sys.modular.role.service.PermissionAssignServic
*/
public class PermissionAssignServiceImpl implements PermissionAssignService {
@Resource
private SysMenuService sysMenuService;
@Resource
private SysAppService sysAppService;
@Override
public RoleBindPermissionResponse getRoleBindPermission(RoleBindPermissionRequest roleBindPermissionRequest) {
@ -28,6 +45,36 @@ public class PermissionAssignServiceImpl implements PermissionAssignService {
@Override
public RoleBindPermissionResponse createSelectTreeStructure() {
// 最顶层,代表是否全选
RoleBindPermissionResponse roleBindPermissionResponse = new RoleBindPermissionResponse();
roleBindPermissionResponse.setChecked(false);
// 获取所有的菜单
LambdaQueryWrapper<SysMenu> menuLambdaQueryWrapper = new LambdaQueryWrapper<>();
menuLambdaQueryWrapper.select(SysMenu::getMenuId, SysMenu::getMenuName, SysMenu::getMenuParentId, SysMenu::getAppId);
menuLambdaQueryWrapper.orderByAsc(SysMenu::getMenuSort);
List<SysMenu> totalMenus = this.sysMenuService.list(menuLambdaQueryWrapper);
// 组装所有的叶子节点菜单
List<RoleBindPermissionItem> totalResultMenus = PermissionAssignFactory.createPermissionMenus(totalMenus);
// 查询菜单对应的所有应用
Set<String> appIdList = totalResultMenus.stream().map(RoleBindPermissionItem::getNodeParentId).collect(Collectors.toSet());
LambdaQueryWrapper<SysApp> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(SysApp::getAppId, SysApp::getAppName);
List<SysApp> totalAppList = sysAppService.list(queryWrapper);
// 组装所有的应用节点信息
// 获取所有的菜单上的功能
// 获取菜单对应的应用
return null;
}