mirror of https://gitee.com/stylefeng/roses
【7.2.5】【role】更新角色绑定操作权限接口
parent
6a3efaa7b6
commit
88d744e5ad
|
@ -108,4 +108,12 @@ public interface MenuServiceApi {
|
|||
*/
|
||||
List<MenuAndButtonTreeResponse> getRoleBindMenuList(SysRoleRequest sysRoleRequest);
|
||||
|
||||
/**
|
||||
* 获取角色绑定的操作权限列表
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/9/28 17:26
|
||||
*/
|
||||
List<MenuAndButtonTreeResponse> getRoleBindOperateList(SysRoleRequest sysRoleRequest);
|
||||
|
||||
}
|
||||
|
|
|
@ -217,4 +217,16 @@ public class SysMenuController {
|
|||
return new SuccessResponseData<>(treeResponseList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色分配操作权限,绑定情况列表
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/9/28 17:23
|
||||
*/
|
||||
@GetResource(name = "获取角色分配操作权限,绑定情况列表", path = "/sysMenu/roleBindOperateList")
|
||||
public ResponseData<List<MenuAndButtonTreeResponse>> roleBindOperateList(@Validated(SysRoleRequest.roleBindMenuList.class) SysRoleRequest sysRoleRequest) {
|
||||
List<MenuAndButtonTreeResponse> treeResponseList = menuServiceApi.getRoleBindOperateList(sysRoleRequest);
|
||||
return new SuccessResponseData<>(treeResponseList);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,10 +41,8 @@ import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenu;
|
|||
import cn.stylefeng.roses.kernel.system.modular.menu.entity.SysMenuButton;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 针对于antd vue版本的前端菜单的组装
|
||||
|
@ -246,6 +244,52 @@ public class AntdMenusFactory {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将按钮集成到菜单列表里,并且只返回一级结构
|
||||
*
|
||||
* @param sysMenuList 菜单集合,包含一级菜单,一级菜单内
|
||||
* @param buttonList 菜单下的操作权限集合
|
||||
* @author fengshuonan
|
||||
* @date 2022/9/28 18:00
|
||||
*/
|
||||
public static List<MenuAndButtonTreeResponse> fillButtons(List<SysMenu> sysMenuList, List<SysMenuButton> buttonList) {
|
||||
List<MenuAndButtonTreeResponse> result = new ArrayList<>();
|
||||
|
||||
for (SysMenu sysMenu : sysMenuList) {
|
||||
|
||||
MenuAndButtonTreeResponse menuAndButtonTreeResponse = new MenuAndButtonTreeResponse();
|
||||
menuAndButtonTreeResponse.setId(sysMenu.getMenuId());
|
||||
menuAndButtonTreeResponse.setName(sysMenu.getMenuName());
|
||||
menuAndButtonTreeResponse.setCode(sysMenu.getMenuCode());
|
||||
menuAndButtonTreeResponse.setPid(sysMenu.getMenuParentId());
|
||||
menuAndButtonTreeResponse.setChecked(false);
|
||||
|
||||
// 获取当前菜单下的所有菜单id
|
||||
List<SysMenu> children = sysMenu.getChildren();
|
||||
Set<Long> totalMenusIds = children.stream().map(SysMenu::getMenuId).collect(Collectors.toSet());
|
||||
totalMenusIds.add(sysMenu.getMenuId());
|
||||
|
||||
// 转化按钮的所属菜单id
|
||||
ArrayList<MenuAndButtonTreeResponse> buttons = new ArrayList<>();
|
||||
for (SysMenuButton sysMenuButton : buttonList) {
|
||||
for (Long menuIdItem : totalMenusIds) {
|
||||
if (sysMenuButton.getMenuId().equals(menuIdItem)) {
|
||||
MenuAndButtonTreeResponse buttonItem = new MenuAndButtonTreeResponse();
|
||||
buttonItem.setId(sysMenuButton.getButtonId());
|
||||
buttonItem.setName(sysMenuButton.getButtonName());
|
||||
buttonItem.setCode(sysMenuButton.getButtonCode());
|
||||
buttonItem.setChecked(false);
|
||||
buttons.add(buttonItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
menuAndButtonTreeResponse.setButtons(buttons);
|
||||
result.add(menuAndButtonTreeResponse);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类过的用户菜单,返回一个menus数组,并且第一个是激活的应用
|
||||
*
|
||||
|
@ -329,4 +373,26 @@ public class AntdMenusFactory {
|
|||
return antdSysMenuDTO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充按钮的选中标识
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/9/28 18:19
|
||||
*/
|
||||
public static List<MenuAndButtonTreeResponse> fillButtonsChecked(List<MenuAndButtonTreeResponse> menuAndButtonTreeResponses, List<SysRoleMenuButtonDTO> roleMenuButtonList) {
|
||||
|
||||
// 遍历所有菜单中的按钮,将选中标识加上
|
||||
for (MenuAndButtonTreeResponse menuAndButtonTreeResponse : menuAndButtonTreeResponses) {
|
||||
List<MenuAndButtonTreeResponse> buttons = menuAndButtonTreeResponse.getButtons();
|
||||
for (MenuAndButtonTreeResponse button : buttons) {
|
||||
for (SysRoleMenuButtonDTO sysRoleMenuButtonDTO : roleMenuButtonList) {
|
||||
if (sysRoleMenuButtonDTO.getButtonId().equals(button.getId())) {
|
||||
button.setChecked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return menuAndButtonTreeResponses;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -481,43 +481,33 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
@Override
|
||||
public List<MenuAndButtonTreeResponse> getRoleBindMenuList(SysRoleRequest sysRoleRequest) {
|
||||
|
||||
// 查询所有菜单列表,根据前台传递参数,可选择前台还是后台菜单
|
||||
LambdaQueryWrapper<SysMenu> menuWrapper = new LambdaQueryWrapper<>();
|
||||
menuWrapper.eq(SysMenu::getDelFlag, YesOrNotEnum.N.getCode());
|
||||
menuWrapper.eq(SysMenu::getStatusFlag, StatusEnum.ENABLE.getCode());
|
||||
menuWrapper.eq(SysMenu::getAntdvFrontType, AntdvFrontTypeEnum.FRONT.getCode());
|
||||
List<SysMenu> sysMenuList = this.list(menuWrapper);
|
||||
// 获取所有一级菜单,子菜单包含在children内
|
||||
List<SysMenu> sysMenus = totalMenusWithOneLevel();
|
||||
|
||||
// 获取角色绑定的菜单
|
||||
List<SysRoleMenuDTO> roleMenuList = roleServiceApi.getRoleMenuList(Collections.singletonList(sysRoleRequest.getRoleId()));
|
||||
|
||||
// 将所有节点转化成树结构,整体只要两级结构,一级是一级菜单,第二级是所有以下菜单
|
||||
Map<Long, SysMenu> firstLevelMenus = new HashMap<>();
|
||||
|
||||
// 找到所有第一级的菜单
|
||||
for (SysMenu sysMenu : sysMenuList) {
|
||||
if (TreeConstants.DEFAULT_PARENT_ID.equals(sysMenu.getMenuParentId())) {
|
||||
firstLevelMenus.put(sysMenu.getMenuId(), sysMenu);
|
||||
}
|
||||
}
|
||||
|
||||
// 找到所有二级和以下菜单,并添加到一级菜单以下
|
||||
for (Map.Entry<Long, SysMenu> menuEntry : firstLevelMenus.entrySet()) {
|
||||
SysMenu firstLevelMenuItem = menuEntry.getValue();
|
||||
List<SysMenu> children = firstLevelMenuItem.getChildren();
|
||||
if (children == null) {
|
||||
children = new ArrayList<>();
|
||||
firstLevelMenuItem.setChildren(children);
|
||||
}
|
||||
for (SysMenu sysMenu : sysMenuList) {
|
||||
if (sysMenu.getMenuPids().contains("[" + firstLevelMenuItem.getMenuId() + "]")) {
|
||||
children.add(sysMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 将组装好的一级菜单和里边的children都转化为响应对象,并填充checked标识
|
||||
return AntdMenusFactory.parseMenuAndButtonTreeResponseWithChildren(ListUtil.toList(firstLevelMenus.values()), roleMenuList);
|
||||
return AntdMenusFactory.parseMenuAndButtonTreeResponseWithChildren(sysMenus, roleMenuList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuAndButtonTreeResponse> getRoleBindOperateList(SysRoleRequest sysRoleRequest) {
|
||||
|
||||
// 获取所有一级菜单,子菜单包含在children内
|
||||
List<SysMenu> sysMenus = totalMenusWithOneLevel();
|
||||
|
||||
// 查询这些菜单对应的所有按钮
|
||||
LambdaQueryWrapper<SysMenuButton> buttonWrapper = new LambdaQueryWrapper<>();
|
||||
buttonWrapper.eq(SysMenuButton::getDelFlag, YesOrNotEnum.N.getCode());
|
||||
List<SysMenuButton> buttonList = sysMenuButtonService.list(buttonWrapper);
|
||||
|
||||
// 将组装好的一级菜单和里边的children都转化为响应对象
|
||||
List<MenuAndButtonTreeResponse> menuAndButtonTreeResponses = AntdMenusFactory.fillButtons(sysMenus, buttonList);
|
||||
|
||||
// 填充checked对象
|
||||
List<SysRoleMenuButtonDTO> roleMenuButtonList = roleServiceApi.getRoleMenuButtonList(Collections.singletonList(sysRoleRequest.getRoleId()));
|
||||
return AntdMenusFactory.fillButtonsChecked(menuAndButtonTreeResponses, roleMenuButtonList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -818,4 +808,46 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
return newPids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的菜单,以一级菜单的形式展示
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/9/28 17:46
|
||||
*/
|
||||
private List<SysMenu> totalMenusWithOneLevel() {
|
||||
// 查询所有菜单列表,根据前台传递参数,可选择前台还是后台菜单
|
||||
LambdaQueryWrapper<SysMenu> menuWrapper = new LambdaQueryWrapper<>();
|
||||
menuWrapper.eq(SysMenu::getDelFlag, YesOrNotEnum.N.getCode());
|
||||
menuWrapper.eq(SysMenu::getStatusFlag, StatusEnum.ENABLE.getCode());
|
||||
menuWrapper.eq(SysMenu::getAntdvFrontType, AntdvFrontTypeEnum.FRONT.getCode());
|
||||
List<SysMenu> sysMenuList = this.list(menuWrapper);
|
||||
|
||||
// 将所有节点转化成树结构,整体只要两级结构,一级是一级菜单,第二级是所有以下菜单
|
||||
Map<Long, SysMenu> firstLevelMenus = new HashMap<>();
|
||||
|
||||
// 找到所有第一级的菜单
|
||||
for (SysMenu sysMenu : sysMenuList) {
|
||||
if (TreeConstants.DEFAULT_PARENT_ID.equals(sysMenu.getMenuParentId())) {
|
||||
firstLevelMenus.put(sysMenu.getMenuId(), sysMenu);
|
||||
}
|
||||
}
|
||||
|
||||
// 找到所有二级和以下菜单,并添加到一级菜单以下
|
||||
for (Map.Entry<Long, SysMenu> menuEntry : firstLevelMenus.entrySet()) {
|
||||
SysMenu firstLevelMenuItem = menuEntry.getValue();
|
||||
List<SysMenu> children = firstLevelMenuItem.getChildren();
|
||||
if (children == null) {
|
||||
children = new ArrayList<>();
|
||||
firstLevelMenuItem.setChildren(children);
|
||||
}
|
||||
for (SysMenu sysMenu : sysMenuList) {
|
||||
if (sysMenu.getMenuPids().contains("[" + firstLevelMenuItem.getMenuId() + "]")) {
|
||||
children.add(sysMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ListUtil.toList(firstLevelMenus.values());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue