diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysMenuServiceApi.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysMenuServiceApi.java index e8aa8fd8b..0fe974352 100644 --- a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysMenuServiceApi.java +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysMenuServiceApi.java @@ -65,4 +65,23 @@ public interface SysMenuServiceApi { */ Set getAppMenuAndOptionIds(Long appId); + /** + * 获取所有菜单的id和父级id的映射关系 + * + * @return 菜单id和父级id的映射关系 + * @author fengshuonan + * @since 2024/6/24 12:38 + */ + Map getMenuIdParentIdMap(); + + /** + * 获取菜单下的所有功能 + * + * @param menuId 指定菜单id + * @param roleLimitMenuIdsAndOptionIds 被限制的功能和id集合 + * @author fengshuonan + * @since 2024/10/31 9:51 + */ + List getMenuOptions(Long menuId, Set roleLimitMenuIdsAndOptionIds); + } diff --git a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/factory/MenuPathCalcFactory.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/factory/MenuPathCalcFactory.java similarity index 96% rename from kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/factory/MenuPathCalcFactory.java rename to kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/factory/MenuPathCalcFactory.java index 1b24f58d4..94fa61923 100644 --- a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/factory/MenuPathCalcFactory.java +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/factory/MenuPathCalcFactory.java @@ -1,4 +1,4 @@ -package cn.stylefeng.roses.kernel.sys.modular.menu.factory; +package cn.stylefeng.roses.kernel.sys.api.factory; import cn.stylefeng.roses.kernel.rule.constants.TreeConstants; diff --git a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/SysMenuService.java b/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/SysMenuService.java index 517138868..5924dbfc8 100644 --- a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/SysMenuService.java +++ b/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/SysMenuService.java @@ -7,7 +7,6 @@ import cn.stylefeng.roses.kernel.sys.modular.menu.pojo.response.AppGroupDetail; import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; -import java.util.Map; import java.util.Set; /** @@ -125,15 +124,6 @@ public interface SysMenuService extends IService, SysMenuServiceApi { */ List getMenuCodeList(List menuIdList); - /** - * 获取所有菜单的id和父级id的映射关系 - * - * @return 菜单id和父级id的映射关系 - * @author fengshuonan - * @since 2024/6/24 12:38 - */ - Map getMenuIdParentIdMap(); - /** * 将指定的菜单补全父级菜单 *

diff --git a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/impl/SysMenuServiceImpl.java b/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/impl/SysMenuServiceImpl.java index 8823245d6..5ac223168 100644 --- a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/impl/SysMenuServiceImpl.java +++ b/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/impl/SysMenuServiceImpl.java @@ -290,6 +290,21 @@ public class SysMenuServiceImpl extends ServiceImpl impl return sysMenuList.stream().collect(Collectors.toMap(SysMenu::getMenuId, SysMenu::getMenuParentId)); } + @Override + public List getMenuOptions(Long menuId, Set roleLimitMenuIdsAndOptionIds) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(SysMenuOptions::getMenuId, menuId); + if (ObjectUtil.isNotEmpty(roleLimitMenuIdsAndOptionIds)) { + queryWrapper.in(SysMenuOptions::getMenuOptionId, roleLimitMenuIdsAndOptionIds); + } + queryWrapper.select(SysMenuOptions::getMenuOptionId); + List list = sysMenuOptionsService.list(queryWrapper); + if (ObjectUtil.isEmpty(list)) { + return new ArrayList<>(); + } + return list.stream().map(SysMenuOptions::getMenuOptionId).collect(Collectors.toList()); + } + @Override public List completeParentMenu(List menuList) { if (ObjectUtil.isEmpty(menuList)) { diff --git a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/RoleBindMenuImpl.java b/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/RoleBindMenuImpl.java index 7aaac9bf6..25f31be19 100644 --- a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/RoleBindMenuImpl.java +++ b/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/RoleBindMenuImpl.java @@ -3,9 +3,8 @@ package cn.stylefeng.roses.kernel.sys.modular.role.service.impl; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.ObjectUtil; import cn.stylefeng.roses.kernel.sys.api.enums.PermissionNodeTypeEnum; +import cn.stylefeng.roses.kernel.sys.api.factory.MenuPathCalcFactory; import cn.stylefeng.roses.kernel.sys.api.pojo.role.request.RoleBindPermissionRequest; -import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions; -import cn.stylefeng.roses.kernel.sys.modular.menu.factory.MenuPathCalcFactory; import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuOptionsService; import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuService; import cn.stylefeng.roses.kernel.sys.modular.role.action.RoleAssignOperateAction; @@ -26,7 +25,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; /** * 角色绑定菜单的相关操作 @@ -91,7 +89,7 @@ public class RoleBindMenuImpl implements RoleAssignOperateAction, RoleBindLimitA } // 2.1. 查询菜单下的所有菜单功能 - List menuOptions = this.getMenuOptions(menuId, roleLimitMenuIdsAndOptionIds); + List menuOptions = this.sysMenuService.getMenuOptions(menuId, roleLimitMenuIdsAndOptionIds); // 菜单下没有菜单功能,则直接返回 if (ObjectUtil.isEmpty(menuOptions)) { @@ -150,7 +148,7 @@ public class RoleBindMenuImpl implements RoleAssignOperateAction, RoleBindLimitA } // 2.1. 查询菜单下的所有菜单功能 - List menuOptionsIds = this.getMenuOptions(menuId); + List menuOptionsIds = this.sysMenuService.getMenuOptions(menuId, null); // 菜单下没有菜单功能,则直接返回 if (ObjectUtil.isEmpty(menuOptionsIds)) { @@ -178,34 +176,4 @@ public class RoleBindMenuImpl implements RoleAssignOperateAction, RoleBindLimitA this.sysRoleLimitService.saveBatch(sysRoleLimitTotal); } - /** - * 获取菜单下的所有菜单功能 - * - * @author fengshuonan - * @since 2023/9/8 16:02 - */ - private List getMenuOptions(Long menuId) { - return this.getMenuOptions(menuId, null); - } - - /** - * 获取菜单下的所有菜单功能 - * - * @author fengshuonan - * @since 2023/9/8 16:02 - */ - private List getMenuOptions(Long menuId, Set roleLimitMenuIdsAndOptionIds) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(SysMenuOptions::getMenuId, menuId); - if (ObjectUtil.isNotEmpty(roleLimitMenuIdsAndOptionIds)) { - queryWrapper.in(SysMenuOptions::getMenuOptionId, roleLimitMenuIdsAndOptionIds); - } - queryWrapper.select(SysMenuOptions::getMenuOptionId); - List list = sysMenuOptionsService.list(queryWrapper); - if (ObjectUtil.isEmpty(list)) { - return new ArrayList<>(); - } - return list.stream().map(SysMenuOptions::getMenuOptionId).collect(Collectors.toList()); - } - }