diff --git a/kernel-s-sys/sys-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysMenuServiceApi.java b/kernel-s-sys/sys-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysMenuServiceApi.java index e5da05a87..92fe0c180 100644 --- a/kernel-s-sys/sys-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysMenuServiceApi.java +++ b/kernel-s-sys/sys-api/src/main/java/cn/stylefeng/roses/kernel/sys/api/SysMenuServiceApi.java @@ -27,6 +27,7 @@ package cn.stylefeng.roses.kernel.sys.api; import cn.stylefeng.roses.kernel.sys.api.pojo.menu.UserAppMenuInfo; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -47,4 +48,13 @@ public interface SysMenuServiceApi { */ List getUserAppMenuDetailList(Set menuIdList); + /** + * 获取菜单对应的应用id(可以批量获取) + * + * @return key是菜单id,value是应用id + * @author fengshuonan + * @since 2023/6/26 21:47 + */ + Map getMenuAppId(List menuIdList); + } diff --git a/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/SysMenuService.java b/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/SysMenuService.java index fdf7318a5..53336c5da 100644 --- a/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/SysMenuService.java +++ b/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/SysMenuService.java @@ -1,5 +1,6 @@ package cn.stylefeng.roses.kernel.sys.modular.menu.service; +import cn.stylefeng.roses.kernel.sys.api.SysMenuServiceApi; import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu; import cn.stylefeng.roses.kernel.sys.modular.menu.pojo.request.SysMenuRequest; import cn.stylefeng.roses.kernel.sys.modular.menu.pojo.response.AppGroupDetail; @@ -14,7 +15,7 @@ import java.util.Set; * @author fengshuonan * @date 2023/06/10 21:28 */ -public interface SysMenuService extends IService { +public interface SysMenuService extends IService, SysMenuServiceApi { /** * 新增 @@ -69,14 +70,6 @@ public interface SysMenuService extends IService { */ boolean validateMenuBindApp(Set appIdList); - /** - * 获取菜单的所属appId - * - * @author fengshuonan - * @since 2023/6/13 22:49 - */ - Long getMenuAppId(Long menuId); - /** * 获取所有的菜单信息,用在角色绑定权限界面 * diff --git a/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/impl/SysMenuOptionsServiceImpl.java b/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/impl/SysMenuOptionsServiceImpl.java index 69f73ae23..2cd64883b 100644 --- a/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/impl/SysMenuOptionsServiceImpl.java +++ b/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/impl/SysMenuOptionsServiceImpl.java @@ -1,6 +1,7 @@ package cn.stylefeng.roses.kernel.sys.modular.menu.service.impl; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.ObjectUtil; import cn.stylefeng.roses.kernel.db.api.factory.PageFactory; import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory; @@ -24,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -53,7 +55,8 @@ public class SysMenuOptionsServiceImpl extends ServiceImpl menuAppId = sysMenuService.getMenuAppId(ListUtil.list(false, sysMenuOptionsRequest.getMenuId())); + Long appId = menuAppId.get(sysMenuOptionsRequest.getMenuId()); sysMenuOptions.setAppId(appId); this.save(sysMenuOptions); diff --git a/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/impl/SysMenuServiceImpl.java b/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/impl/SysMenuServiceImpl.java index 5f6240f8b..c9d0178b3 100644 --- a/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/impl/SysMenuServiceImpl.java +++ b/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/menu/service/impl/SysMenuServiceImpl.java @@ -9,7 +9,6 @@ import cn.stylefeng.roses.kernel.rule.constants.SymbolConstant; import cn.stylefeng.roses.kernel.rule.constants.TreeConstants; import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException; import cn.stylefeng.roses.kernel.rule.tree.buildpids.PidStructureBuildUtil; -import cn.stylefeng.roses.kernel.sys.api.SysMenuServiceApi; import cn.stylefeng.roses.kernel.sys.api.callback.RemoveMenuCallbackApi; import cn.stylefeng.roses.kernel.sys.api.pojo.menu.UserAppMenuInfo; import cn.stylefeng.roses.kernel.sys.modular.app.service.SysAppService; @@ -28,10 +27,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; /** @@ -41,7 +37,7 @@ import java.util.stream.Collectors; * @date 2023/06/10 21:28 */ @Service -public class SysMenuServiceImpl extends ServiceImpl implements SysMenuService, SysMenuServiceApi { +public class SysMenuServiceImpl extends ServiceImpl implements SysMenuService { @Resource private SysAppService sysAppService; @@ -127,19 +123,6 @@ public class SysMenuServiceImpl extends ServiceImpl impl return count > 0; } - @Override - public Long getMenuAppId(Long menuId) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(SysMenu::getMenuId, menuId); - queryWrapper.select(SysMenu::getAppId); - SysMenu one = this.getOne(queryWrapper, false); - if (one != null) { - return one.getAppId(); - } else { - return null; - } - } - @Override public List getTotalMenus() { LambdaQueryWrapper menuLambdaQueryWrapper = new LambdaQueryWrapper<>(); @@ -281,6 +264,34 @@ public class SysMenuServiceImpl extends ServiceImpl impl return result; } + @Override + public Map getMenuAppId(List menuIdList) { + + // 定义返回结果 + HashMap menuIdAppIdMap = new HashMap<>(); + + if (ObjectUtil.isEmpty(menuIdList)) { + return menuIdAppIdMap; + } + + // 查询数据库菜单id对应的应用id集合 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.in(SysMenu::getMenuId, menuIdList); + queryWrapper.select(SysMenu::getAppId); + List queryList = this.list(queryWrapper); + + if (ObjectUtil.isEmpty(queryList)) { + return menuIdAppIdMap; + } + + // 制作映射关系 + for (SysMenu sysMenu : queryList) { + menuIdAppIdMap.put(sysMenu.getMenuId(), sysMenu.getAppId()); + } + + return menuIdAppIdMap; + } + /** * 获取信息 * diff --git a/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/SysRoleMenuServiceImpl.java b/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/SysRoleMenuServiceImpl.java index e1575c230..aac8b51b1 100644 --- a/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/SysRoleMenuServiceImpl.java +++ b/kernel-s-sys/sys-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/SysRoleMenuServiceImpl.java @@ -1,6 +1,7 @@ package cn.stylefeng.roses.kernel.sys.modular.role.service.impl; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.ObjectUtil; import cn.stylefeng.roses.kernel.db.api.factory.PageFactory; import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory; @@ -32,6 +33,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -169,7 +171,8 @@ public class SysRoleMenuServiceImpl extends ServiceImpl menuAppIdMap = sysMenuService.getMenuAppId(ListUtil.list(false, menuId)); + Long appId = menuAppIdMap.get(menuId); sysRoleMenu.setAppId(appId); // 2. 查询菜单下所有的菜单功能