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.

127 lines
7.8 KiB

2 years ago
using System.Linq;
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.Shared;
using Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent.Outgoing;
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent;
public class TyrpOutgoingBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
{
private readonly string Outgoing = "TYRP Outgoing";
private readonly IOptions<TyrpOptions> _options;
public TyrpOutgoingBackgroundWorker(
AbpAsyncTimer timer
, IOptions<TyrpOptions> options
, IServiceScopeFactory serviceScopeFactory
) : base(timer, serviceScopeFactory)
{
_options = options;
Timer.Period = options.Value.OutgoingOptions.PeriodSeconds * 1000; //default 10 minutes
}
[UnitOfWork]
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{
Logger.LogInformation($"Starting: Handling {Outgoing}");
if (!_options.Value.IncomingOptions.Active)
{
Logger.LogInformation($"{Outgoing} is not active!");
return;
}
var scontrolWriter = workerContext.ServiceProvider.GetRequiredService<ScontrolWriter>();//scontrol中间表服务
var wmsoutmWriter = workerContext.ServiceProvider.GetRequiredService<WmsoutmWriter>();//wmsoutm中间表的服务
Logger.LogInformation($"Write PurchaseOrder");//采购单
var purchaseOrderConvert = workerContext.ServiceProvider.GetRequiredService<PurchaseOrderConverter>();
var purchaseOrderList = await purchaseOrderConvert.ConvertAsync().ConfigureAwait(false);
await scontrolWriter.WriteAsync(purchaseOrderList).ConfigureAwait(false);
Logger.LogInformation($"Write PurchaseReturn");//采购退货单
var purchaseReturnConvert = workerContext.ServiceProvider.GetRequiredService<PurchaseReturnConverter>();
var purchaseReturnList = await purchaseReturnConvert.ConvertAsync().ConfigureAwait(false);
await scontrolWriter.WriteAsync(purchaseReturnList).ConfigureAwait(false);
Logger.LogInformation($"Write PutawayNote");//验收单
var putawayNoteConvert = workerContext.ServiceProvider.GetRequiredService<PutawayNoteConverter>();
var putawayNoteList = await putawayNoteConvert.ConvertAsync().ConfigureAwait(false);
await scontrolWriter.WriteAsync(putawayNoteList).ConfigureAwait(false);
Logger.LogInformation($"Write IssueNote");//线边仓领料单
var issueNoteConvert = workerContext.ServiceProvider.GetRequiredService<IssueNoteConverter>();
var issueNoteList = await issueNoteConvert.ConvertAsync().ConfigureAwait(false);
await scontrolWriter.WriteAsync(issueNoteList).ConfigureAwait(false);
Logger.LogInformation($"Write ProductionReturnNote");//线边仓退料单
var productionReturnNoteConvert = workerContext.ServiceProvider.GetRequiredService<ProductionReturnNoteConverter>();
var productionReturnNoteList = await productionReturnNoteConvert.ConvertAsync().ConfigureAwait(false);
await scontrolWriter.WriteAsync(productionReturnNoteList).ConfigureAwait(false);
Logger.LogInformation($"Write TransferNote");//储位、线边仓调拨单 和 客户储位调拨单
var transferNoteConvert = workerContext.ServiceProvider.GetRequiredService<TransferNoteConverter>();
var transferNoteList = await transferNoteConvert.ConvertAsync().ConfigureAwait(false);
var transferNoteForErpList = transferNoteList.Where(r => r.DataType == EnumOutgoingDataType.TransferForErp.ToString()).ToList();//储位、线边仓调拨单
var transferNoteForCustomList = transferNoteList.Where(r => r.DataType == EnumOutgoingDataType.TransferForCustom.ToString()).ToList();//客户储位调拨单
await scontrolWriter.WriteAsync(transferNoteForErpList).ConfigureAwait(false);
await wmsoutmWriter.WriteAsync(transferNoteForCustomList).ConfigureAwait(false);
Logger.LogInformation($"Write ProductReceiptNote");//缴库单
var productReceiptNoteConvert = workerContext.ServiceProvider.GetRequiredService<ProductReceiptNoteConverter>();
var productReceiptNoteList = await productReceiptNoteConvert.ConvertAsync().ConfigureAwait(false);
var productReceiptNoteWriter = workerContext.ServiceProvider.GetRequiredService<ProductReceiptNoteWriter>();
await productReceiptNoteWriter.WriteAsync(productReceiptNoteList).ConfigureAwait(false);
Logger.LogInformation($"Write DeliverNote");//出货单
var deliverNoteConvert = workerContext.ServiceProvider.GetRequiredService<DeliverNoteConverter>();
var deliverNoteList = await deliverNoteConvert.ConvertAsync().ConfigureAwait(false);
await wmsoutmWriter.WriteAsync(deliverNoteList).ConfigureAwait(false);
Logger.LogInformation($"Write CustomerReturnNote");//退货单
var customerReturnNoteConvert = workerContext.ServiceProvider.GetRequiredService<CustomerReturnNoteConverter>();
var customerReturnNoteList = await customerReturnNoteConvert.ConvertAsync().ConfigureAwait(false);
await wmsoutmWriter.WriteAsync(customerReturnNoteList).ConfigureAwait(false);
Logger.LogInformation($"Write UnplannedIssueNote");//非生产领料单
var unplannedIssueNoteConvert = workerContext.ServiceProvider.GetRequiredService<UnplannedIssueNoteConverter>();
var unplannedIssueNoteNoteList = await unplannedIssueNoteConvert.ConvertAsync().ConfigureAwait(false);
await wmsoutmWriter.WriteAsync(unplannedIssueNoteNoteList).ConfigureAwait(false);
//Logger.LogInformation($"Write UnplannedReceiptNote");//非生产退料
//var unplannedReceiptNoteConvert = workerContext.ServiceProvider.GetRequiredService<UnplannedReceiptNoteConverter>();
//var unplannedReceiptNoteList = await unplannedReceiptNoteConvert.ConvertAsync();
//await wmsoutmWriter.WriteAsync(unplannedReceiptNoteList);
Logger.LogInformation($"Write RecycledMaterialReceiptNote");//回收料入库单
var recycledMaterialReceiptNoteConvert = workerContext.ServiceProvider.GetRequiredService<RecycledMaterialReceiptNoteConverter>();
var recycledMaterialReceiptNoteList = await recycledMaterialReceiptNoteConvert.ConvertAsync().ConfigureAwait(false);
await wmsoutmWriter.WriteAsync(recycledMaterialReceiptNoteList).ConfigureAwait(false);
Logger.LogInformation($"Write BackFlushNote");//退拆单
var productRecycleNoteConvert = workerContext.ServiceProvider.GetRequiredService<ProductRecycleNoteConverter>();
var productRecycleNoteList = await productRecycleNoteConvert.ConvertAsync().ConfigureAwait(false);
await wmsoutmWriter.WriteAsync(productRecycleNoteList).ConfigureAwait(false);
Logger.LogInformation($"Write CountAdjusNote");//调整单、线边仓调整单
var countadjustNoteConvert = workerContext.ServiceProvider.GetRequiredService<CountAdjustNoteConverter>();
var countadjustNoteList = await countadjustNoteConvert.ConvertAsync().ConfigureAwait(false);
var countadjustWriter = workerContext.ServiceProvider.GetRequiredService<CountAdjustNoteWriter>();
await countadjustWriter.WriteAsync(countadjustNoteList).ConfigureAwait(false);
Logger.LogInformation($"Write ScrapNote");//报废单、线边仓报废单
var scrapNoteConvert = workerContext.ServiceProvider.GetRequiredService<ScrapNoteConverter>();
var scrapNoteList = await scrapNoteConvert.ConvertAsync().ConfigureAwait(false);
await countadjustWriter.WriteAsync(scrapNoteList).ConfigureAwait(false);
Logger.LogInformation($"Completed: Handling {Outgoing}");
}
}