2021与蓝度共同重构项目,服务端
liuhaonan
2022-03-09 fc34005a2bb11d57a9d7eba2ae9f1b7492d570d1
ximon-admin/src/main/java/com/sandu/ximon/admin/service/MenuService.java
@@ -35,6 +35,7 @@
public class MenuService extends BaseServiceImpl<MenuMapper, Menu> {
    private final RoleMenuRelationService roleMenuRelationService;
    /**
     * 获取角色下的菜单
     */
@@ -49,7 +50,8 @@
    public boolean addMenu(MenuParam param) {
        Menu menu = new Menu();
        BeanUtils.copyProperties(param,menu);
        BeanUtils.copyProperties(param, menu);
        menu.setPermission(param.getRouterName());
        return save(menu);
    }
@@ -78,7 +80,7 @@
        return node;
    }
    public boolean updateMenu(Long menuId,MenuParam param) {
    public boolean updateMenu(Long menuId, MenuParam param) {
        Menu one = getById(menuId);
        if (one == null) {
            throw new BusinessException("找不到菜单信息");
@@ -86,12 +88,13 @@
        List<Role> roles = SpringContextHolder.getBean(RoleService.class).listByAdminId(SecurityUtils.getUserId());
        Integer roleLevel = roles.stream().map(Role::getLevel).min(Integer::compareTo).orElse(RoleLevelStatus.COMMON.getCode());
        if(!RoleLevelStatus.SUPER.getCode().equals(roleLevel)){
        if (!RoleLevelStatus.SUPER.getCode().equals(roleLevel)) {
            throw new BusinessException("超级管理员才可以编辑菜单");
        }
        Menu menu = new Menu();
        BeanUtils.copyProperties(param,menu);
        BeanUtils.copyProperties(param, menu);
        menu.setPermission(param.getRouterName());
        menu.setId(menuId);
        return updateById(menu);
    }
@@ -103,6 +106,8 @@
                .map(menu -> covertMenuNode(menu, list)).collect(Collectors.toList());
    }
    private MenuMapper menuMapper;
    public boolean delMenu(Long menuId) {
        Menu one = getById(menuId);
        if (one == null) {
@@ -111,9 +116,17 @@
        List<Role> roles = SpringContextHolder.getBean(RoleService.class).listByAdminId(SecurityUtils.getUserId());
        Integer roleLevel = roles.stream().map(Role::getLevel).min(Integer::compareTo).orElse(RoleLevelStatus.COMMON.getCode());
        if(!RoleLevelStatus.SUPER.getCode().equals(roleLevel)){
        if (!RoleLevelStatus.SUPER.getCode().equals(roleLevel)) {
            throw new BusinessException("超级管理员才可以删除菜单");
        }
        return removeById(menuId);
        List<Long> list = menuMapper.listMenuIfBinding(menuId);
        List<Long> list1 = menuMapper.listMenuIfBinding1(menuId);
        if (list.size() == 0 && list1.size() == 0) {
            return removeById(menuId);
        } else {
            throw new BusinessException("菜单正在使用,请勿删除");
        }
    }
}