From 20a45d1ce1b93d8e5ca3cbbd21878130e651939b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=BE=E8=8D=A3=E5=9B=BD?= Date: Wed, 1 Jun 2022 08:39:01 +0800 Subject: [PATCH] =?UTF-8?q?[fix]ASN=E7=94=9F=E6=88=90BUG=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Asns}/AsnFactory.cs | 0 .../AsnFactory.cs | 194 ------------------ .../Win_in.Sfs.Scp.WebApi.Console/Program.cs | 3 +- .../Win_in.Sfs.Scp.WebApi.Console.csproj | 1 + .../ASN_X12/ISA.cs | 4 +- 5 files changed, 5 insertions(+), 197 deletions(-) rename WebApiService/src/{Win_in.Sfs.Scp.WebApi.HttpApi.Host/AsnBackgroundWorker => Win_in.Sfs.Scp.WebApi.Application/Asns}/AsnFactory.cs (100%) delete mode 100644 WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/AsnFactory.cs diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/AsnBackgroundWorker/AsnFactory.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/AsnFactory.cs similarity index 100% rename from WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/AsnBackgroundWorker/AsnFactory.cs rename to WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/AsnFactory.cs diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/AsnFactory.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/AsnFactory.cs deleted file mode 100644 index 5ecc6d1..0000000 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/AsnFactory.cs +++ /dev/null @@ -1,194 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Win_in.Sfs.Scp.v1.Domain.Asns; -using Win_in.Sfs.Scp.WebApi.Asns; - -namespace Win_in.Sfs.Scp.WebApi.Console -{ - public class AsnFactory - { - public ASN_X12_856_3060 CreateAsnX128563060(TB_ASN scpAsn,List barcodes) - { - - var asnCode = scpAsn.AsnBillNum; - var senderId = scpAsn.VendId; - var receiverId = "IACNA_ID"; - var shipTime = scpAsn.ShipTime ?? DateTime.Now; - - var envType = ISA.EnvType.P; - var authorization = ""; - var security = ""; - //初始化ASN单 - var asn = CreateAsn(asnCode,senderId,receiverId,shipTime,envType,authorization,security); - - var functionalGroupCode = "123456789"; - //初始化功能组 - var functionalGroup = CreateFunctionalGroup(senderId,receiverId,shipTime,functionalGroupCode); - - var shipNoticeCode = "0001"; - var datetimeType = "011"; - //初始化发货单 - var shipNotice = CreateShipNotice(shipNoticeCode,functionalGroupCode,shipTime,datetimeType); - - var gValue = 0; - var gUom = "KG"; - var nValue = 0; - var nUom = "KG"; - var routeSequenceCode = "B"; - var identificationCode = "PSTV"; - var mode = "LT"; - var equipmentCode = "TL"; - var equipmentNumber = "123456";//TODO 车牌号 - //初始化发货明细 - var shipment = CreateShipment(shipNotice,gValue,gUom,nValue,nUom,routeSequenceCode,identificationCode,mode, - equipmentCode,equipmentNumber,functionalGroupCode,functionalGroupCode,senderId,receiverId); - - - //计算与添加托盘和尾箱 - var palletCodes = barcodes.Select(p => p.Extend2).Distinct().ToList(); - foreach (var palletCode in palletCodes) - { - var palletBarcodes = barcodes.Where(p => p.Extend2==palletCode).ToList(); - - var items = new List(); - var group = palletBarcodes - .GroupBy(p => new { p.PartCode, p.Qty, p.Batch, p.PoUnit, p.PoBillNum,p.PackQty}) - .Select(p => new - { - p.Key.PartCode, - p.Key.Qty, - p.Key.Batch, - p.Key.PoUnit, - p.Key.PoBillNum, - p.Key.PackQty, - Labels = p.Select(p=>p.BarCode).ToList() - }) - .ToList(); - - foreach (var b in group) - { - var accumQty = 0;//TODO 如何计算 - var loadQty = b.Labels.Count; - var unitQty = b.PackQty; - var item = CreateItem(b.PartCode, loadQty * unitQty, b.PoUnit, accumQty, b.PoBillNum, loadQty, unitQty,b.Labels); - items.Add(item); - } - - //如果托标签为空,当作尾箱处理 - if (string.IsNullOrEmpty(palletCode)) - { - foreach (var item in items) - { - shipment.AddOrphanItem(shipNotice,item); - } - } - //添加托盘 - else - { - var tare = CreateTare(palletCode); - shipment.AddTare(shipNotice,tare); - foreach (var item in items) - { - tare.AddItem(shipNotice, item); - } - } - - } - - //TODO 如何获取包装代码,或者规则是什么? - var packagingCode = "PLT90"; - //装载量需要在添加托盘和尾箱后再计算 - var loadingQty = shipment.Tares.Count+shipment.OrphanItems.Count; - shipment.SetTD1(packagingCode, loadingQty); - - shipNotice - .AddShipment(shipment) //添加发货明细 - .SetCTT() //设置发货单汇总 - .SetSE(shipNoticeCode); //设置发货明细结尾 - //添加发货单 - functionalGroup - .AddShipNotice(shipNotice) - .SetGE(functionalGroupCode); - //添加功能组 - asn - .AddFunctionGroup(functionalGroup) - .SetIEA(asnCode); - return asn; - } - - private ASN_X12_856_3060 CreateAsn(string asnCode, string senderId, string receiverId, DateTime datetime, - ISA.EnvType envType = ISA.EnvType.P, string authorization = "", string security = "") - { - var asn = new ASN_X12_856_3060(); - asn.SetISA(asnCode, senderId, receiverId, datetime, envType, authorization, security); - return asn; - } - - private FunctionalGroup CreateFunctionalGroup(string senderId, string receiverId, DateTime datetime, - string functionalGroupCode) - { - var functionGroup = new FunctionalGroup(); - functionGroup.SetGS(senderId, receiverId, datetime, functionalGroupCode); - return functionGroup; - } - - private ShipNotice CreateShipNotice(string shipNoticeCode, string noticeNumber, DateTime datetime, - string datetimeType="011", string purpose = "00") - { - var shipNotice = new ShipNotice(); - shipNotice - .SetST(shipNoticeCode) - .SetBSN(noticeNumber, datetime, purpose) - .SetDTM(datetime, datetimeType); - shipNotice.AddSegment(4); - return shipNotice; - } - - private Shipment CreateShipment(ShipNotice shipNotice, decimal gValue, string gUom, decimal nValue, string nUom, - string routeSequenceCode, string identificationCode, string mode, string equipmentCode, - string equipmentNumber, string bmRefValue, string pkRefValue, string senderId, string receiverId) - { - var shipment = new Shipment(); - shipment - .SetHL() - .SetMEA_G(gValue, gUom) - .SetMEA_N(nValue, nUom) - .SetTD5(routeSequenceCode, identificationCode, mode) - .SetTD3(equipmentCode, equipmentNumber) - .SetREF_BM(bmRefValue) - .SetREF_PK(pkRefValue) - .SetN1_SF(senderId) - .SetN1_ST(receiverId) - ; - shipNotice.AddSegment(10); - - return shipment; - } - - private Tare CreateTare(string tareLabelCode) - { - var tare = new Tare(); - tare.SetHL() - .SetREF_LS(tareLabelCode); - - return tare; - } - - private Item CreateItem(string itemCode, decimal qty, string uom, int accumQty, - string poNumber, int loadQty, decimal unitQty, Dictionary itemLabelCodes) - { - - var item = new Item(); - item.SetHL() - .SetLIN(itemCode) - .SetSN1(qty, uom, accumQty) - .SetPRF(poNumber) - .SetCLD(loadQty, unitQty) - .SetREF_LS_LTs(itemLabelCodes); - return item; - } - - - } -} \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/Program.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/Program.cs index afcdb4d..49d22ba 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/Program.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/Program.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Win_in.Sfs.Scp.v1.Domain.Asns; +using Win_in.Sfs.Scp.WebApi; namespace Win_in.Sfs.Scp.WebApi.Console { @@ -12,7 +13,7 @@ namespace Win_in.Sfs.Scp.WebApi.Console var asnFactory = new AsnFactory(); var scpAsn = InitTbAsn(); var barcodes = InitTsBarcodes(); - var asn = asnFactory.CreateAsnX128563060(scpAsn, barcodes); + var asn = asnFactory.CreateAsnX128563060("IACNA_ID", scpAsn, barcodes); var ediString = asn.ToString(); System.Console.WriteLine(ediString); System.Console.Read(); diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/Win_in.Sfs.Scp.WebApi.Console.csproj b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/Win_in.Sfs.Scp.WebApi.Console.csproj index 58740eb..831fa61 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/Win_in.Sfs.Scp.WebApi.Console.csproj +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/Win_in.Sfs.Scp.WebApi.Console.csproj @@ -7,6 +7,7 @@ + diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/ASN_X12/ISA.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/ASN_X12/ISA.cs index 6bc7e35..2adebf7 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/ASN_X12/ISA.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/ASN_X12/ISA.cs @@ -148,8 +148,8 @@ public class ISA ISA06 = senderId.PadRight(15); ISA08 = receiverId.PadRight(15); ISA09 = datetime.ToString(X12Const.DateFormat); - ISA09 = datetime.ToString(X12Const.TimeFormat); - ISA10 = asnCode.PadRight(9); + ISA10 = datetime.ToString(X12Const.TimeFormat); + ISA13 = asnCode.PadRight(9); ISA15 = envType.ToString(); ISA02 = authorization.PadRight(10); ISA04 = security.PadRight(10);