|
|
@ -5,6 +5,7 @@ using System.Runtime.Serialization; |
|
|
|
using System.Text.Json; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using AutoMapper; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
@ -32,17 +33,20 @@ namespace Win_in.Sfs.Scp.WebApi |
|
|
|
{ |
|
|
|
private readonly AsnOptions _options; |
|
|
|
private readonly IObjectMapper _objectMapper; |
|
|
|
private readonly IPostService _postService; |
|
|
|
|
|
|
|
public AsnBackgroundWorker( |
|
|
|
AbpAsyncTimer timer, |
|
|
|
IOptions<AsnOptions> options, |
|
|
|
IServiceScopeFactory serviceScopeFactory, |
|
|
|
IObjectMapper objectMapper |
|
|
|
IObjectMapper objectMapper, |
|
|
|
IPostService postService |
|
|
|
) : base(timer, serviceScopeFactory) |
|
|
|
{ |
|
|
|
_options = options.Value; |
|
|
|
_objectMapper = objectMapper; |
|
|
|
Timer.Period = options.Value.PeriodSeconds * 1000; //default 5 minutes
|
|
|
|
_postService = postService; |
|
|
|
} |
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
@ -96,24 +100,60 @@ namespace Win_in.Sfs.Scp.WebApi |
|
|
|
await scpAsnManager.GetUnreadAsnsAsync(siteCode, lastUid, _options.BatchSize); |
|
|
|
|
|
|
|
Logger.LogInformation($"{siteCode}: {scpAsns.Count} ASNs were Found"); |
|
|
|
|
|
|
|
var baseUrl = _options.BaseUrl; |
|
|
|
var username = _options.Username; |
|
|
|
var password = _options.Password; |
|
|
|
foreach (var asn in scpAsns) |
|
|
|
{ |
|
|
|
var barcodes = await scpAsnManager.GetBarcodesAsync(siteCode, asn.AsnBillNum); |
|
|
|
|
|
|
|
var noPoAsn = CreateNoPoAsn(asn, barcodes); |
|
|
|
asnX12List.Add(noPoAsn); |
|
|
|
|
|
|
|
asn.IsPort = 1; |
|
|
|
var apiUrl = ""; |
|
|
|
|
|
|
|
if (asn.AsnBillNum.StartsWith(_options.QadAsnPrefix))//ASN to QAD
|
|
|
|
var jsonString = noPoAsn.JsonString; |
|
|
|
try |
|
|
|
{ |
|
|
|
//埃驰要求不传托盘信息 @20220905
|
|
|
|
barcodes.ForEach(p => p.PalletCode = ""); |
|
|
|
//埃驰要求不传托盘信息 @20220905
|
|
|
|
|
|
|
|
var asnX12 = CreateX12Asn(site, asn, barcodes); |
|
|
|
asnX12List.Add(asnX12); |
|
|
|
var a = 0; |
|
|
|
var ss = 8 / a; |
|
|
|
var result = await _postService.PostAsync(baseUrl, apiUrl, jsonString, username, password); |
|
|
|
if (result == null) |
|
|
|
{ |
|
|
|
noPoAsn.SetError("Boomi", EnumExchangeDataErrorCode.None, "Boomi没有返回值"); |
|
|
|
} |
|
|
|
if (result?.Status == "SUCCESS") |
|
|
|
{ |
|
|
|
noPoAsn.SetSuccess("Boomi", "Boomi接口执行成功"); |
|
|
|
} |
|
|
|
else if (result?.Status == "EXCEPTION") |
|
|
|
{ |
|
|
|
noPoAsn.SetError("Boomi", EnumExchangeDataErrorCode.Exception, "EXCEPTION" + result?.ErrorMessage); |
|
|
|
} |
|
|
|
else if (result?.Status == "FAIL") |
|
|
|
{ |
|
|
|
noPoAsn.SetError("Boomi", EnumExchangeDataErrorCode.FAIL, "FAIL" + result?.ErrorMessage); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
Logger.LogException(e); |
|
|
|
e = e.GetBaseException(); |
|
|
|
noPoAsn.SetError("Boomi", EnumExchangeDataErrorCode.Exception, "接口程序异常"+e.Message); |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
asnX12List.Add(noPoAsn); |
|
|
|
} |
|
|
|
//if (asn.AsnBillNum.StartsWith(_options.QadAsnPrefix))//ASN to QAD
|
|
|
|
//{
|
|
|
|
// //埃驰要求不传托盘信息 @20220905
|
|
|
|
// barcodes.ForEach(p => p.PalletCode = "");
|
|
|
|
// //埃驰要求不传托盘信息 @20220905
|
|
|
|
|
|
|
|
// var asnX12 = CreateX12Asn(site, asn, barcodes);
|
|
|
|
// asnX12List.Add(asnX12);
|
|
|
|
//}
|
|
|
|
|
|
|
|
Logger.LogInformation($"{siteCode}:{asn.Id} {asn.AsnBillNum} was loaded"); |
|
|
|
} |
|
|
@ -132,29 +172,29 @@ namespace Win_in.Sfs.Scp.WebApi |
|
|
|
|
|
|
|
Logger.LogInformation("Get ASN from SCP: Complete"); |
|
|
|
} |
|
|
|
|
|
|
|
private X12Asn CreateNoPoAsn(TB_ASN asn, List<TS_BARCODE> barcodes) |
|
|
|
{ |
|
|
|
|
|
|
|
var asnMstr = new AsnMstr() |
|
|
|
{ |
|
|
|
UID = asn.Id, |
|
|
|
Company = asn.Site, |
|
|
|
Site = asn.Site, |
|
|
|
AsnNbr = asn.AsnBillNum, |
|
|
|
RpNbr = asn.AskBillNum, |
|
|
|
PoNbr = asn.PoBillNum, |
|
|
|
VendorCode = asn.VendId, |
|
|
|
Contacts = asn.ReceiveUser, |
|
|
|
Phone = "", |
|
|
|
TruckNbr = asn.PlateNumber, |
|
|
|
Whse = "", |
|
|
|
Dock = asn.Dock, |
|
|
|
ShipDate = asn.ShipTime, |
|
|
|
DueDate = asn.ReceiveTime, |
|
|
|
TimeWindow =asn.ReceivedPort, |
|
|
|
Remark = asn.Remark, |
|
|
|
Subsite =asn.WebSubSite, |
|
|
|
traceId = asn.Site+"-"+ asn.Id .ToString()+ "-"+ Guid.NewGuid().ToString(), |
|
|
|
uid = asn.Id, |
|
|
|
company = asn.Site, |
|
|
|
site = asn.Site, |
|
|
|
asnNbr = asn.AsnBillNum, |
|
|
|
rpNbr = asn.AskBillNum, |
|
|
|
poNbr = asn.PoBillNum, |
|
|
|
vendorCode = asn.VendId, |
|
|
|
contacts = asn.ReceiveUser, |
|
|
|
phone = "", |
|
|
|
status = null, |
|
|
|
truckNbr = asn.PlateNumber, |
|
|
|
whse = "", |
|
|
|
dock = asn.Dock, |
|
|
|
shipDate = asn.ShipTime, |
|
|
|
dueDate = asn.ReceiveTime, |
|
|
|
timeWindow = asn.ReceivedPort, |
|
|
|
remark = asn.Remark, |
|
|
|
}; |
|
|
|
if (string.IsNullOrEmpty(asnMstr.TimeWindow)) |
|
|
|
{ |
|
|
@ -164,28 +204,28 @@ namespace Win_in.Sfs.Scp.WebApi |
|
|
|
{ |
|
|
|
var det = new AsnDet() |
|
|
|
{ |
|
|
|
AsnNbr = asn.AsnBillNum, |
|
|
|
PoNbr = asn.PoBillNum, |
|
|
|
PoLine = barcode.PoBillLine, |
|
|
|
PartCode = barcode.PartCode, |
|
|
|
Lot = barcode.Batch, |
|
|
|
Qty = barcode.Qty, |
|
|
|
ProductionDate = barcode.ProduceDate, |
|
|
|
WareClass = "", |
|
|
|
WareCode = "", |
|
|
|
StdPackQty = barcode.PackQty, |
|
|
|
PoUm = barcode.PoUnit, |
|
|
|
LocUm = barcode.LocUnit, |
|
|
|
UmConv = 1, |
|
|
|
PartType = "", |
|
|
|
Supplierlot = barcode.VendBatch, |
|
|
|
Status = barcode.State.ToString(), |
|
|
|
LabelCode = barcode.Extend2, |
|
|
|
EntireBarCode = barcode.FullBarCode, |
|
|
|
PalletLabelCode = barcode.PalletCode, |
|
|
|
Remark = barcode.Remark, |
|
|
|
asnNbr = asn.AsnBillNum, |
|
|
|
poNbr = asn.PoBillNum, |
|
|
|
poLine = barcode.PoBillLine, |
|
|
|
partCode = barcode.PartCode, |
|
|
|
lot = barcode.Batch, |
|
|
|
qty = barcode.Qty, |
|
|
|
productionDate = barcode.ProduceDate, |
|
|
|
wareClass = "", |
|
|
|
wareCode = "", |
|
|
|
stdPackQty = barcode.PackQty, |
|
|
|
poUm = barcode.PoUnit, |
|
|
|
locUm = barcode.LocUnit, |
|
|
|
umConv = 1, |
|
|
|
partType = "", |
|
|
|
supplierlot = barcode.VendBatch, |
|
|
|
status = barcode.State.ToString(), |
|
|
|
labelCode = barcode.Extend2, |
|
|
|
entireBarCode = barcode.FullBarCode, |
|
|
|
palletLabelCode = barcode.PalletCode, |
|
|
|
remark = barcode.Remark, |
|
|
|
}; |
|
|
|
asnMstr.Details.Add(det); |
|
|
|
asnMstr.details.Add(det); |
|
|
|
} |
|
|
|
var jsonString = JsonSerializer.Serialize(asnMstr); |
|
|
|
var ediString = jsonString; |
|
|
@ -193,7 +233,6 @@ namespace Win_in.Sfs.Scp.WebApi |
|
|
|
asn.ShipTime ?? DateTime.Today); |
|
|
|
return asnX12; |
|
|
|
} |
|
|
|
|
|
|
|
private static X12Asn CreateX12Asn(AsnOptions.Site site, TB_ASN asn, List<TS_BARCODE> barcodes) |
|
|
|
{ |
|
|
|
var asnFactory = new AsnFactory(); |
|
|
|