206 lines
8.4 KiB
C#
206 lines
8.4 KiB
C#
using JSMachine.WMS.Common;
|
|||
|
|
using JSMachine.WMS.Infrastructure.Attributes;
|
||
|
|
using JSMachine.WMS.Infrastructure.Enums;
|
||
|
|
using JSMachine.WMS.Infrastructure.Helper;
|
||
|
|
using JSMachine.WMS.RPC.ErpRPC.Dto.In.XRBusinessResult;
|
||
|
|
using JSMachine.WMS.RPC.ErpRPC.Dto.Out.XRBusinessResult;
|
||
|
|
using JSMachine.WMS.RPC.ErpRPC.IService;
|
||
|
|
using Newtonsoft.Json;
|
||
|
|
using RestSharp;
|
||
|
|
|
||
|
|
namespace JSMachine.WMS.RPC.ErpRPC.Service.XinRong
|
||
|
|
{
|
||
|
|
[ErpTypeAttribute(ErpType.XinRong)]
|
||
|
|
public class XinRongPaperStorageService : IPaperStorageService
|
||
|
|
{
|
||
|
|
private static readonly string xrUrl = Global.AppSettings.ErpConfig.ErpUrl;
|
||
|
|
private static readonly string userkey = Global.AppSettings.ErpConfig.Userkey;
|
||
|
|
private static readonly string queryMateriaInforUrl = Global.AppSettings.ErpConfig.QueryMateriaInforUrl;
|
||
|
|
private static readonly string produceInUrl = Global.AppSettings.ErpConfig.ProduceInUrl;
|
||
|
|
private static readonly string produceOutUrl = Global.AppSettings.ErpConfig.ProduceOutUrl;
|
||
|
|
private static readonly string saleOutUrl = Global.AppSettings.ErpConfig.SaleOutUrl;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// PDA扫合格证码获取物料信息
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="barCode"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
public async Task<XRResultDto> GetMateriaInfo(string barCode)
|
||
|
|
{
|
||
|
|
var result = new XRResultDto();
|
||
|
|
try
|
||
|
|
{
|
||
|
|
string url = xrUrl + queryMateriaInforUrl;
|
||
|
|
var jsonParam = new
|
||
|
|
{
|
||
|
|
barCode = barCode,
|
||
|
|
user_key = userkey
|
||
|
|
};
|
||
|
|
string resStr = await HttpRequestHelper.RequestByJson(url, Method.POST, JsonConvert.SerializeObject(jsonParam), 15000);
|
||
|
|
if (string.IsNullOrEmpty(resStr))
|
||
|
|
{
|
||
|
|
LogHelper.Error($"PDA扫合格证码获取物料信息(GetMateriaInfo)失败");
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
var apiResultDto = JsonConvert.DeserializeObject<XRApiResult<XRResultDto>>(resStr);
|
||
|
|
result = JsonConvert.DeserializeObject<XRResultDto>(apiResultDto.result);
|
||
|
|
if (!result.success)
|
||
|
|
{
|
||
|
|
LogHelper.Error($"PDA扫合格证码获取物料信息(GetMateriaInfo)失败: {result.errors}");
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
LogHelper.Error($"PDA扫合格证码获取物料信息(GetMateriaInfo)失败: {ex.Message} \n {ex.StackTrace}");
|
||
|
|
}
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 生产入库
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="erpProduceInParam"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
public async Task<XRResultDto> AddProduceIn(ErpProduceInParam erpProduceInParam)
|
||
|
|
{
|
||
|
|
var result = new XRResultDto { success = false, status = 500 };
|
||
|
|
try
|
||
|
|
{
|
||
|
|
string url = xrUrl + produceInUrl;
|
||
|
|
var jsonParam = new ErpProduceInParam
|
||
|
|
{
|
||
|
|
barCode = erpProduceInParam.barCode,
|
||
|
|
materiaName = erpProduceInParam.materiaName,
|
||
|
|
materiaBatch = erpProduceInParam.materiaBatch,
|
||
|
|
materiaCode = erpProduceInParam.materiaCode,
|
||
|
|
materiaNum = erpProduceInParam.materiaNum,
|
||
|
|
user_key = userkey
|
||
|
|
};
|
||
|
|
string resStr = await HttpRequestHelper.RequestByJson(url, Method.POST, JsonConvert.SerializeObject(jsonParam), 30000);
|
||
|
|
if (string.IsNullOrEmpty(resStr))
|
||
|
|
{
|
||
|
|
result.errors = $"调用Erp生产入库(AddProduceIn)接口失败:{url}";
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
var apiResultDto = JsonConvert.DeserializeObject<XRApiResult<XRResultDto>>(resStr);
|
||
|
|
result = JsonConvert.DeserializeObject<XRResultDto>(apiResultDto.result);
|
||
|
|
|
||
|
|
if (result.success)
|
||
|
|
{
|
||
|
|
result.status = 200;
|
||
|
|
result.success = true;
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
result.errors = $"生产入库(AddProduceIn)接口返回失败:" + result.errors;
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
result.errors = $"生产入库(AddProduceIn)异常: {ex.Message} \n {ex.StackTrace}";
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 生产退库
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="erpProduceOutParam"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
public async Task<XRResultDto> AddProduceOut(ErpProduceOutParam erpProduceOutParam)
|
||
|
|
{
|
||
|
|
var result = new XRResultDto { success = false, status = 500 };
|
||
|
|
|
||
|
|
try
|
||
|
|
{
|
||
|
|
string url = xrUrl + produceOutUrl;
|
||
|
|
var jsonParam = new ErpProduceOutParam
|
||
|
|
{
|
||
|
|
produceReturnCode = erpProduceOutParam.produceReturnCode,
|
||
|
|
barCode = erpProduceOutParam.barCode,
|
||
|
|
materiaName = erpProduceOutParam.materiaName,
|
||
|
|
materiaBatch = erpProduceOutParam.materiaBatch,
|
||
|
|
materiaCode = erpProduceOutParam.materiaCode,
|
||
|
|
num = erpProduceOutParam.num,
|
||
|
|
user_key = userkey
|
||
|
|
};
|
||
|
|
string resStr = await HttpRequestHelper.RequestByJson(url, Method.POST, JsonConvert.SerializeObject(jsonParam), 30000);
|
||
|
|
if (string.IsNullOrEmpty(resStr))
|
||
|
|
{
|
||
|
|
result.errors = $"调用Erp生产退库(AddProduceOut)接口失败:{url}";
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
result = JsonConvert.DeserializeObject<XRResultDto>(resStr);
|
||
|
|
if (result.success)
|
||
|
|
{
|
||
|
|
result.status = 200;
|
||
|
|
result.success = true;
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
result.errors = $"生产退库(AddProduceOut)接口返回失败:" + result.errors;
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
result.errors = $"生产退库(AddProduceOut)异常: {ex.Message} \n {ex.StackTrace}";
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 销售出库
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="erpSaleOutParam"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
public async Task<XRResultDto> AddSaleOut(StockOutParam erpSaleOutParam)
|
||
|
|
{
|
||
|
|
var result = new XRResultDto { success = false, status = 500 };
|
||
|
|
|
||
|
|
try
|
||
|
|
{
|
||
|
|
string url = xrUrl + saleOutUrl;
|
||
|
|
var jsonParam = new StockOutParam
|
||
|
|
{
|
||
|
|
saleNo = erpSaleOutParam.saleNo,
|
||
|
|
barCode = erpSaleOutParam.barCode,
|
||
|
|
materiaCode = erpSaleOutParam.materiaCode,
|
||
|
|
num = erpSaleOutParam.num,
|
||
|
|
materiaBatch = erpSaleOutParam.materiaBatch,
|
||
|
|
user_key = userkey
|
||
|
|
|
||
|
|
};
|
||
|
|
string resStr = await HttpRequestHelper.RequestByJson(url, Method.POST, JsonConvert.SerializeObject(jsonParam), 30000);
|
||
|
|
if (string.IsNullOrEmpty(resStr))
|
||
|
|
{
|
||
|
|
result.errors = $"调用Erp销售出库(AddSaleOut)接口失败:{url}";
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
var apiResultDto = JsonConvert.DeserializeObject<XRApiResult<XRResultDto>>(resStr);
|
||
|
|
result = JsonConvert.DeserializeObject<XRResultDto>(apiResultDto.result);
|
||
|
|
if (result.success)
|
||
|
|
{
|
||
|
|
result.status = 200;
|
||
|
|
result.success = true;
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
result.errors = $"销售出库(AddSaleOut)接口返回失败:" + result.errors;
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
result.errors = $"销售出库(AddSaleOut)异常: {ex.Message} \n {ex.StackTrace}";
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|