|
@@ -87,11 +87,11 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public boolean grant(@NotEmpty List<Long> roleIds, List<Long> menuIds, List<Long> menuClientIds, List<Long> dataScopeIds, List<Long> apiScopeIds, List<Long> tableOwners) {
|
|
|
+ public boolean grant(@NotEmpty List<Long> roleIds, List<String> menuIds, List<String> menuClientIds, List<Long> dataScopeIds, List<Long> apiScopeIds, List<Long> tableOwners) {
|
|
|
return grantRoleMenu(roleIds, menuIds, menuClientIds) && grantDataScope(roleIds, dataScopeIds) && grantApiScope(roleIds, apiScopeIds) && submitRoleAndTableOwner(roleIds, tableOwners);
|
|
|
}
|
|
|
|
|
|
- private boolean grantRoleMenu(List<Long> roleIds, List<Long> menuIds, List<Long> menuClientIds) {
|
|
|
+ private boolean grantRoleMenu(List<Long> roleIds, List<String> menuIds, List<String> menuClientIds) {
|
|
|
// 防止越权配置超管角色
|
|
|
Long administratorCount = baseMapper.selectCount(Wrappers.<Role>query().lambda().eq(Role::getRoleAlias, RoleConstant.ADMINISTRATOR).in(Role::getId, roleIds));
|
|
|
if (!AuthUtil.isAdministrator() && administratorCount > 0L) {
|
|
@@ -110,7 +110,8 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
|
|
|
roleIds.forEach(roleId -> menuIds.forEach(menuId -> {
|
|
|
RoleMenu roleMenu = new RoleMenu();
|
|
|
roleMenu.setRoleId(roleId);
|
|
|
- roleMenu.setMenuId(menuId);
|
|
|
+ roleMenu.setMenuId(Long.valueOf(menuId.split("---")[0]));
|
|
|
+ roleMenu.setStatus(menuId.split("---")[1]);
|
|
|
roleMenus.add(roleMenu);
|
|
|
}));
|
|
|
|
|
@@ -118,7 +119,8 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
|
|
|
roleIds.forEach(roleId -> menuClientIds.forEach(menuIdC -> {
|
|
|
RoleMenu roleMenu = new RoleMenu();
|
|
|
roleMenu.setRoleId(roleId);
|
|
|
- roleMenu.setMenuId(menuIdC);
|
|
|
+ roleMenu.setMenuId(Long.valueOf(menuIdC.split("---")[0]));
|
|
|
+ roleMenu.setStatus(menuIdC.split("---")[1]);
|
|
|
roleMenus.add(roleMenu);
|
|
|
}));
|
|
|
|
|
@@ -132,7 +134,14 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- private void recursionRoleMenu(List<Long> roleIds, List<Long> menuIds) {
|
|
|
+ private void recursionRoleMenu(List<Long> roleIds, List<String> menuIdsAll) {
|
|
|
+ //解析menuIds
|
|
|
+ List<Long> menuIds = new ArrayList<>();
|
|
|
+ for (String menuId : menuIdsAll) {
|
|
|
+ String[] split = menuId.split("---");
|
|
|
+ String id = split[0]; //id
|
|
|
+ menuIds.add(Long.valueOf(id));
|
|
|
+ }
|
|
|
roleIds.forEach(roleId -> baseMapper.selectList(Wrappers.<Role>query().lambda().eq(Role::getParentId, roleId)).forEach(role -> {
|
|
|
List<RoleMenu> roleMenuList = roleMenuService.list(Wrappers.<RoleMenu>query().lambda().eq(RoleMenu::getRoleId, role.getId()));
|
|
|
// 子节点过滤出父节点删除的菜单集合
|
|
@@ -141,7 +150,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
|
|
|
// 删除子节点权限外的菜单集合
|
|
|
roleMenuService.remove(Wrappers.<RoleMenu>update().lambda().eq(RoleMenu::getRoleId, role.getId()).in(RoleMenu::getMenuId, collectRoleMenuIds));
|
|
|
// 递归设置下属角色菜单集合
|
|
|
- recursionRoleMenu(Collections.singletonList(role.getId()), menuIds);
|
|
|
+ recursionRoleMenu(Collections.singletonList(role.getId()), menuIdsAll);
|
|
|
}
|
|
|
}));
|
|
|
}
|