APP菜单权限

This commit is contained in:
秦鸿展
2026-06-29 17:21:09 +08:00
parent d982cc41c3
commit 4afe929020
2 changed files with 48 additions and 8 deletions
@@ -28,6 +28,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
@@ -93,8 +94,10 @@ public class AppMenuApplicationService {
appMenuDO.setTopOrganizationId(SecurityUtils.getLoginUser().getUserPo().getTopOrganizationId());
}
List<MenuPo> menuPos = appMenuDomainService.queryMenuListByApp(appMenuDO);
// 车队主管显示「订单调度」;业务主管显示「订单审核」
// 获取用户角色 → 查角色APP菜单权限 → 取交集去重
List<UserRoleMenuPO> userRoles = userFeignService.selectUserRoles(appMenuDO.getUserId());
menuPos = filterMenuByUserRole(menuPos, userRoles);
// 车队主管显示「订单调度」;业务主管显示「订单审核」
menuPos = filterMenuByRole(menuPos, userRoles);
//判断控制推广码是否显示
if (menuPos != null){
@@ -108,6 +111,39 @@ public class AppMenuApplicationService {
return menuPos;
}
/**
* 在APP配置菜单基础上,根据用户角色取集合,去除重复菜单
*/
private List<MenuPo> filterMenuByUserRole(List<MenuPo> appMenus, List<UserRoleMenuPO> userRoles) {
if (appMenus == null || appMenus.isEmpty() || userRoles == null || userRoles.isEmpty()) {
return appMenus != null ? appMenus : new ArrayList<>();
}
// 获取用户所有角色ID
List<Long> roleIds = userRoles.stream()
.map(UserRoleMenuPO::getRoleId)
.filter(id -> id != null)
.distinct()
.collect(Collectors.toList());
if (roleIds.isEmpty()) {
return appMenus;
}
// 查询角色对应的APP菜单权限(role_menu表中roleMenuClient=2的)
R<List<UserRoleMenuPO>> roleMenuR = userServiceFeign.roleAppMenuListByRoleIds(roleIds);
if (R.FAIL == roleMenuR.getCode() || roleMenuR.getData() == null || roleMenuR.getData().isEmpty()) {
return appMenus;
}
// 取角色菜单ID集合
Set<Long> roleMenuIds = roleMenuR.getData().stream()
.map(UserRoleMenuPO::getMenuId)
.filter(id -> id != null)
.collect(Collectors.toSet());
// 过滤:只保留APP配置菜单中也在角色权限中的菜单
return appMenus.stream()
.filter(menu -> menu.getMenuId() != null && roleMenuIds.contains(menu.getMenuId()))
.distinct()
.collect(Collectors.toList());
}
/**
* 按角色过滤互斥菜单:
* 车队主管隐藏「订单审核」;业务主管隐藏「订单调度」