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.
 
 
 
 
 
 

152 lines
6.3 KiB

using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.Threading;
using Volo.Abp.Uow;
using Win_in.Sfs.Wms.DataExchange.Domain;
using Win_in.Sfs.Wms.DataExchange.Domain.Shared;
namespace Win_in.Sfs.Wms.DataExchange.Agent;
public class IncomingToWmsWorker : AsyncPeriodicBackgroundWorkerBase
{
private readonly IOptions<DataExchangeOptions> _options;
public IncomingToWmsWorker(
AbpAsyncTimer timer,
IOptions<DataExchangeOptions> options,
IServiceScopeFactory serviceScopeFactory
) : base(timer, serviceScopeFactory)
{
_options = options;
Timer.Period = options.Value.IncomingOptions.PeriodSeconds * 1000; //default 5 minutes
}
[UnitOfWork]
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{
Logger.LogInformation("Starting: Handling Incoming Exchange data...");
if (!_options.Value.IncomingOptions.Active)
{
Logger.LogInformation("Incoming Exchange is not active!");
return;
}
await HandleIncomingDataAsync(workerContext).ConfigureAwait(false);
Logger.LogInformation("Completed: Handling Incoming Exchange data...");
}
private async Task HandleIncomingDataAsync(PeriodicBackgroundWorkerContext workerContext)
{
//Resolve dependencies
var incomingToWmsManager = workerContext.ServiceProvider.GetRequiredService<IIncomingToWmsManager>();
//Do the work
var incomingToWmsList = await incomingToWmsManager.GetToBeProcessedListAsync().ConfigureAwait(false);
foreach (var incomingToWms in incomingToWmsList)
{
try
{
await AddOrUpdateWmsAsync(workerContext, incomingToWms).ConfigureAwait(false);
}
catch (Exception e)
{
e = e.GetBaseException();
incomingToWms.SetError(EnumExchangeDataErrorCode.Exception, e.Message);
}
//归档并删除
await incomingToWmsManager.ArchiveAsync(incomingToWms).ConfigureAwait(false);
}
}
[UnitOfWork]
public async Task AddOrUpdateWmsAsync(PeriodicBackgroundWorkerContext workerContext,
IncomingToWms incomingToWms)
{
if (!Enum.TryParse(incomingToWms.DataType, true, out EnumIncomingDataType dataType))
{
incomingToWms.SetError(EnumExchangeDataErrorCode.UnknownDataType, "无法识别的数据类型");
return;
}
//TODO 完成全部接口
switch (dataType)
{
case EnumIncomingDataType.Department:
await incomingToWms.HandleDepartmentsAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.User:
await incomingToWms.HandleUsersAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.Item:
await incomingToWms.HandleItemsAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.Location:
await incomingToWms.HandleErpLocationsAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.Bom:
await incomingToWms.HandleBomsAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.Dict:
await incomingToWms.HandleDictsAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.Supplier:
await incomingToWms.HandleSuppliersAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.SupplierItem:
await incomingToWms.HandleSupplierItemsAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.ItemPack:
await incomingToWms.HandleItemPacksAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.Customer:
await incomingToWms.HandleCustomersAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.CustomerItem:
await incomingToWms.HandleCustomerItemsAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.InterfaceCalendar:
await incomingToWms.HandleInterfaceCalendarsAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.PurchaseOrder:
await incomingToWms.HandlePurchaseOrdersAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.SaleOrder:
await incomingToWms.HandleSaleOrdersAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.SupplierAsn:
await incomingToWms.HandleAsnsAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.ProductReceipt:
await incomingToWms.HandleProductReceiptsAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.MaterialRequest:
await incomingToWms.HandleMaterialRequestsAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.Scrap:
await incomingToWms.HandleScrapsAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.IssueConfirm:
await incomingToWms.HandleIssueNoteConfirmAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.PurchaseLabel:
await incomingToWms.HandleInventoryLabelsAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.BackFlush:
await incomingToWms.HandleBackFlushsAsync(workerContext).ConfigureAwait(false);
break;
case EnumIncomingDataType.None:
default:
throw new ArgumentOutOfRangeException();
}
incomingToWms.SetSuccess();
}
}