From 5b9f87937feb53890138dbcd3a94cd883997e950 Mon Sep 17 00:00:00 2001 From: houzhongjian <houzhongyi@126.com> Date: 星期四, 26 十二月 2024 16:32:44 +0800 Subject: [PATCH] 修改菜单报错bug --- iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/permission/PermissionServiceImpl.java | 67 +++++++++++++++++---------------- 1 files changed, 35 insertions(+), 32 deletions(-) diff --git a/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/permission/PermissionServiceImpl.java b/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/permission/PermissionServiceImpl.java index a4deaf4..0ad56ef 100644 --- a/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/permission/PermissionServiceImpl.java +++ b/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/permission/PermissionServiceImpl.java @@ -172,34 +172,34 @@ // ========== 角色-菜单的相关方法 ========== - @Override - @DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换 - @CacheEvict(value = RedisKeyConstants.MENU_ROLE_ID_LIST, - allEntries = true) // allEntries 清空所有缓存,主要一次更新涉及到的 menuIds 较多,反倒批量会更快 - public void assignRoleAppMenu(Long roleId, Set<Long> menuIds) { - // 获得角色拥有应用菜单编号 - MenuListReqVO reqVO = new MenuListReqVO(); - List<MenuDO> appMenuList = menuService.getAppMenuList(reqVO); - Set<Long> appMenuIds = convertSet(appMenuList, MenuDO::getId); - Set<Long> dbMenuIds = convertSet(roleMenuMapper.selectListByRoleId(roleId), RoleMenuDO::getMenuId); - dbMenuIds.retainAll(appMenuIds); - // 计算新增和删除的菜单编号 - Set<Long> menuIdList = CollUtil.emptyIfNull(menuIds); - Collection<Long> createMenuIds = CollUtil.subtract(menuIdList, dbMenuIds); - Collection<Long> deleteMenuIds = CollUtil.subtract(dbMenuIds, menuIdList); - // 执行新增和删除。对于已经授权的菜单,不用做任何处理 - if (CollUtil.isNotEmpty(createMenuIds)) { - roleMenuMapper.insertBatch(CollectionUtils.convertList(createMenuIds, menuId -> { - RoleMenuDO entity = new RoleMenuDO(); - entity.setRoleId(roleId); - entity.setMenuId(menuId); - return entity; - })); - } - if (CollUtil.isNotEmpty(deleteMenuIds)) { - roleMenuMapper.deleteListByRoleIdAndMenuIds(roleId, deleteMenuIds); - } - } +// @Override +// @DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换 +// @CacheEvict(value = RedisKeyConstants.MENU_ROLE_ID_LIST, +// allEntries = true) // allEntries 清空所有缓存,主要一次更新涉及到的 menuIds 较多,反倒批量会更快 +// public void assignRoleAppMenu(Long roleId, Set<Long> menuIds) { +// // 获得角色拥有应用菜单编号 +// MenuListReqVO reqVO = new MenuListReqVO(); +// List<MenuDO> appMenuList = menuService.getAppMenuList(reqVO); +// Set<Long> appMenuIds = convertSet(appMenuList, MenuDO::getId); +// Set<Long> dbMenuIds = convertSet(roleMenuMapper.selectListByRoleId(roleId), RoleMenuDO::getMenuId); +// dbMenuIds.retainAll(appMenuIds); +// // 计算新增和删除的菜单编号 +// Set<Long> menuIdList = CollUtil.emptyIfNull(menuIds); +// Collection<Long> createMenuIds = CollUtil.subtract(menuIdList, dbMenuIds); +// Collection<Long> deleteMenuIds = CollUtil.subtract(dbMenuIds, menuIdList); +// // 执行新增和删除。对于已经授权的菜单,不用做任何处理 +// if (CollUtil.isNotEmpty(createMenuIds)) { +// roleMenuMapper.insertBatch(CollectionUtils.convertList(createMenuIds, menuId -> { +// RoleMenuDO entity = new RoleMenuDO(); +// entity.setRoleId(roleId); +// entity.setMenuId(menuId); +// return entity; +// })); +// } +// if (CollUtil.isNotEmpty(deleteMenuIds)) { +// roleMenuMapper.deleteListByRoleIdAndMenuIds(roleId, deleteMenuIds); +// } +// } @Override @Transactional(rollbackFor = Exception.class) @@ -227,6 +227,10 @@ if (CollUtil.isEmpty(roleIds)) { return Collections.emptySet(); } + // 如果是管理员的情况下,获取全部菜单编号 + if (roleService.hasAnySuperAdmin(roleIds)) { + return convertSet(menuService.getMenuList(), MenuDO::getId); + } return convertSet(roleMenuMapper.selectListByRoleId(roleIds), RoleMenuDO::getMenuId); } @@ -235,15 +239,14 @@ if (CollUtil.isEmpty(roleIds)) { return Collections.emptySet(); } - + // 获取 tenantId + Long tenantId = getTenantId(); // 如果是管理员的情况下,获取全部应用菜单编号 if (roleService.hasAnySuperAdmin(roleIds)) { MenuListReqVO reqVO = new MenuListReqVO(); - return convertSet(menuService.getAppMenuList(reqVO), MenuDO::getId); + return convertSet(menuService.getAppMenuList(tenantId, reqVO), MenuDO::getId); } // 如果是非管理员的情况下,获得拥有的应用菜单编号 - // 获取 tenantId - Long tenantId = getTenantId(); TenantDO tenant = tenantService.getTenant(tenantId); TenantPackageDO tenantPackage = tenantPackageService.getTenantPackage(tenant.getPackageId()); Set<Long> menuIds = tenantPackage.getMenuIds(); -- Gitblit v1.9.3