优化金蝶获取数据
This commit is contained in:
@@ -31,6 +31,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
private static void AddRepositories(this IServiceCollection services)
|
||||
{
|
||||
services.AddHttpContextAccessor();
|
||||
services.AddScoped<ILoginRepositories, LoginRepositories>();
|
||||
|
||||
services.AddTransient<ITransactionRepositories, TransactionRepositories>();
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ using WMS.Web.Core;
|
||||
using WMS.Web.Core.Dto;
|
||||
using WMS.Web.Core.Internal.Results;
|
||||
using WMS.Web.Domain.Infrastructure;
|
||||
using WMS.Web.Domain.IService.Public;
|
||||
using WMS.Web.Domain.Values.Single;
|
||||
using WMS.Web.Repositories.Configuration;
|
||||
|
||||
namespace WMS.Web.Repositories
|
||||
@@ -20,14 +22,18 @@ namespace WMS.Web.Repositories
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly ILoginRepositories _loginRepositories;
|
||||
private readonly RepositoryDbContext _context;
|
||||
private readonly ISingleDataService _singleDataService;
|
||||
|
||||
|
||||
public InStockRepositories(RepositoryDbContext context, IMapper mapper, IServiceProvider serviceProvider)
|
||||
public InStockRepositories(RepositoryDbContext context, IMapper mapper, ILoginRepositories loginRepositories, IServiceProvider serviceProvider, ISingleDataService singleDataService)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
_serviceProvider = serviceProvider;
|
||||
_loginRepositories = loginRepositories;
|
||||
_singleDataService = singleDataService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -61,10 +67,10 @@ namespace WMS.Web.Repositories
|
||||
MaterialName="",
|
||||
MaterialNumber="",
|
||||
Specifications="",
|
||||
Stock="",
|
||||
Qty=s.detail.Qty,
|
||||
Creator="",
|
||||
CreateTime=s.order.CreateTime,
|
||||
Stock= _singleDataService.GetSingleData(SingleAction.Stocks, _loginRepositories.CompanyId, s.detail.StockId),
|
||||
Qty =s.detail.Qty,
|
||||
Creator = _singleDataService.GetSingleData(SingleAction.Staffs, _loginRepositories.CompanyId, s.order.CreatorId),
|
||||
CreateTime =s.order.CreateTime,
|
||||
SuccessSync=s.order.SuccessSync
|
||||
}).OrderByDescending(x => x.Id).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
||||
|
||||
|
||||
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