优化金蝶获取数据
This commit is contained in:
44
src/WMS.Web.Repositories/LoginRepositories.cs
Normal file
44
src/WMS.Web.Repositories/LoginRepositories.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using WMS.Web.Core.Dto.Login;
|
||||
using WMS.Web.Domain.Infrastructure;
|
||||
using WMS.Web.Domain.Services.Public;
|
||||
|
||||
namespace WMS.Web.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 登录仓储
|
||||
/// </summary>
|
||||
public class LoginRepositories:ILoginRepositories
|
||||
{
|
||||
public int CompanyId { get; set; } = 0;
|
||||
private readonly RedisClientService _redisClientService;
|
||||
public LoginRepositories(ILogger<LoginRepositories> logger, IHttpContextAccessor httpContextAccessor, RedisClientService redisClientService)
|
||||
{
|
||||
try
|
||||
{
|
||||
string authorization = httpContextAccessor?.HttpContext?.Request?.Headers["Authorization"] ?? "";
|
||||
if (string.IsNullOrEmpty(authorization)) return;
|
||||
|
||||
string token = string.Empty;
|
||||
if (authorization.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||
token = authorization.Substring("Bearer ".Length).Trim();
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
this.CompanyId = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
_redisClientService = redisClientService;
|
||||
var logininfo = _redisClientService.GetStringKey<LoginInDto>($"wms_login_{token}");
|
||||
this.CompanyId = logininfo == null ? 0 : logininfo.UserInfo.CompanyId;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user