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 92fe0c180..e8aa8fd8b 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 @@ -57,4 +57,12 @@ public interface SysMenuServiceApi { */ Map getMenuAppId(List menuIdList); + /** + * 获取指定应用下的所有菜单和功能的id + * + * @author fengshuonan + * @since 2024/10/31 0:22 + */ + Set getAppMenuAndOptionIds(Long appId); + } 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 1caf7ad23..8823245d6 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 @@ -18,6 +18,7 @@ import cn.stylefeng.roses.kernel.sys.api.pojo.menu.UserAppMenuInfo; import cn.stylefeng.roses.kernel.sys.modular.app.service.SysAppService; import cn.stylefeng.roses.kernel.sys.modular.menu.constants.MenuConstants; import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu; +import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions; import cn.stylefeng.roses.kernel.sys.modular.menu.enums.SysMenuExceptionEnum; import cn.stylefeng.roses.kernel.sys.modular.menu.factory.MenuFactory; import cn.stylefeng.roses.kernel.sys.modular.menu.factory.MenuTreeFactory; @@ -25,6 +26,7 @@ import cn.stylefeng.roses.kernel.sys.modular.menu.factory.MenuValidateFactory; import cn.stylefeng.roses.kernel.sys.modular.menu.mapper.SysMenuMapper; import cn.stylefeng.roses.kernel.sys.modular.menu.pojo.request.SysMenuRequest; import cn.stylefeng.roses.kernel.sys.modular.menu.pojo.response.AppGroupDetail; +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.menu.util.MenuOrderFixUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -54,6 +56,9 @@ public class SysMenuServiceImpl extends ServiceImpl impl @Resource(name = "menuCodeCache") private CacheOperatorApi menuCodeCache; + @Resource + private SysMenuOptionsService sysMenuOptionsService; + @Override public void add(SysMenuRequest sysMenuRequest) { @@ -425,6 +430,38 @@ public class SysMenuServiceImpl extends ServiceImpl impl return menuIdAppIdMap; } + @Override + public Set getAppMenuAndOptionIds(Long appId) { + + Set totalIdList = new HashSet<>(); + if (ObjectUtil.isEmpty(appId)) { + return totalIdList; + } + + // 获取应用下的所有菜单id + LambdaQueryWrapper sysMenuLambdaQueryWrapper = new LambdaQueryWrapper<>(); + sysMenuLambdaQueryWrapper.eq(SysMenu::getAppId, appId); + sysMenuLambdaQueryWrapper.select(SysMenu::getMenuId); + List list = this.list(sysMenuLambdaQueryWrapper); + if (ObjectUtil.isEmpty(totalIdList)) { + return totalIdList; + } + Set menuIdList = list.stream().map(SysMenu::getMenuId).collect(Collectors.toSet()); + totalIdList.addAll(menuIdList); + + // 获取应用下的所有功能id + LambdaQueryWrapper optionsLambdaQueryWrapper = new LambdaQueryWrapper<>(); + optionsLambdaQueryWrapper.eq(SysMenuOptions::getAppId, appId); + optionsLambdaQueryWrapper.select(SysMenuOptions::getMenuOptionId); + List optionsList = sysMenuOptionsService.list(optionsLambdaQueryWrapper); + if (ObjectUtil.isNotEmpty(optionsList)) { + Set optionIdList = optionsList.stream().map(SysMenuOptions::getMenuOptionId).collect(Collectors.toSet()); + totalIdList.addAll(optionIdList); + } + + return totalIdList; + } + /** * 获取信息 *