Browse Source

[fix]添加最小UID值

master
贾荣国 2 years ago
parent
commit
9e060cfbd6
  1. 9
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/AsnOptions.cs
  2. 36
      WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/AsnBackgroundWorker/AsnBackgroundWorker.cs
  3. 2
      WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.Production.Development.json
  4. 2
      WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.Production.secrets.json
  5. 11
      WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.json
  6. 2
      WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.secrets.json

9
WebApiService/src/Win_in.Sfs.Scp.WebApi.Domain.Shared/AsnOptions.cs

@ -9,6 +9,13 @@ public class AsnOptions
public int RetryTimes { get; set; } = 3; public int RetryTimes { get; set; } = 3;
public int BatchSize { get; set; } = 10; public int BatchSize { get; set; } = 10;
public int MaxCount { get; set; } = 100; public int MaxCount { get; set; } = 100;
public List<string> Sites { get; set; } =new() ; public List<Site> Sites { get; set; } =new() ;
public string Receiver { get; set; } = "IACNA_ID"; public string Receiver { get; set; } = "IACNA_ID";
public class Site
{
public string Code { get; set; }
public long MinUid { get; set; }
}
} }

36
WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/AsnBackgroundWorker/AsnBackgroundWorker.cs

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

2
WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.Production.Development.json

@ -1,2 +0,0 @@
{
}

2
WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.Production.secrets.json

@ -1,2 +0,0 @@
{
}

11
WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.json

@ -85,7 +85,16 @@
"BatchSize": 10, "BatchSize": 10,
"MaxCount": 100, "MaxCount": 100,
"Receiver": "IACNA_ID", "Receiver": "IACNA_ID",
"Sites": [ "T8", "T5" ] "Sites": [
{
"Code": "T8",
"MinUid": 200
},
{
"Code": "T5",
"MinUid": 100
}
]
}, },
"AlwaysAllowAuthorization": false "AlwaysAllowAuthorization": false
} }

2
WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.secrets.json

@ -1,2 +0,0 @@
{
}
Loading…
Cancel
Save