加入erp的相关服务

This commit is contained in:
tongfei
2023-10-25 15:31:26 +08:00
parent 25c09f4a0a
commit 22213af18f
16 changed files with 1827 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
using AutoMapper;
using ERP;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using WMS.Web.Core.Dto.Erp;
using WMS.Web.Core.Dto.Erp.Purchase;
using WMS.Web.Core.Internal.Results;
using WMS.Web.Domain.IService.Public;
using WMS.Web.Domain.Options;
using WMS.Web.Domain.Values;
namespace WMS.Web.Domain.Services.Public
{
/// <summary>
/// erp数据交互服务
/// </summary>
public class ErpService : IErpService
{
private IMapper _mapper;
private ErpOptions _erpOptions;
private ILogger<ErpService> _logger;
public ErpService(
IMapper mapper,
IOptions<ErpOptions> erpOptions,
ILogger<ErpService> logger)
{
this._erpOptions = erpOptions?.Value;
this._mapper = mapper;
this._logger = logger;
}
/// <summary>
/// 初始化ERP登录到ERP
/// </summary>
/// <returns></returns>
public async Task<Result<AccessResult>> Init()
{
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress(this._erpOptions.EndpointAddress);
ERPGWSoapClient 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);
}
catch (Exception ex)
{
return Result<AccessResult>.ReFailure(ResultCodes.Erp_Login_Error);
}
}
/// <summary>
/// erp:单据查询-采购入库单
/// </summary>
/// <returns></returns>
public async Task<ResultList<ErpPurchaseInStockResultDto>> BillQueryForPurchaseInStock()
{
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 param = new ErpBillQueryParamDto();
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<ErpPurchaseInStockResultDto>();
foreach (var item in result)
{
var lis = new ErpPurchaseInStockResultDto();
lis.BillNo = item[0];
lis.Specifications = item[1];
list.Add(lis);
}
return ResultList<ErpPurchaseInStockResultDto>.ReSuccess(list);
}
}
}