|
|
|
|
@ -13,6 +13,7 @@ import org.dromara.common.core.utils.StreamUtils;
|
|
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
import org.dromara.common.core.utils.TreeBuildUtils;
|
|
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
|
|
import org.dromara.system.constant.ClientMenuConstants;
|
|
|
|
|
import org.dromara.system.domain.SysMenu;
|
|
|
|
|
import org.dromara.system.domain.SysRole;
|
|
|
|
|
import org.dromara.system.domain.SysRoleMenu;
|
|
|
|
|
@ -385,4 +386,72 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 按客户端限制过滤菜单树
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<SysMenu> filterMenusByClient(List<SysMenu> menus, String clientId) {
|
|
|
|
|
if (!ClientMenuConstants.isRestrictedClient(clientId) || CollUtil.isEmpty(menus)) {
|
|
|
|
|
return menus;
|
|
|
|
|
}
|
|
|
|
|
return menus.stream()
|
|
|
|
|
.filter(menu -> ClientMenuConstants.RESTRICTED_ALLOWED_ROOT_MENU_NAMES.contains(menu.getMenuName()))
|
|
|
|
|
.toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 按客户端限制过滤用户菜单权限
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Set<String> selectMenuPermsByUserIdForClient(Long userId, String clientId) {
|
|
|
|
|
if (!ClientMenuConstants.isRestrictedClient(clientId)) {
|
|
|
|
|
return selectMenuPermsByUserId(userId);
|
|
|
|
|
}
|
|
|
|
|
Set<Long> allowedMenuIds = getRestrictedClientAllowedMenuIds();
|
|
|
|
|
if (CollUtil.isEmpty(allowedMenuIds)) {
|
|
|
|
|
return Collections.emptySet();
|
|
|
|
|
}
|
|
|
|
|
List<String> list = baseMapper.selectObjs(
|
|
|
|
|
new LambdaQueryWrapper<SysMenu>()
|
|
|
|
|
.select(SysMenu::getPerms)
|
|
|
|
|
.inSql(SysMenu::getMenuId, baseMapper.buildMenuByUserSql(userId))
|
|
|
|
|
.in(SysMenu::getMenuId, allowedMenuIds)
|
|
|
|
|
.isNotNull(SysMenu::getPerms)
|
|
|
|
|
);
|
|
|
|
|
return new HashSet<>(StreamUtils.filter(list, StringUtils::isNotBlank));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取受限客户端允许访问的全部菜单 ID(含子菜单)
|
|
|
|
|
*/
|
|
|
|
|
private Set<Long> getRestrictedClientAllowedMenuIds() {
|
|
|
|
|
List<SysMenu> rootMenus = baseMapper.selectList(
|
|
|
|
|
new LambdaQueryWrapper<SysMenu>()
|
|
|
|
|
.eq(SysMenu::getParentId, Constants.TOP_PARENT_ID)
|
|
|
|
|
.in(SysMenu::getMenuName, ClientMenuConstants.RESTRICTED_ALLOWED_ROOT_MENU_NAMES)
|
|
|
|
|
);
|
|
|
|
|
if (CollUtil.isEmpty(rootMenus)) {
|
|
|
|
|
return Collections.emptySet();
|
|
|
|
|
}
|
|
|
|
|
List<SysMenu> allMenus = baseMapper.selectList(
|
|
|
|
|
new LambdaQueryWrapper<SysMenu>()
|
|
|
|
|
.eq(SysMenu::getStatus, SystemConstants.NORMAL)
|
|
|
|
|
);
|
|
|
|
|
Set<Long> allowedMenuIds = new HashSet<>();
|
|
|
|
|
for (SysMenu rootMenu : rootMenus) {
|
|
|
|
|
allowedMenuIds.add(rootMenu.getMenuId());
|
|
|
|
|
collectDescendantMenuIds(allMenus, rootMenu.getMenuId(), allowedMenuIds);
|
|
|
|
|
}
|
|
|
|
|
return allowedMenuIds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void collectDescendantMenuIds(List<SysMenu> allMenus, Long parentId, Set<Long> allowedMenuIds) {
|
|
|
|
|
for (SysMenu menu : allMenus) {
|
|
|
|
|
if (parentId.equals(menu.getParentId())) {
|
|
|
|
|
allowedMenuIds.add(menu.getMenuId());
|
|
|
|
|
collectDescendantMenuIds(allMenus, menu.getMenuId(), allowedMenuIds);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|