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.BusinessDto; using JSMachine.WMS.RPC.ErpRPC.Dto.In; using JSMachine.WMS.RPC.ErpRPC.Dto.In.BusinessParam; using JSMachine.WMS.RPC.ErpRPC.Dto.Out; using JSMachine.WMS.RPC.ErpRPC.Dto.Out.BusinessResult; using JSMachine.WMS.RPC.ErpRPC.IService; using Newtonsoft.Json; using RestSharp; using JSMachine.WMS.RPC.ErpRPC.Dto.Out.XRBusinessResult; using JSMachine.WMS.RPC.ErpRPC.Dto.In.XRBusinessResult; namespace JSMachine.WMS.RPC.ErpRPC.Service.IBS { [ErpTypeAttribute(ErpType.ChenLong)] public class ChenLongPaperStorageService : IPaperStorageService { private static string url = $"{Global.AppSettings.ErpConfig.ErpUrl}/"; /// /// 纸卷领用记录新增 /// /// /// public async Task AddPaperReceiptRecord(PaperReceiptRecordAddParam paperReceiptRecordParam) { var result = await AddPaperReceiptRecordSource(paperReceiptRecordParam); return result ?.Data ?.Data ?.FirstOrDefault() ?.ALL; } /// /// 纸卷领用记录新增 /// 返回原生的接口调用信息 /// /// /// public async Task> AddPaperReceiptRecordSource(PaperReceiptRecordAddParam paperReceiptRecordParam) { var apiResultDto = new ApiResult(); try { string resStr = await HttpRequestHelper.RequestByJson( url + "ODIRollPickInsert", Method.POST, RequestParam.CreateJsonParam(ActionID.ODIRollPickInsert, paperReceiptRecordParam) ); if (string.IsNullOrEmpty(resStr)) { LogHelper.Error($"Erp纸卷{paperReceiptRecordParam.Barcode}领用记录新增(ODIRollPickInsert)出错"); return null; } apiResultDto = JsonConvert.DeserializeObject>(resStr); } catch (Exception ex) { LogHelper.Error($"Erp纸卷{paperReceiptRecordParam.Barcode}领用记录新增(ODIRollPickInsert)出错: {ex.Message} \n {ex.StackTrace}"); } return apiResultDto; } /// /// 纸卷退库记录新增 /// /// /// public async Task AddPaperReturn(PaperReturnAddParam paperReturnAddParam) { var result = await AddPaperReturnSource(paperReturnAddParam); return result ?.Data ?.Data ?.FirstOrDefault() ?.ALL; } /// /// 纸卷退库记录新增 /// 返回原生的接口调用信息 /// /// /// public async Task> AddPaperReturnSource(PaperReturnAddParam paperReturnAddParam) { ApiResult apiResultDto = new ApiResult(); try { string resStr = await HttpRequestHelper.RequestByJson( url + "ODIRollReturnInsert", Method.POST, RequestParam.CreateJsonParam(ActionID.ODIRollReturnInsert, paperReturnAddParam) ); if (string.IsNullOrEmpty(resStr)) { LogHelper.Error($"Erp纸卷{paperReturnAddParam.Barcode}退库记录新增(ODIRollReturnInsert)出错"); return null; } apiResultDto = JsonConvert.DeserializeObject>(resStr); } catch (Exception ex) { LogHelper.Error($"Erp纸卷{paperReturnAddParam.Barcode}退库记录新增(ODIRollReturnInsert)出错: {ex.Message} \n {ex.StackTrace}"); } return apiResultDto; } /// /// 纸卷领用记录删除 /// /// /// public async Task DelPaperReceiptRecord(PaperReceiptRecordDelParam paperReceiptRecordDelParam) { var result = false; try { string resStr = await HttpRequestHelper.RequestByDic( url, Method.POST, RequestParam.CreateParam(ActionID.ODIRollPickDelete, paperReceiptRecordDelParam) ); if (string.IsNullOrEmpty(resStr)) { LogHelper.Error($"Erp纸卷{paperReceiptRecordDelParam.Barcode}领用记录删除(ODIRollPickDelete)出错"); return result; } ApiResult apiResultDto = JsonConvert.DeserializeObject>(resStr); result = apiResultDto.ResultCode == "200"; } catch (Exception ex) { LogHelper.Error($"Erp纸卷{paperReceiptRecordDelParam.Barcode}领用记录删除(ODIRollPickDelete)出错: {ex.Message} \n {ex.StackTrace}"); } return result; } /// /// 纸卷库存按条码查询(获取某卷纸的库存信息) /// /// /// public async Task QueryByBarcode(string barcode) { ApiReturnResult apiResultDto = new(); try { var resStr = await HttpRequestHelper.RequestByJson( url + "ODIRollStockQueryByBarcode", Method.POST, RequestParam.CreateJsonParam( ActionID.ODIRollStockQueryByBarcode, new PaperStorageParam { Barcode = barcode }) ); if (string.IsNullOrEmpty(resStr)) { LogHelper.Error($"Erp纸卷{barcode}库存按条码查询(ODIRollStockQueryByBarcode)出错"); return null; } apiResultDto = JsonConvert.DeserializeObject>(resStr); if (apiResultDto != null) { var item = apiResultDto.Data; //ActualQty if (item.ActualQty == "0" || string.IsNullOrEmpty(item.ActualQty)) { item.ActualQty = "0"; } else { if (item.ActualQty.Contains(".")) { item.ActualQty = item.ActualQty.Substring(0, item.ActualQty.LastIndexOf(".")); } else { item.ActualQty = item.ActualQty; } } //StockMeter if (item.StockMeter == "0" || string.IsNullOrEmpty(item.StockMeter)) { item.StockMeter = "0"; } else { if (item.StockMeter.Contains(".")) { item.StockMeter = item.StockMeter.Substring(0, item.StockMeter.LastIndexOf(".")); } else { item.StockMeter = item.StockMeter; } } //GPerM2 if (item.GPerM2 == "0" || string.IsNullOrEmpty(item.GPerM2)) { item.GPerM2 = "0"; } else { if (item.GPerM2.Contains(".")) { item.GPerM2 = item.GPerM2.Substring(0, item.GPerM2.LastIndexOf(".")); } else { item.GPerM2 = item.GPerM2; } } //PaperWidth if (item.PaperWidth == "0" || string.IsNullOrEmpty(item.PaperWidth)) { item.PaperWidth = "0"; } else { if (item.PaperWidth.Contains(".")) { item.PaperWidth = item.PaperWidth.Substring(0, item.PaperWidth.LastIndexOf(".")); } else { item.PaperWidth = item.PaperWidth; } } } } catch (Exception ex) { LogHelper.Error($"Erp纸卷{barcode}库存按条码查询(ODIRollStockQueryByBarcode)出错: {ex.Message} \n {ex.StackTrace}"); } return apiResultDto?.Data; } /// /// 原纸退纸记录删除 /// /// public async Task DelPaperReturn(PaperReturnDelParam paperReturnDelParam) { var result = false; try { string resStr = await HttpRequestHelper.RequestByDic( url, Method.POST, RequestParam.CreateParam(ActionID.ODIRollReturnDelete, paperReturnDelParam) ); if (string.IsNullOrEmpty(resStr)) { LogHelper.Error($"Erp原纸{paperReturnDelParam.Barcode}退纸记录删除(ODIRollReturnDelete)出错"); return result; } ApiResult apiResultDto = JsonConvert.DeserializeObject>(resStr); result = apiResultDto.ResultCode == "200"; } catch (Exception ex) { LogHelper.Error($"Erp原纸{paperReturnDelParam.Barcode}退纸记录删除(ODIRollReturnDelete)出错: {ex.Message} \n {ex.StackTrace}"); } return result; } /// /// 原纸库存,按门幅、纸质编码查询 /// /// /// public async Task> QueryByPaperWidthAndCode(PaperPreparationQueryParam param) { ApiReturnResult> apiResultDto = new(); try { if (param.Paper.Contains("-")) { param.Paper = param.Paper.Replace("-", ""); } string resStr = await HttpRequestHelper.RequestByJson( url+ "ODIRollStockQuery", Method.POST, RequestParam.CreateJsonParam( ActionID.ODIRollStockQuery, new PaperPreparationQueryParam { Paper = param.Paper, PaperWidth = param.PaperWidth }) ); if (string.IsNullOrEmpty(resStr)) { LogHelper.Error($"Erp纸卷库存,按门幅、纸质编码查询(ODIRollStockQuery)出错"); return null; } apiResultDto = JsonConvert.DeserializeObject>>(resStr); if (apiResultDto != null) { foreach (var item in apiResultDto?.Data) { //ActualQty if (item.ActualQty == "0" || string.IsNullOrEmpty(item.ActualQty)) { item.ActualQty = "0"; } else { if (item.ActualQty.Contains(".")) { item.ActualQty = item.ActualQty.Substring(0, item.ActualQty.LastIndexOf(".")); } else { item.ActualQty = item.ActualQty; } } //StockMeter if (item.StockMeter == "0" || string.IsNullOrEmpty(item.StockMeter)) { item.StockMeter = "0"; } else { if (item.StockMeter.Contains(".")) { item.StockMeter = item.StockMeter.Substring(0, item.StockMeter.LastIndexOf(".")); } else { item.StockMeter = item.StockMeter; } } //GPerM2 if (item.GPerM2 == "0" || string.IsNullOrEmpty(item.GPerM2)) { item.GPerM2 = "0"; } else { if (item.GPerM2.Contains(".")) { item.GPerM2 = item.GPerM2.Substring(0, item.GPerM2.LastIndexOf(".")); } else { item.GPerM2 = item.GPerM2; } } //PaperWidth if (item.PaperWidth == "0" || string.IsNullOrEmpty(item.PaperWidth)) { item.PaperWidth = "0"; } else { if (item.PaperWidth.Contains(".")) { item.PaperWidth = item.PaperWidth.Substring(0, item.PaperWidth.LastIndexOf(".")); } else { item.PaperWidth = item.PaperWidth; } } } } } catch (Exception ex) { LogHelper.Error($"Erp纸卷库存,按门幅、纸质编码查询(ODIRollStockQuery)出错: {ex.Message} \n {ex.StackTrace}"); } return apiResultDto?.Data; } /// /// 新卷入库信息查询(按起始时间) /// /// /// public async Task> RollNewQueryByTime(PaperStorageQueryParam param) { List apiResultDto = new List(); try { string resStr = await HttpRequestHelper.RequestByDic( url, Method.POST, RequestParam.CreateParam( ActionID.ODIRollNewQueryByTime, new PaperStorageQueryParam { StartTime = param.StartTime, EndTime = param.EndTime }) ); if (string.IsNullOrEmpty(resStr)) { LogHelper.Error($"新卷入库信息查询(按起始时间)(ODIRollNewQueryByTime)出错"); return null; } apiResultDto = JsonConvert.DeserializeObject>(resStr); } catch (Exception ex) { LogHelper.Error($"新卷入库信息查询(按起始时间)(ODIRollNewQueryByTime)出错: {ex.Message} \n {ex.StackTrace}"); } return apiResultDto; } /// /// PDA扫合格证码获取物料信息 /// /// public async Task GetMateriaInfo(string barCode) { throw new NotImplementedException(); } /// /// 生产入库 /// /// public async Task AddProduceIn(ErpProduceInParam erpMateriaInDto) { throw new NotImplementedException(); } /// /// 生产退库 /// /// /// public async Task AddProduceOut(ErpProduceOutParam erpProduceOutParam) { throw new NotImplementedException(); } /// /// 销售出库 /// /// /// public async Task AddSaleOut(ErpSaleOutParam erpSaleOutParam) { throw new NotImplementedException(); } } }