107 lines
3.9 KiB
C#
107 lines
3.9 KiB
C#
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;
|
||
using WMS.Web.Domain.Values.Erp;
|
||
|
||
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()
|
||
{
|
||
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 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 = 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];
|
||
lis.SupplierName = item[2];
|
||
lis.OrgName = item[3];
|
||
lis.MaterialName = item[4];
|
||
lis.MaterialNumber = item[5];
|
||
list.Add(lis);
|
||
|
||
}
|
||
return ResultList<ErpPurchaseInStockResultDto>.ReSuccess(list);
|
||
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
return ResultList<ErpPurchaseInStockResultDto>.ReFailure("错误",10001);
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|