namespace Admin.NET.Core.Service; /// /// 系统角色菜单服务 /// public class SysRoleMenuService : ITransient { private readonly SqlSugarRepository _sysRoleMenuRep; private readonly SysCacheService _sysCacheService; public SysRoleMenuService(SqlSugarRepository sysRoleMenuRep, SysCacheService sysCacheService) { _sysRoleMenuRep = sysRoleMenuRep; _sysCacheService = sysCacheService; } /// /// 根据角色Id集合获取菜单Id集合 /// /// /// public async Task> GetRoleMenuIdList(List roleIdList) { return await _sysRoleMenuRep.AsQueryable() .Where(u => roleIdList.Contains(u.RoleId)) .Select(u => u.MenuId).ToListAsync(); } /// /// 授权角色菜单 /// /// /// [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); } /// /// 根据菜单Id集合删除角色菜单 /// /// /// public async Task DeleteRoleMenuByMenuIdList(List menuIdList) { await _sysRoleMenuRep.DeleteAsync(u => menuIdList.Contains(u.MenuId)); } /// /// 根据角色Id删除角色菜单 /// /// /// public async Task DeleteRoleMenuByRoleId(long roleId) { await _sysRoleMenuRep.DeleteAsync(u => u.RoleId == roleId); } }