You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
192 lines
7.1 KiB
192 lines
7.1 KiB
3 years ago
|
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 = "receiver";
|
||
|
var shipTime = scpAsn.ShipTime ?? DateTime.Now;
|
||
|
|
||
|
var envType = ISA.EnvType.P;
|
||
|
var authorization = " ";
|
||
|
var security = " ";
|
||
|
//初始化ASN单
|
||
|
var asn = InitAsn(asnCode,senderId,receiverId,shipTime,envType,authorization,security);
|
||
|
|
||
|
var functionalGroupCode = "0000000000";
|
||
|
//初始化功能组
|
||
|
var functionalGroup = InitFunctionalGroup(senderId,receiverId,shipTime,functionalGroupCode);
|
||
|
|
||
|
var shipNoticeCode = "0001";
|
||
|
var datetimeType = "011";
|
||
|
//初始化发货单
|
||
|
var shipNotice = InitShipNotice(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";//车牌号
|
||
|
//初始化发货明细
|
||
|
var shipment = InitShipment(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);
|
||
|
//设置发货单汇总
|
||
|
shipNotice.SetCTT();
|
||
|
//添加发货单
|
||
|
functionalGroup.AddShipNotice(shipNotice);
|
||
|
functionalGroup.SetGE(functionalGroupCode);
|
||
|
//添加功能组
|
||
|
asn.AddFunctionGroup(functionalGroup);
|
||
|
|
||
|
return asn;
|
||
|
}
|
||
|
|
||
|
private ASN_X12_856_3060 InitAsn(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)
|
||
|
.SetIEA(asnCode);
|
||
|
return asn;
|
||
|
}
|
||
|
|
||
|
private FunctionalGroup InitFunctionalGroup(string senderId, string receiverId, DateTime datetime,
|
||
|
string functionalGroupCode)
|
||
|
{
|
||
|
var functionGroup = new FunctionalGroup();
|
||
|
functionGroup
|
||
|
.SetGS(senderId, receiverId, datetime, functionalGroupCode);
|
||
|
return functionGroup;
|
||
|
}
|
||
|
|
||
|
private ShipNotice InitShipNotice(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)
|
||
|
.SetSE(shipNoticeCode);
|
||
|
return shipNotice;
|
||
|
}
|
||
|
|
||
|
private Shipment InitShipment(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)
|
||
|
;
|
||
|
|
||
|
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, List<string> itemLabelCodes)
|
||
|
{
|
||
|
|
||
|
var item = new Item();
|
||
|
item.SetHL()
|
||
|
.SetLIN(itemCode)
|
||
|
.SetSN1(qty, uom, accumQty)
|
||
|
.SetPRF(poNumber)
|
||
|
.SetCLD(loadQty, unitQty)
|
||
|
.SetREF_LSs(itemLabelCodes);
|
||
|
return item;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|