加入erp的相关服务
This commit is contained in:
18
src/WMS.Web.Domain/IService/Public/IErpService.cs
Normal file
18
src/WMS.Web.Domain/IService/Public/IErpService.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto.Erp.Purchase;
|
||||
using WMS.Web.Core.Internal.Results;
|
||||
|
||||
namespace WMS.Web.Domain.IService.Public
|
||||
{
|
||||
public interface IErpService
|
||||
{
|
||||
/// <summary>
|
||||
/// erp:单据查询-采购入库单
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<ResultList<ErpPurchaseInStockResultDto>> BillQueryForPurchaseInStock();
|
||||
}
|
||||
}
|
||||
32
src/WMS.Web.Domain/Options/ErpOptions.cs
Normal file
32
src/WMS.Web.Domain/Options/ErpOptions.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Domain.Options
|
||||
{
|
||||
/// <summary>
|
||||
/// erp相关配置文件
|
||||
/// </summary>
|
||||
public class ErpOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// erp-请求地址
|
||||
/// </summary>
|
||||
public string EndpointAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 账号
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
public string Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// erp-Id
|
||||
/// </summary>
|
||||
public string ErpId { get; set; }
|
||||
}
|
||||
}
|
||||
89
src/WMS.Web.Domain/Services/Public/ErpService.cs
Normal file
89
src/WMS.Web.Domain/Services/Public/ErpService.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,5 +9,8 @@ namespace WMS.Web.Domain.Values
|
||||
/// </summary>
|
||||
public partial class ResultCodes
|
||||
{
|
||||
public static ValueTuple<int, string> Erp_Login_Error = (1001, "Erp登录返回错误");
|
||||
|
||||
public static ValueTuple<int, string> Erp_BillQuery_Error = (1002, "Erp单据查询返回错误");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user