update 增加获取方法
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Ewide.Core
|
namespace Ewide.Core
|
||||||
{
|
{
|
||||||
@@ -10,7 +11,11 @@ namespace Ewide.Core
|
|||||||
SysUser User { get; }
|
SysUser User { get; }
|
||||||
string UserId { get; }
|
string UserId { get; }
|
||||||
|
|
||||||
Task<SysUser> CheckUserAsync(string userId, bool tracking = true);
|
Task<SysUser> CheckUserAsync();
|
||||||
|
Task<SysUser> CheckUserAsync(string userId);
|
||||||
|
Task<SysEmp> GetUserEmpInfo();
|
||||||
Task<SysEmp> GetUserEmpInfo(string userId);
|
Task<SysEmp> GetUserEmpInfo(string userId);
|
||||||
|
Task<List<string>> GetUserRoleIdList();
|
||||||
|
Task<List<string>> GetUserRoleIdList(string userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,10 @@
|
|||||||
using Furion.DependencyInjection;
|
using Furion.DependencyInjection;
|
||||||
using Furion.FriendlyException;
|
using Furion.FriendlyException;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Ewide.Core
|
namespace Ewide.Core
|
||||||
{
|
{
|
||||||
@@ -12,6 +15,8 @@ namespace Ewide.Core
|
|||||||
public class UserManager : IUserManager, IScoped
|
public class UserManager : IUserManager, IScoped
|
||||||
{
|
{
|
||||||
private readonly IRepository<SysUser> _sysUserRep; // 用户表仓储
|
private readonly IRepository<SysUser> _sysUserRep; // 用户表仓储
|
||||||
|
private readonly IRepository<SysRole> _sysRoleRep;
|
||||||
|
private readonly IRepository<SysUserRole> _sysUserRoleRep;
|
||||||
private readonly IRepository<SysEmp> _sysEmpRep; // 员工表
|
private readonly IRepository<SysEmp> _sysEmpRep; // 员工表
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
|
|
||||||
@@ -40,11 +45,16 @@ namespace Ewide.Core
|
|||||||
get => _sysUserRep.Find(UserId);
|
get => _sysUserRep.Find(UserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserManager(IRepository<SysUser> sysUserRep,
|
public UserManager(
|
||||||
|
IRepository<SysUser> sysUserRep,
|
||||||
|
IRepository<SysRole> sysRoleRep,
|
||||||
|
IRepository<SysUserRole> sysUserRoleRep,
|
||||||
IRepository<SysEmp> sysEmpRep,
|
IRepository<SysEmp> sysEmpRep,
|
||||||
IHttpContextAccessor httpContextAccessor)
|
IHttpContextAccessor httpContextAccessor)
|
||||||
{
|
{
|
||||||
_sysUserRep = sysUserRep;
|
_sysUserRep = sysUserRep;
|
||||||
|
_sysRoleRep = sysRoleRep;
|
||||||
|
_sysUserRoleRep = sysUserRoleRep;
|
||||||
_sysEmpRep = sysEmpRep;
|
_sysEmpRep = sysEmpRep;
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
}
|
}
|
||||||
@@ -55,12 +65,17 @@ namespace Ewide.Core
|
|||||||
/// <param name="userId"></param>
|
/// <param name="userId"></param>
|
||||||
/// <param name="tracking"></param>
|
/// <param name="tracking"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<SysUser> CheckUserAsync(string userId, bool tracking = true)
|
public async Task<SysUser> CheckUserAsync(string userId)
|
||||||
{
|
{
|
||||||
var user = await _sysUserRep.FirstOrDefaultAsync(u => u.Id == userId, tracking);
|
var user = await _sysUserRep.FirstOrDefaultAsync(u => u.Id == userId, false);
|
||||||
return user ?? throw Oops.Oh(ErrorCode.D1002);
|
return user ?? throw Oops.Oh(ErrorCode.D1002);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<SysUser> CheckUserAsync()
|
||||||
|
{
|
||||||
|
return await CheckUserAsync(UserId);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取用户员工信息
|
/// 获取用户员工信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -71,5 +86,21 @@ namespace Ewide.Core
|
|||||||
var emp = await _sysEmpRep.FirstOrDefaultAsync(u => u.Id == userId, false);
|
var emp = await _sysEmpRep.FirstOrDefaultAsync(u => u.Id == userId, false);
|
||||||
return emp ?? throw Oops.Oh(ErrorCode.D1002);
|
return emp ?? throw Oops.Oh(ErrorCode.D1002);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<SysEmp> GetUserEmpInfo()
|
||||||
|
{
|
||||||
|
return await GetUserEmpInfo(UserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<string>> GetUserRoleIdList(string userId)
|
||||||
|
{
|
||||||
|
var roleIds = await _sysUserRoleRep.DetachedEntities.Where(u => u.SysUserId == userId).Select(u => u.SysRoleId).ToListAsync();
|
||||||
|
return roleIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<string>> GetUserRoleIdList()
|
||||||
|
{
|
||||||
|
return await GetUserRoleIdList(UserId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user