You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.1 KiB
70 lines
2.1 KiB
5 days ago
|
namespace Admin.NET.Core.Service;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 系统角色菜单服务
|
||
|
/// </summary>
|
||
|
public class SysRoleMenuService : ITransient
|
||
|
{
|
||
|
private readonly SqlSugarRepository<SysRoleMenu> _sysRoleMenuRep;
|
||
|
private readonly SysCacheService _sysCacheService;
|
||
|
|
||
|
public SysRoleMenuService(SqlSugarRepository<SysRoleMenu> sysRoleMenuRep,
|
||
|
SysCacheService sysCacheService)
|
||
|
{
|
||
|
_sysRoleMenuRep = sysRoleMenuRep;
|
||
|
_sysCacheService = sysCacheService;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 根据角色Id集合获取菜单Id集合
|
||
|
/// </summary>
|
||
|
/// <param name="roleIdList"></param>
|
||
|
/// <returns></returns>
|
||
|
public async Task<List<long>> GetRoleMenuIdList(List<long> roleIdList)
|
||
|
{
|
||
|
return await _sysRoleMenuRep.AsQueryable()
|
||
|
.Where(u => roleIdList.Contains(u.RoleId))
|
||
|
.Select(u => u.MenuId).ToListAsync();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 授权角色菜单
|
||
|
/// </summary>
|
||
|
/// <param name="input"></param>
|
||
|
/// <returns></returns>
|
||
|
[UnitOfWork]
|
||
|
public async Task GrantRoleMenu(RoleMenuInput input)
|
||
|
{
|
||
|
await _sysRoleMenuRep.DeleteAsync(u => u.RoleId == input.Id);
|
||
|
var menus = input.MenuIdList.Select(u => new SysRoleMenu
|
||
|
{
|
||
|
RoleId = input.Id,
|
||
|
MenuId = u
|
||
|
}).ToList();
|
||
|
await _sysRoleMenuRep.InsertRangeAsync(menus);
|
||
|
|
||
|
// 清除缓存
|
||
|
_sysCacheService.RemoveByPrefixKey(CacheConst.KeyMenu);
|
||
|
_sysCacheService.RemoveByPrefixKey(CacheConst.KeyPermission);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 根据菜单Id集合删除角色菜单
|
||
|
/// </summary>
|
||
|
/// <param name="menuIdList"></param>
|
||
|
/// <returns></returns>
|
||
|
public async Task DeleteRoleMenuByMenuIdList(List<long> menuIdList)
|
||
|
{
|
||
|
await _sysRoleMenuRep.DeleteAsync(u => menuIdList.Contains(u.MenuId));
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 根据角色Id删除角色菜单
|
||
|
/// </summary>
|
||
|
/// <param name="roleId"></param>
|
||
|
/// <returns></returns>
|
||
|
public async Task DeleteRoleMenuByRoleId(long roleId)
|
||
|
{
|
||
|
await _sysRoleMenuRep.DeleteAsync(u => u.RoleId == roleId);
|
||
|
}
|
||
|
}
|