mirror of https://gitee.com/stylefeng/roses
【8.3.1】【menu】抽离出来获取应用菜单的接口
parent
14a84d92b5
commit
41ca429a43
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.sys.api;
|
||||
|
||||
import cn.stylefeng.roses.kernel.sys.api.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.menu.UserAppMenuInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -84,4 +85,24 @@ public interface SysMenuServiceApi {
|
|||
*/
|
||||
List<Long> getMenuOptions(Long menuId, Set<Long> roleLimitMenuIdsAndOptionIds);
|
||||
|
||||
/**
|
||||
* 获取应用下的所有菜单id
|
||||
*
|
||||
* @param appId 指定应用id
|
||||
* @param roleLimitMenuIdsAndOptionIds 被限制指定范围的菜单集合
|
||||
* @author fengshuonan
|
||||
* @since 2023/9/8 15:03
|
||||
*/
|
||||
Set<Long> getAppMenuIds(Long appId, Set<Long> roleLimitMenuIdsAndOptionIds);
|
||||
|
||||
/**
|
||||
* 获取应用下的所有菜单功能
|
||||
*
|
||||
* @param appId 应用id
|
||||
* @param roleLimitMenuIdsAndOptionIds 被限制的功能和id集合
|
||||
* @author fengshuonan
|
||||
* @since 2023/9/8 15:13
|
||||
*/
|
||||
List<SysMenuOptions> getAppMenuOptions(Long appId, Set<Long> roleLimitMenuIdsAndOptionIds);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.menu.entity;
|
||||
package cn.stylefeng.roses.kernel.sys.api.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
|
@ -7,7 +7,7 @@ import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
|||
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
||||
import cn.stylefeng.roses.kernel.sys.api.constants.PermissionCodeConstants;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.api.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.pojo.request.SysMenuOptionsRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuOptionsService;
|
||||
import jakarta.annotation.Resource;
|
||||
|
|
|
@ -2,7 +2,7 @@ package cn.stylefeng.roses.kernel.sys.modular.menu.factory;
|
|||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.api.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.enums.SysMenuOptionsExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.pojo.request.SysMenuOptionsRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuOptionsService;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.menu.mapper;
|
||||
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.api.entity.SysMenuOptions;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.menu.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.api.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.pojo.request.SysMenuOptionsRequest;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ import cn.stylefeng.roses.kernel.event.sdk.publish.BusinessEventPublisher;
|
|||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveMenuCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.constants.SysConstants;
|
||||
import cn.stylefeng.roses.kernel.sys.api.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.constants.MenuConstants;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.enums.SysMenuOptionsExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.factory.MenuOptionsValidateFactory;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.mapper.SysMenuOptionsMapper;
|
||||
|
|
|
@ -14,11 +14,11 @@ import cn.stylefeng.roses.kernel.rule.pidset.ParentIdParseUtil;
|
|||
import cn.stylefeng.roses.kernel.rule.tree.buildpids.PidStructureBuildUtil;
|
||||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveMenuCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.constants.SysConstants;
|
||||
import cn.stylefeng.roses.kernel.sys.api.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.menu.UserAppMenuInfo;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.app.service.SysAppService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.constants.MenuConstants;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.enums.SysMenuExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.factory.MenuFactory;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.factory.MenuTreeFactory;
|
||||
|
@ -305,6 +305,34 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
return list.stream().map(SysMenuOptions::getMenuOptionId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Long> getAppMenuIds(Long appId, Set<Long> roleLimitMenuIdsAndOptionIds) {
|
||||
LambdaQueryWrapper<SysMenu> menuLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
menuLambdaQueryWrapper.eq(SysMenu::getAppId, appId);
|
||||
// 如果有范围限制,则查询范围内的菜单
|
||||
if (ObjectUtil.isNotEmpty(roleLimitMenuIdsAndOptionIds)) {
|
||||
menuLambdaQueryWrapper.in(SysMenu::getMenuId, roleLimitMenuIdsAndOptionIds);
|
||||
}
|
||||
menuLambdaQueryWrapper.select(SysMenu::getMenuId);
|
||||
List<SysMenu> totalMenus = this.list(menuLambdaQueryWrapper);
|
||||
if (ObjectUtil.isEmpty(totalMenus)) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
return totalMenus.stream().map(SysMenu::getMenuId).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuOptions> getAppMenuOptions(Long appId, Set<Long> roleLimitMenuIdsAndOptionIds) {
|
||||
LambdaQueryWrapper<SysMenuOptions> menuOptionsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
menuOptionsLambdaQueryWrapper.eq(SysMenuOptions::getAppId, appId);
|
||||
// 如果有范围限制,则查询范围内的菜单
|
||||
if (ObjectUtil.isNotEmpty(roleLimitMenuIdsAndOptionIds)) {
|
||||
menuOptionsLambdaQueryWrapper.in(SysMenuOptions::getMenuOptionId, roleLimitMenuIdsAndOptionIds);
|
||||
}
|
||||
menuOptionsLambdaQueryWrapper.select(SysMenuOptions::getMenuOptionId, SysMenuOptions::getMenuId);
|
||||
return sysMenuOptionsService.list(menuOptionsLambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenu> completeParentMenu(List<SysMenu> menuList) {
|
||||
if (ObjectUtil.isEmpty(menuList)) {
|
||||
|
|
|
@ -2,11 +2,11 @@ package cn.stylefeng.roses.kernel.sys.modular.role.factory;
|
|||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.TreeConstants;
|
||||
import cn.stylefeng.roses.kernel.sys.api.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.api.enums.PermissionNodeTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.role.response.RoleBindPermissionItem;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.app.entity.SysApp;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.role.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.api.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRoleMenuOptions;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import cn.hutool.extra.spring.SpringUtil;
|
|||
import cn.stylefeng.roses.kernel.event.sdk.publish.BusinessEventPublisher;
|
||||
import cn.stylefeng.roses.kernel.log.api.util.BusinessLogUtil;
|
||||
import cn.stylefeng.roses.kernel.sys.api.SysUserRoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.api.factory.RoleBindPermissionFactory;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.role.request.RoleBindPermissionRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.role.response.RoleBindPermissionItem;
|
||||
|
@ -12,7 +13,6 @@ import cn.stylefeng.roses.kernel.sys.api.pojo.role.response.RoleBindPermissionRe
|
|||
import cn.stylefeng.roses.kernel.sys.modular.app.entity.SysApp;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.app.service.SysAppService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuOptionsService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.action.RoleAssignOperateAction;
|
||||
|
|
|
@ -2,10 +2,9 @@ package cn.stylefeng.roses.kernel.sys.modular.role.service.impl;
|
|||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.sys.api.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.api.enums.PermissionNodeTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.role.request.RoleBindPermissionRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuOptionsService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.action.RoleAssignOperateAction;
|
||||
|
@ -23,7 +22,6 @@ import jakarta.annotation.Resource;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -65,13 +63,13 @@ public class RoleBindAppImpl implements RoleAssignOperateAction, RoleBindLimitAc
|
|||
Long appId = roleBindPermissionRequest.getNodeId();
|
||||
|
||||
// 找到所选应用的对应的所有菜单
|
||||
Set<Long> appMenuIds = this.getAppMenuIds(appId, roleLimitMenuIdsAndOptionIds);
|
||||
Set<Long> appMenuIds = this.sysMenuService.getAppMenuIds(appId, roleLimitMenuIdsAndOptionIds);
|
||||
if (ObjectUtil.isEmpty(appMenuIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 找到所选应用的对应的所有菜单功能
|
||||
List<SysMenuOptions> totalMenuOptions = this.getAppMenuOptions(appId, roleLimitMenuIdsAndOptionIds);
|
||||
List<SysMenuOptions> totalMenuOptions = this.sysMenuService.getAppMenuOptions(appId, roleLimitMenuIdsAndOptionIds);
|
||||
Set<Long> totalMenuOptionIds = totalMenuOptions.stream().map(SysMenuOptions::getMenuOptionId).collect(Collectors.toSet());
|
||||
|
||||
// 先删除角色绑定的这些菜单
|
||||
|
@ -126,7 +124,7 @@ public class RoleBindAppImpl implements RoleAssignOperateAction, RoleBindLimitAc
|
|||
Long appId = roleBindPermissionRequest.getNodeId();
|
||||
|
||||
// 找到所选应用的对应的所有菜单
|
||||
Set<Long> menuIds = this.getAppMenuIds(appId);
|
||||
Set<Long> menuIds = this.sysMenuService.getAppMenuIds(appId, null);
|
||||
|
||||
// 菜单为空,则直接返回
|
||||
if (ObjectUtil.isEmpty(menuIds)) {
|
||||
|
@ -134,7 +132,7 @@ public class RoleBindAppImpl implements RoleAssignOperateAction, RoleBindLimitAc
|
|||
}
|
||||
|
||||
// 找到所选应用的对应的所有菜单功能
|
||||
List<SysMenuOptions> totalMenuOptions = this.getAppMenuOptions(appId);
|
||||
List<SysMenuOptions> totalMenuOptions = this.sysMenuService.getAppMenuOptions(appId, null);
|
||||
Set<Long> menuOptionIds = totalMenuOptions.stream().map(SysMenuOptions::getMenuOptionId).collect(Collectors.toSet());
|
||||
|
||||
// 组装菜单id和功能id的集合
|
||||
|
@ -178,62 +176,4 @@ public class RoleBindAppImpl implements RoleAssignOperateAction, RoleBindLimitAc
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用下的所有菜单id
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/9/8 15:03
|
||||
*/
|
||||
private Set<Long> getAppMenuIds(Long appId) {
|
||||
return this.getAppMenuIds(appId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用下的所有菜单id
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/9/8 15:03
|
||||
*/
|
||||
private Set<Long> getAppMenuIds(Long appId, Set<Long> roleLimitMenuIdsAndOptionIds) {
|
||||
LambdaQueryWrapper<SysMenu> menuLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
menuLambdaQueryWrapper.eq(SysMenu::getAppId, appId);
|
||||
// 如果有范围限制,则查询范围内的菜单
|
||||
if (ObjectUtil.isNotEmpty(roleLimitMenuIdsAndOptionIds)) {
|
||||
menuLambdaQueryWrapper.in(SysMenu::getMenuId, roleLimitMenuIdsAndOptionIds);
|
||||
}
|
||||
menuLambdaQueryWrapper.select(SysMenu::getMenuId);
|
||||
List<SysMenu> totalMenus = sysMenuService.list(menuLambdaQueryWrapper);
|
||||
if (ObjectUtil.isEmpty(totalMenus)) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
return totalMenus.stream().map(SysMenu::getMenuId).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用下的所有菜单功能
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/9/8 15:13
|
||||
*/
|
||||
private List<SysMenuOptions> getAppMenuOptions(Long appId) {
|
||||
return this.getAppMenuOptions(appId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用下的所有菜单功能
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/9/8 15:13
|
||||
*/
|
||||
private List<SysMenuOptions> getAppMenuOptions(Long appId, Set<Long> roleLimitMenuIdsAndOptionIds) {
|
||||
LambdaQueryWrapper<SysMenuOptions> menuOptionsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
menuOptionsLambdaQueryWrapper.eq(SysMenuOptions::getAppId, appId);
|
||||
// 如果有范围限制,则查询范围内的菜单
|
||||
if (ObjectUtil.isNotEmpty(roleLimitMenuIdsAndOptionIds)) {
|
||||
menuOptionsLambdaQueryWrapper.in(SysMenuOptions::getMenuOptionId, roleLimitMenuIdsAndOptionIds);
|
||||
}
|
||||
menuOptionsLambdaQueryWrapper.select(SysMenuOptions::getMenuOptionId, SysMenuOptions::getMenuId);
|
||||
return sysMenuOptionsService.list(menuOptionsLambdaQueryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.role.service.impl;
|
||||
|
||||
import cn.stylefeng.roses.kernel.sys.api.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.api.enums.PermissionNodeTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.role.request.RoleBindPermissionRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuOptionsService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.action.RoleAssignOperateAction;
|
||||
|
|
|
@ -7,7 +7,7 @@ import cn.stylefeng.roses.kernel.rule.enums.DbTypeEnum;
|
|||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveMenuCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveRoleCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.constants.SysConstants;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.api.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRoleMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.mapper.SysRoleMenuOptionsMapper;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleMenuOptionsService;
|
||||
|
|
|
@ -16,10 +16,10 @@ import cn.stylefeng.roses.kernel.rule.enums.permission.DataScopeTypeEnum;
|
|||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveRoleCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.constants.SysConstants;
|
||||
import cn.stylefeng.roses.kernel.sys.api.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.api.enums.role.RoleTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.role.SysRoleDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuOptionsService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.service.SysMenuService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRole;
|
||||
|
|
Loading…
Reference in New Issue