namespace Admin.NET.Core; /// /// 用户管理 /// public class UserManager : IUserManager, IScoped { private readonly SqlSugarRepository _sysUserRep; private readonly IHttpContextAccessor _httpContextAccessor; public long UserId { get => long.Parse(_httpContextAccessor.HttpContext.User.FindFirst(ClaimConst.UserId)?.Value); } public string UserName { get => _httpContextAccessor.HttpContext.User.FindFirst(ClaimConst.UserName)?.Value; } public string RealName { get => _httpContextAccessor.HttpContext.User.FindFirst(ClaimConst.RealName)?.Value; } public bool SuperAdmin { get => _httpContextAccessor.HttpContext.User.FindFirst(ClaimConst.SuperAdmin)?.Value == ((int)UserTypeEnum.SuperAdmin).ToString(); } public string OpenId { get => _httpContextAccessor.HttpContext.User.FindFirst(ClaimConst.OpenId)?.Value; } public SysUser User { get => _sysUserRep.AsQueryable().Includes(t => t.SysOrg).First(u => u.Id == UserId); } public UserManager(SqlSugarRepository sysUserRep, IHttpContextAccessor httpContextAccessor) { _sysUserRep = sysUserRep; _httpContextAccessor = httpContextAccessor; } /// /// 获取用户信息 /// /// /// public async Task CheckUserAsync(long userId) { var user = await _sysUserRep.GetFirstAsync(u => u.Id == userId); return user ?? throw Oops.Oh(ErrorCodeEnum.D1002); } }