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