|
|
@ -53,37 +53,47 @@ public class AsnBackgroundWorker : AsyncPeriodicBackgroundWorkerBase |
|
|
|
var dataFilter = workerContext.ServiceProvider.GetRequiredService<IDataFilter>(); |
|
|
|
|
|
|
|
//Do the work
|
|
|
|
long maxUid = 0; |
|
|
|
var x12 = await x12AsnRepository.OrderByDescending(p => p.UID).FirstOrDefaultAsync(); |
|
|
|
maxUid = x12?.UID ?? 0; |
|
|
|
var asnX12List = new List<X12Asn>(); |
|
|
|
|
|
|
|
foreach (var site in _options.Value.Sites) |
|
|
|
{ |
|
|
|
|
|
|
|
var siteCode = site.Code; |
|
|
|
var siteMinUid = site.MinUid; |
|
|
|
try |
|
|
|
{ |
|
|
|
var tenant = await tenantStore.FindAsync(site); |
|
|
|
var tenant = await tenantStore.FindAsync(siteCode); |
|
|
|
|
|
|
|
using (currentTenant.Change(tenant.Id, tenant.Name)) |
|
|
|
{ |
|
|
|
using (dataFilter.Disable<IMultiTenant>()) |
|
|
|
{ |
|
|
|
var scpAsns = await scpAsnManager.GetUnreadAsnsAsync(site,maxUid, _options.Value.BatchSize); |
|
|
|
long lastUid = 0; |
|
|
|
|
|
|
|
var x12 = await x12AsnRepository |
|
|
|
.Where(p => p.Site == siteCode) |
|
|
|
.OrderByDescending(p => p.UID) |
|
|
|
.FirstOrDefaultAsync(); |
|
|
|
lastUid = x12?.UID ?? 0; |
|
|
|
|
|
|
|
if (lastUid < siteMinUid) |
|
|
|
{ |
|
|
|
lastUid = siteMinUid; |
|
|
|
} |
|
|
|
Logger.LogInformation($"{siteCode}: Last UID is {lastUid}"); |
|
|
|
var scpAsns = await scpAsnManager.GetUnreadAsnsAsync(siteCode, lastUid, _options.Value.BatchSize); |
|
|
|
|
|
|
|
Logger.LogInformation($"{site}: {scpAsns.Count} ASNs were Found"); |
|
|
|
Logger.LogInformation($"{siteCode}: {scpAsns.Count} ASNs were Found"); |
|
|
|
|
|
|
|
foreach (var asn in scpAsns) |
|
|
|
{ |
|
|
|
var barcodes = await scpAsnManager.GetBarcodesAsync(site,asn.AsnBillNum); |
|
|
|
var barcodes = await scpAsnManager.GetBarcodesAsync(siteCode, asn.AsnBillNum); |
|
|
|
var asnFactory = new AsnFactory(); |
|
|
|
var asnX128563060 = asnFactory.CreateAsnX128563060(_options.Value.Receiver, asn, barcodes); |
|
|
|
var jsonString = JsonSerializer.Serialize(asnX128563060); |
|
|
|
var ediString = asnX128563060.ToString(); |
|
|
|
var asnX12 = new X12Asn(asn.Id, asn.Site, asn.AsnBillNum, jsonString, ediString, asn.ShipTime ?? DateTime.Today); |
|
|
|
asnX12List.Add(asnX12); |
|
|
|
Logger.LogInformation($"{site}:{asn.Id} {asn.AsnBillNum} was loaded"); |
|
|
|
Logger.LogInformation($"{siteCode}:{asn.Id} {asn.AsnBillNum} was loaded"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -113,7 +123,7 @@ public class AsnBackgroundWorker : AsyncPeriodicBackgroundWorkerBase |
|
|
|
|
|
|
|
await x12AsnRepository.InsertManyAsync(asnX12List, true); |
|
|
|
|
|
|
|
Logger.LogInformation("Get ASN from SCP: Completed"); |
|
|
|
Logger.LogInformation("Get ASN from SCP: Complete"); |
|
|
|
} |
|
|
|
|
|
|
|
} |