优化金蝶获取数据
This commit is contained in:
@@ -26,7 +26,8 @@ namespace WMS.Web.Api.Controllers
|
||||
[Route("hj")]
|
||||
public async Task<string> TestHJ()
|
||||
{
|
||||
var result= await this._erpService.BillQueryForPurchaseInStock();
|
||||
//var result= await this._erpService.BillQueryForPurchaseInStock();
|
||||
var result = await this._erpService.BillQueryForOrg();
|
||||
if (!result.IsSuccess)
|
||||
return "";
|
||||
return JsonConvert.SerializeObject(result.Data);
|
||||
|
||||
@@ -305,6 +305,11 @@
|
||||
表单所在的子系统内码,字符串类型(非必录)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Erp.Org.ErpOrgDto.Id">
|
||||
<summary>
|
||||
Id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Core.Dto.Erp.Purchase.ErpPurchaseInStockResultDto">
|
||||
<summary>
|
||||
erp-采购入库-返回数据源
|
||||
|
||||
@@ -899,6 +899,11 @@
|
||||
<param name="isTransaction"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Domain.Infrastructure.ILoginRepositories.CompanyId">
|
||||
<summary>
|
||||
公司Id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Infrastructure.ITransactionRepositories.GetTransaction">
|
||||
<summary>
|
||||
获取事务 用来处理即时库存
|
||||
@@ -927,6 +932,12 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.IService.Public.IErpService.BillQueryForOrg">
|
||||
<summary>
|
||||
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.IService.Public.ILoginService">
|
||||
<summary>
|
||||
登录服务接口
|
||||
@@ -1390,6 +1401,12 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Services.Public.ErpService.BillQueryForOrg">
|
||||
<summary>
|
||||
erp:单据查询-组织数据
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Services.Public.HttpClientService.GetAsync``1(System.String,System.Int32)">
|
||||
<summary>
|
||||
Get方法
|
||||
@@ -1779,6 +1796,16 @@
|
||||
组装拆卸单:里面包含出和入
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:WMS.Web.Domain.Values.Erp.FormIdParam.ORG_Organizations">
|
||||
<summary>
|
||||
组织
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:WMS.Web.Domain.Values.Erp.FormIdParam.BD_Supplier">
|
||||
<summary>
|
||||
供应商
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.Values.InstockStatus">
|
||||
<summary>
|
||||
入库状态
|
||||
|
||||
@@ -41,11 +41,11 @@ namespace WMS.Web.Core.Dto.Erp
|
||||
/// <summary>
|
||||
/// 开始行索引,整型(非必录)
|
||||
/// </summary>
|
||||
public int StartRow { get; set; } = 1;
|
||||
public int StartRow { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// 最大行数,整型,不能超过10000(非必录)
|
||||
/// </summary>
|
||||
public int Limit { get; set; } = 2;
|
||||
public int Limit { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 表单所在的子系统内码,字符串类型(非必录)
|
||||
|
||||
16
src/WMS.Web.Core/Dto/Erp/Org/ErpOrgDto.cs
Normal file
16
src/WMS.Web.Core/Dto/Erp/Org/ErpOrgDto.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Core.Dto.Erp.Org
|
||||
{
|
||||
public class ErpOrgDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Id
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto.Erp.Org;
|
||||
using WMS.Web.Core.Dto.Erp.Purchase;
|
||||
using WMS.Web.Core.Internal.Results;
|
||||
|
||||
@@ -14,5 +15,11 @@ namespace WMS.Web.Domain.IService.Public
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<ResultList<ErpPurchaseInStockResultDto>> BillQueryForPurchaseInStock();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<ResultList<ErpOrgDto>> BillQueryForOrg();
|
||||
}
|
||||
}
|
||||
|
||||
14
src/WMS.Web.Domain/Infrastructure/ILoginRepositories.cs
Normal file
14
src/WMS.Web.Domain/Infrastructure/ILoginRepositories.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Domain.Infrastructure
|
||||
{
|
||||
public interface ILoginRepositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 公司Id
|
||||
/// </summary>
|
||||
int CompanyId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using AutoMapper;
|
||||
using ERP;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
@@ -9,6 +10,7 @@ using System.ServiceModel;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto.Erp;
|
||||
using WMS.Web.Core.Dto.Erp.Org;
|
||||
using WMS.Web.Core.Dto.Erp.Purchase;
|
||||
using WMS.Web.Core.Internal.Results;
|
||||
using WMS.Web.Domain.IService.Public;
|
||||
@@ -26,35 +28,50 @@ namespace WMS.Web.Domain.Services.Public
|
||||
private IMapper _mapper;
|
||||
private ErpOptions _erpOptions;
|
||||
private ILogger<ErpService> _logger;
|
||||
private ERPGWSoapClient _client;
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
public ErpService(
|
||||
IMapper mapper,
|
||||
IOptions<ErpOptions> erpOptions,
|
||||
ILogger<ErpService> logger)
|
||||
ILogger<ErpService> logger,
|
||||
IMemoryCache memoryCache)
|
||||
{
|
||||
this._erpOptions = erpOptions?.Value;
|
||||
this._mapper = mapper;
|
||||
this._logger = logger;
|
||||
this._memoryCache = memoryCache;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化ERP:登录到ERP
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<Result<AccessResult>> Init()
|
||||
public async Task<Result<string>> Init()
|
||||
{
|
||||
BasicHttpBinding binding = new BasicHttpBinding();
|
||||
EndpointAddress address = new EndpointAddress(this._erpOptions.EndpointAddress);
|
||||
ERPGWSoapClient client = new ERPGWSoapClient(binding, address);
|
||||
this._client = new ERPGWSoapClient(binding, address);
|
||||
try
|
||||
{
|
||||
var result = await client.ValidateSystemAsync(this._erpOptions.UserName, this._erpOptions.Password, this._erpOptions.ErpId, "");
|
||||
if (result == null)
|
||||
return Result<AccessResult>.ReFailure(ResultCodes.Erp_Login_Error);
|
||||
return Result<AccessResult>.ReSuccess(result);
|
||||
var appId = "wms";
|
||||
var cache_key = "erp_accesstoken_"+ appId;
|
||||
var cache_value = _memoryCache.Get<string>(cache_key);
|
||||
if (!string.IsNullOrEmpty(cache_value))
|
||||
return Result<string>.ReSuccess(cache_value);
|
||||
else
|
||||
{
|
||||
var result = await this._client.ValidateSystemAsync(this._erpOptions.UserName, this._erpOptions.Password, this._erpOptions.ErpId, appId);
|
||||
if (result == null)
|
||||
return Result<string>.ReFailure(ResultCodes.Erp_Login_Error);
|
||||
|
||||
_memoryCache.Set(cache_key, true, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(30)));
|
||||
return Result<string>.ReSuccess(result.AccessToken);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Result<AccessResult>.ReFailure(ResultCodes.Erp_Login_Error);
|
||||
return Result<string>.ReFailure(ResultCodes.Erp_Login_Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,17 +83,17 @@ namespace WMS.Web.Domain.Services.Public
|
||||
{
|
||||
try
|
||||
{
|
||||
BasicHttpBinding binding = new BasicHttpBinding();
|
||||
EndpointAddress address = new EndpointAddress(this._erpOptions.EndpointAddress);
|
||||
ERPGWSoapClient client = new ERPGWSoapClient(binding, address);
|
||||
var token_result = await client.ValidateSystemAsync(this._erpOptions.UserName, this._erpOptions.Password, this._erpOptions.ErpId, "");
|
||||
var query = new ErpBillQueryDto(token_result.AccessToken);
|
||||
var token_result = await this.Init();
|
||||
if(!token_result.IsSuccess)
|
||||
return ResultList<ErpPurchaseInStockResultDto>.ReFailure(token_result);
|
||||
|
||||
var query = new ErpBillQueryDto(token_result.Data);
|
||||
var param = new ErpBillQueryParamDto(FormIdParam.STK_InStock.ToString());
|
||||
param.FieldKeys = this._erpOptions.PurchaseInstockFieldKeys;
|
||||
query.Data = JsonConvert.SerializeObject(param);
|
||||
var json = JsonConvert.SerializeObject(query);
|
||||
|
||||
var result_json = await client.ExecuteBillQueryAsync(json);
|
||||
var result_json = await _client.ExecuteBillQueryAsync(json);
|
||||
var result = JsonConvert.DeserializeObject<List<List<string>>>(result_json);
|
||||
|
||||
var list = new List<ErpPurchaseInStockResultDto>();
|
||||
@@ -97,10 +114,48 @@ namespace WMS.Web.Domain.Services.Public
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
return ResultList<ErpPurchaseInStockResultDto>.ReFailure("错误",10001);
|
||||
return ResultList<ErpPurchaseInStockResultDto>.ReFailure("错误", 10001);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// erp:单据查询-组织数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<ResultList<ErpOrgDto>> BillQueryForOrg()
|
||||
{
|
||||
try
|
||||
{
|
||||
var token_result = await this.Init();
|
||||
if (!token_result.IsSuccess)
|
||||
return ResultList<ErpOrgDto>.ReFailure(token_result);
|
||||
var query = new ErpBillQueryDto(token_result.Data);
|
||||
var param = new ErpBillQueryParamDto(FormIdParam.ORG_Organizations.ToString());
|
||||
param.FieldKeys = "FOrgID,FName";
|
||||
param.FilterString = "FOrgID=100008";
|
||||
query.Data = JsonConvert.SerializeObject(param);
|
||||
var json = JsonConvert.SerializeObject(query);
|
||||
|
||||
var result_json = await _client.ExecuteBillQueryAsync(json);
|
||||
var result = JsonConvert.DeserializeObject<List<List<string>>>(result_json);
|
||||
|
||||
var list = new List<ErpOrgDto>();
|
||||
foreach (var item in result)
|
||||
{
|
||||
var lis = new ErpOrgDto();
|
||||
lis.Id = int.Parse(item[0]);
|
||||
lis.Name = item[1];
|
||||
|
||||
list.Add(lis);
|
||||
|
||||
}
|
||||
return ResultList<ErpOrgDto>.ReSuccess(list);
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return ResultList<ErpOrgDto>.ReFailure("错误", 10002);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,5 +33,13 @@ namespace WMS.Web.Domain.Values.Erp
|
||||
/// 组装拆卸单:里面包含出和入
|
||||
/// </summary>
|
||||
STK_AssembledApp=6,
|
||||
/// <summary>
|
||||
/// 组织
|
||||
/// </summary>
|
||||
ORG_Organizations=7,
|
||||
/// <summary>
|
||||
/// 供应商
|
||||
/// </summary>
|
||||
BD_Supplier=8,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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