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.BusinessParam; using JSMachine.WMS.RPC.ErpRPC.Dto.In.XRBusinessResult; using JSMachine.WMS.RPC.ErpRPC.Dto.Out; using JSMachine.WMS.RPC.ErpRPC.Dto.Out.BusinessResult; using JSMachine.WMS.RPC.ErpRPC.Dto.Out.IBSBusinessResult; using JSMachine.WMS.RPC.ErpRPC.Dto.Out.XRBusinessResult; using JSMachine.WMS.RPC.ErpRPC.IService; using Newtonsoft.Json; namespace JSMachine.WMS.RPC.ErpRPC.Service.IBS { [ErpTypeAttribute(ErpType.IBS)] public class IBSPaperStorageService : IPaperStorageService { private static readonly string IbsUrl = Global.AppSettings.ErpConfig.ErpUrl; private static readonly string QueryByPaperLabelUrl = Global.AppSettings.ErpConfig.QueryByPaperLabelUrl; private static readonly string PaperStockOutUrl = Global.AppSettings.ErpConfig.PaperStockOutUrl; private static readonly string QueryByPaperWidthAndCodeUrl = Global.AppSettings.ErpConfig.QueryByPaperWidthAndCodeUrl; private static readonly string RePaperStockInUrl = Global.AppSettings.ErpConfig.RePaperStockInUrl; private static readonly Dictionary header = new Dictionary { { "AppId", Global.AppSettings.ErpConfig.AppId }, { "AppKey", Global.AppSettings.ErpConfig.AppKey } }; /// /// 新增纸卷领用记录(原纸出库) /// /// /// public async Task AddPaperReceiptRecord(PaperReceiptRecordAddParam paperReceiptRecordParam) { try { var url = IbsUrl + PaperStockOutUrl; var parameters = new Dictionary { { "PaperLabel", paperReceiptRecordParam.Barcode } }; var resStr = await HttpRequestHelper.Post(url, parameters, header); if (resStr == null) { LogHelper.Error($"IBS原纸出库(PaperStockOut)失败"); return null; } var ibsResult = JsonConvert.DeserializeObject>(resStr); if (ibsResult == null || !ibsResult.Data.State) return null; return new PaperReceiptRecordAddResult(); } catch (Exception ex) { LogHelper.Error($"IBS原纸出库(PaperStockOut)失败: {ex.Message} \n {ex.StackTrace}"); return null; } } /// /// 新增纸卷领用记录(原纸出库) /// /// /// public async Task> AddPaperReceiptRecordSource(PaperReceiptRecordAddParam paperReceiptRecordParam) { var ibsResult = new IbsApiResult(); try { var url = IbsUrl + PaperStockOutUrl; var parameters = new Dictionary { { "PaperLabel", paperReceiptRecordParam.Barcode } }; var resStr = await HttpRequestHelper.Post(url, parameters, header); if (resStr == null) { LogHelper.Error($"IBS原纸出库(PaperStockOut)失败"); return null; } ibsResult = JsonConvert.DeserializeObject>(resStr); } catch (Exception ex) { LogHelper.Error($"IBS原纸出库(PaperStockOut)失败: {ex.Message} \n {ex.StackTrace}"); } ApiResult apiResult = new() { ResultCode = ibsResult != null && ibsResult.Data.State ? "200" : "500", ErrorMsg = ibsResult == null ? "" : ibsResult.Data.Messages }; return apiResult; } /// /// 新增纸卷退库记录(入库) /// /// /// /// public async Task AddPaperReturn(PaperReturnAddParam paperReturnAddParam) { try { var url = IbsUrl + RePaperStockInUrl; var parameters = new Dictionary { { "PaperLabel", paperReturnAddParam.Barcode }, { "Weight", paperReturnAddParam.ReturnQty.ToString() }, { "Meters", paperReturnAddParam.ReturnMeter.ToString() } }; var resStr = await HttpRequestHelper.Post(url, parameters, header); if (resStr == null) { LogHelper.Error($"IBS残卷回库(RePaperStockIn)失败"); return null; } var ibsResult = JsonConvert.DeserializeObject>(resStr); return ibsResult == null || !ibsResult.Data.State ? null : new PaperReturnAddResult(); } catch (Exception ex) { LogHelper.Error($"IBS残卷回库(RePaperStockIn)失败: {ex.Message} \n {ex.StackTrace}"); return null; } } /// /// 纸卷退库记录新增 /// 返回原生的接口调用信息 /// /// /// public async Task> AddPaperReturnSource(PaperReturnAddParam paperReturnAddParam) { var ibsResult = new IbsApiResult(); try { var url = IbsUrl + RePaperStockInUrl; var parameters = new Dictionary { { "PaperLabel", paperReturnAddParam.Barcode }, { "Weight", paperReturnAddParam.ReturnQty.ToString() }, { "Meters", paperReturnAddParam.ReturnMeter.ToString() } }; var resStr = await HttpRequestHelper.Post(url, parameters, header); if (resStr == null) { LogHelper.Error($"IBS残卷回库(RePaperStockIn)失败"); return null; } ibsResult = JsonConvert.DeserializeObject>(resStr); } catch (Exception ex) { LogHelper.Error($"IBS残卷回库(RePaperStockIn)失败: {ex.Message} \n {ex.StackTrace}"); } ApiResult apiResult = new() { ResultCode = ibsResult != null && ibsResult.Data != null && ibsResult.Data.State ? "200" : "500", ErrorMsg = ibsResult != null && ibsResult.Data != null ? ibsResult.Data.Messages : "" }; return apiResult; } public Task DelPaperReceiptRecord(PaperReceiptRecordDelParam paperReceiptRecordDelParam) { throw new NotImplementedException(); } public Task DelPaperReturn(PaperReturnDelParam paperReturnDelParam) { throw new NotImplementedException(); } /// /// 纸卷库存按条码查询(获取某卷纸的库存信息) /// /// /// public async Task QueryByBarcode(string barcode) { var ibsResult = new IbsApiResult(); try { var url = IbsUrl + QueryByPaperLabelUrl + barcode; var resStr = await HttpRequestHelper.Get(url, header); if (resStr == null) { LogHelper.Error($"IBS原纸信息,按原纸卷标查询(GetPaperMessage)出错"); return null; } ibsResult = JsonConvert.DeserializeObject>(resStr); } catch (Exception ex) { LogHelper.Error($"IBS原纸信息,按原纸卷标查询(GetPaperMessage)出错: {ex.Message} \n {ex.StackTrace}"); } if (ibsResult?.Data == null) { return null; } PaperStorageResult paperStorageResult = new() { Maker = ibsResult.Data.MakerName, ActualQty = ibsResult.Data.InWeight.ToString(), StockMeter = ibsResult.Data.Meters.ToString(), Paper = ibsResult.Data.PaperCode, GPerM2 = ibsResult.Data.PaperUnitWeight?.ToString(), PaperWidth = ibsResult.Data.PaperWidth.ToString(), Barcode = ibsResult.Data.PaperLabel, SuppShortName = ibsResult.Data.Phonetic, Location = ibsResult.Data.StockHouseCode, LocSub = ibsResult.Data.LocationMark, ObjID = ibsResult.Data.ID.ToString("N"), }; return paperStorageResult; } /// /// 原纸库存,按门幅、纸质编码查询 /// /// /// /// public async Task> QueryByPaperWidthAndCode(PaperPreparationQueryParam param) { var ibsResult = new IbsApiResult>(); try { var url = IbsUrl + QueryByPaperWidthAndCodeUrl + "?paperWidth=" + param.PaperWidth + "&paperCode=" + param.Paper.Replace("-", ""); var resStr = await HttpRequestHelper.Get(url, header); if (resStr == null) { LogHelper.Error($"IBS原纸库存,按门幅、纸质编码查询(GetPaperMessage)出错"); return null; } ibsResult = JsonConvert.DeserializeObject>>(resStr); } catch (Exception ex) { LogHelper.Error($"IBS原纸库存,按门幅、纸质编码查询(GetPaperMessage)出错: {ex.Message} \n {ex.StackTrace}"); } if (ibsResult?.Data == null) { return null; } var paperStorageResultList = new List(); foreach (PaperBaseInfoDto item in ibsResult.Data) { paperStorageResultList.Add(new PaperStockQueryResult { Paper = item.PaperCode, Barcode = item.PaperLabel, PaperWidth = item.PaperWidth.ToString(), StockMeter = item.Meters == 0m ? "" : Math.Round(item.Meters, 2).ToString(), ActualQty = item.InWeight == 0 ? "" : item.InWeight.ToString(), Location = item.StockHouseCode, LocSub = item.LocationMark, GPerM2 = item.PaperUnitWeight?.ToString(), SuppShortName = item.Phonetic, Maker = item.Phonetic, ObjID = item.ID.ToString("N"), }); } return paperStorageResultList; } public Task> RollNewQueryByTime(PaperStorageQueryParam param) { throw new NotImplementedException(); } /// /// 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(); } } }