Browse Source

[fix]ASN生成BUG修复

master
贾荣国 2 years ago
parent
commit
20a45d1ce1
  1. 0
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/AsnFactory.cs
  2. 194
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/AsnFactory.cs
  3. 3
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/Program.cs
  4. 1
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/Win_in.Sfs.Scp.WebApi.Console.csproj
  5. 4
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/ASN_X12/ISA.cs

0
WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/AsnBackgroundWorker/AsnFactory.cs → WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/AsnFactory.cs

194
WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/AsnFactory.cs

@ -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<TS_BARCODE> 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<Item>();
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<string,string> itemLabelCodes)
{
var item = new Item();
item.SetHL()
.SetLIN(itemCode)
.SetSN1(qty, uom, accumQty)
.SetPRF(poNumber)
.SetCLD(loadQty, unitQty)
.SetREF_LS_LTs(itemLabelCodes);
return item;
}
}
}

3
WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/Program.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Win_in.Sfs.Scp.v1.Domain.Asns; using Win_in.Sfs.Scp.v1.Domain.Asns;
using Win_in.Sfs.Scp.WebApi;
namespace Win_in.Sfs.Scp.WebApi.Console namespace Win_in.Sfs.Scp.WebApi.Console
{ {
@ -12,7 +13,7 @@ namespace Win_in.Sfs.Scp.WebApi.Console
var asnFactory = new AsnFactory(); var asnFactory = new AsnFactory();
var scpAsn = InitTbAsn(); var scpAsn = InitTbAsn();
var barcodes = InitTsBarcodes(); var barcodes = InitTsBarcodes();
var asn = asnFactory.CreateAsnX128563060(scpAsn, barcodes); var asn = asnFactory.CreateAsnX128563060("IACNA_ID", scpAsn, barcodes);
var ediString = asn.ToString(); var ediString = asn.ToString();
System.Console.WriteLine(ediString); System.Console.WriteLine(ediString);
System.Console.Read(); System.Console.Read();

1
WebApiService/src/Win_in.Sfs.Scp.WebApi.Console/Win_in.Sfs.Scp.WebApi.Console.csproj

@ -7,6 +7,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Win_in.Sfs.Scp.v1.Domain\Win_in.Sfs.Scp.v1.Domain.csproj" /> <ProjectReference Include="..\Win_in.Sfs.Scp.v1.Domain\Win_in.Sfs.Scp.v1.Domain.csproj" />
<ProjectReference Include="..\Win_in.Sfs.Scp.WebApi.Application\Win_in.Sfs.Scp.WebApi.Application.csproj" />
<ProjectReference Include="..\Win_in.Sfs.Scp.WebApi.Domain\Win_in.Sfs.Scp.WebApi.Domain.csproj" /> <ProjectReference Include="..\Win_in.Sfs.Scp.WebApi.Domain\Win_in.Sfs.Scp.WebApi.Domain.csproj" />
</ItemGroup> </ItemGroup>

4
WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/ASN_X12/ISA.cs

@ -148,8 +148,8 @@ public class ISA
ISA06 = senderId.PadRight(15); ISA06 = senderId.PadRight(15);
ISA08 = receiverId.PadRight(15); ISA08 = receiverId.PadRight(15);
ISA09 = datetime.ToString(X12Const.DateFormat); ISA09 = datetime.ToString(X12Const.DateFormat);
ISA09 = datetime.ToString(X12Const.TimeFormat); ISA10 = datetime.ToString(X12Const.TimeFormat);
ISA10 = asnCode.PadRight(9); ISA13 = asnCode.PadRight(9);
ISA15 = envType.ToString(); ISA15 = envType.ToString();
ISA02 = authorization.PadRight(10); ISA02 = authorization.PadRight(10);
ISA04 = security.PadRight(10); ISA04 = security.PadRight(10);

Loading…
Cancel
Save