|
|
|
|
using Autofac;
|
|
|
|
|
using Common.Const;
|
|
|
|
|
using Entity.DbModel.System;
|
|
|
|
|
using Entity.Dto.Req;
|
|
|
|
|
using HybirdFrameworkCore.Autofac;
|
|
|
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
|
|
|
using HybirdFrameworkCore.Redis;
|
|
|
|
|
using Repository.System;
|
|
|
|
|
|
|
|
|
|
namespace Service.Mgr
|
|
|
|
|
{
|
|
|
|
|
[Scope("SingleInstance")]
|
|
|
|
|
public class SysUserRoleMgr
|
|
|
|
|
{
|
|
|
|
|
private readonly SysUserRoleRepository _sysUserRoleRep;
|
|
|
|
|
|
|
|
|
|
public SysUserRoleMgr(SysUserRoleRepository sysUserRoleRep)
|
|
|
|
|
{
|
|
|
|
|
_sysUserRoleRep = sysUserRoleRep;
|
|
|
|
|
}
|
|
|
|
|
RedisHelper redisHelper = AppInfo.Container.Resolve<RedisHelper>();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 授权用户角色
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task GrantUserRole(UserRoleReq input)
|
|
|
|
|
{
|
|
|
|
|
await _sysUserRoleRep.DeleteAsync(u => u.UserId == input.UserId);
|
|
|
|
|
|
|
|
|
|
if (input.RoleIdList == null || input.RoleIdList.Count < 1) return;
|
|
|
|
|
var roles = input.RoleIdList.Select(u => new SysUserRole
|
|
|
|
|
{
|
|
|
|
|
UserId = input.UserId,
|
|
|
|
|
RoleId = u
|
|
|
|
|
}).ToList();
|
|
|
|
|
await _sysUserRoleRep.InsertAsync(roles);
|
|
|
|
|
redisHelper.Remove(RedisConstMgr.KeyUserButton + input.UserId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据角色Id删除用户角色
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="roleId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task DeleteUserRoleByRoleId(long roleId)
|
|
|
|
|
{
|
|
|
|
|
await _sysUserRoleRep.DeleteUserRoleByRoleId(u => u.RoleId == roleId, u => u.UserId,
|
|
|
|
|
(userId =>
|
|
|
|
|
{
|
|
|
|
|
redisHelper.Remove(RedisConstMgr.KeyUserButton + userId);
|
|
|
|
|
}));
|
|
|
|
|
await _sysUserRoleRep.DeleteAsync(u => u.RoleId == roleId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据用户Id删除用户角色
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task DeleteUserRoleByUserId(long userId)
|
|
|
|
|
{
|
|
|
|
|
await _sysUserRoleRep.DeleteAsync(u => u.UserId == userId);
|
|
|
|
|
redisHelper.Remove(RedisConstMgr.KeyUserButton + userId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据用户Id获取角色Id集合
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<List<long>> GetUserRoleIdList(long userId)
|
|
|
|
|
{
|
|
|
|
|
return await _sysUserRoleRep.QueryByClauseAsync(u => u.UserId == userId, u => u.RoleId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据角色Id获取用户Id集合
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="roleId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<List<long>> GetUserIdList(long roleId)
|
|
|
|
|
{
|
|
|
|
|
return await _sysUserRoleRep.QueryByClauseAsync(u => u.RoleId == roleId, u => u.UserId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|