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.
 
 
 
 
 
 

180 lines
10 KiB

using System;
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.Incoming;
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent;
public class TyrpIncomingBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
{
private readonly string Incoming = "TYRP Incoming";
private readonly IOptions<TyrpOptions> _options;
public TyrpIncomingBackgroundWorker(
AbpAsyncTimer timer,
IOptions<TyrpOptions> options,
IServiceScopeFactory serviceScopeFactory
) : base(timer, serviceScopeFactory)
{
_options = options;
Timer.Period = options.Value.IncomingOptions.PeriodSeconds * 1000; //default 10 minutes
common.isupdate = true;
common.updatedt = DateTime.Now.AddDays(-1);
}
[UnitOfWork]
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{
Logger.LogInformation($"Starting: Handling {Incoming}");
if (!_options.Value.IncomingOptions.Active)
{
Logger.LogInformation($"{Incoming} is not active!");
return;
}
//var repository = workerContext.ServiceProvider.GetRequiredService<IPartLinq2DbRepository>();
//var list = await repository.GetListAsync();
//foreach (var part in list)
//{
// Console.WriteLine(part);
// part.Name = DateTime.Now.Ticks.ToString();
// await repository.UpdateAsync(part);
//}
if (DateTime.Now.Day > common.updatedt.Day)
{
if (common.isupdate)
{
common.updatedt = DateTime.Now;
common.isupdate = false;
Logger.LogInformation($"Read ItemBasic");//物品
var itemBasicReader = workerContext.ServiceProvider.GetRequiredService<ItemBasicReader>();
var itemBasicConverter = workerContext.ServiceProvider.GetRequiredService<ItemBasicConverter>();
//读取并保存itemBasic
var itemBasicOutsFromExternalList = await itemBasicReader.ReadAsync().ConfigureAwait(false);
//转换itemBasic
await itemBasicConverter.ConvertAsync(itemBasicOutsFromExternalList).ConfigureAwait(false);
Logger.LogInformation($"Read User");//用户和部门
var userReader = workerContext.ServiceProvider.GetRequiredService<UserReader>();
var userConverter = workerContext.ServiceProvider.GetRequiredService<UserConverter>();
var departmentConverter = workerContext.ServiceProvider.GetRequiredService<DepartmentConverter>();
//读取并保存user
var outsFromExternalList = await userReader.ReadAsync().ConfigureAwait(false);
var userOutsFromExternalList = outsFromExternalList.Where(r => r.DataType == EnumIncomingDataType.User.ToString()).ToList();
var departmentOutsFromExternalList = outsFromExternalList.Where(r => r.DataType == EnumIncomingDataType.Department.ToString()).ToList();
//转换user
await userConverter.ConvertAsync(userOutsFromExternalList).ConfigureAwait(false);
//转换department
await departmentConverter.ConvertAsync(departmentOutsFromExternalList).ConfigureAwait(false);
Logger.LogInformation($"Read InterfaceCalendar");//账期
var interfaceCalendarReader = workerContext.ServiceProvider.GetRequiredService<InterfaceCalendarReader>();
var interfaceCalendarConverter = workerContext.ServiceProvider.GetRequiredService<InterfaceCalendarConverter>();
//读取并保存InterfaceCalendar
var interfaceCalendarOutsFromExternalList = await interfaceCalendarReader.ReadAsync().ConfigureAwait(false);
//转换InterfaceCalendar
await interfaceCalendarConverter.ConvertAsync(interfaceCalendarOutsFromExternalList).ConfigureAwait(false);
Logger.LogInformation($"Read Dict");//系统代码
var dictReader = workerContext.ServiceProvider.GetRequiredService<DictReader>();
var dictConverter = workerContext.ServiceProvider.GetRequiredService<DictConverter>();
//读取并保存Dict
var dictOutsFromExternalList = await dictReader.ReadAsync().ConfigureAwait(false);
//转换Dict
await dictConverter.ConvertAsync(dictOutsFromExternalList).ConfigureAwait(false);
Logger.LogInformation($"Read Bom");
var BomReader = workerContext.ServiceProvider.GetRequiredService<BomReader>();
var BomConverter = workerContext.ServiceProvider.GetRequiredService<BomConverter>();
//读取并保存Bom
var bomsFromExternalList = await BomReader.ReadAsync().ConfigureAwait(false);
//转换Bom
await BomConverter.ConvertAsync(bomsFromExternalList).ConfigureAwait(false);
Logger.LogInformation($"Read Supplier");//供应商
var SupplierReader = workerContext.ServiceProvider.GetRequiredService<SupplierReader>();
var SupplierConverter = workerContext.ServiceProvider.GetRequiredService<SupplierConverter>();
//读取并保存Supplier
var suppliersFromExternalList = await SupplierReader.ReadAsync().ConfigureAwait(false);
//转换Supplier
await SupplierConverter.ConvertAsync(suppliersFromExternalList).ConfigureAwait(false);
Logger.LogInformation($"Read Dictpj");//专案代码
var DictpjReader = workerContext.ServiceProvider.GetRequiredService<DictpjReader>();
//读取并保存Dictpj
var dictpjOutsFromExternalList = await DictpjReader.ReadAsync().ConfigureAwait(false);
//转换Dictpj
await dictConverter.ConvertAsync(dictpjOutsFromExternalList).ConfigureAwait(false);
Logger.LogInformation($"Read Customer");//客户资料
var CustomerReader = workerContext.ServiceProvider.GetRequiredService<CustomerReader>();
var CustomerConverter = workerContext.ServiceProvider.GetRequiredService<CustomerConverter>();
//读取并保存Customer
var customersFromExternalList = await CustomerReader.ReadAsync().ConfigureAwait(false);
//转换Customer
await CustomerConverter.ConvertAsync(customersFromExternalList).ConfigureAwait(false);
Logger.LogInformation($"Read ErpLocationItem");//储位与物品对应关系(开账)
var ErpLocationItemReader = workerContext.ServiceProvider.GetRequiredService<ErpLocationItemReader>();
var ErpLocationItemConverter = workerContext.ServiceProvider.GetRequiredService<ErpLocationItemConverter>();
//读取并保存ErpLocationItem
var erpLocationItemFromExternalList = await ErpLocationItemReader.ReadAsync().ConfigureAwait(false);
//转换ErpLocationItem
await ErpLocationItemConverter.ConvertAsync(erpLocationItemFromExternalList).ConfigureAwait(false);
Logger.LogInformation($"Read PurchasePrice");//采购价格
var PurchasePriceReader = workerContext.ServiceProvider.GetRequiredService<PurchasePriceReader>();
var PurchasePriceConverter = workerContext.ServiceProvider.GetRequiredService<PurchasePriceConverter>();
//读取并保存PurchasePrice
var purchasePriceFromExternalList = await PurchasePriceReader.ReadAsync().ConfigureAwait(false);
//转换PurchasePrice
await PurchasePriceConverter.ConvertAsync(purchasePriceFromExternalList).ConfigureAwait(false);
Logger.LogInformation($"Read SalePrice");//销售价格
var SalePriceReader = workerContext.ServiceProvider.GetRequiredService<SalePriceReader>();
var SalePriceConverter = workerContext.ServiceProvider.GetRequiredService<SalePriceConverter>();
//读取并保存SalePrice
var salePriceFromExternalList = await SalePriceReader.ReadAsync().ConfigureAwait(false);
//转换SalePrice
await SalePriceConverter.ConvertAsync(salePriceFromExternalList).ConfigureAwait(false);
Logger.LogInformation($"Read StdCostPrice");//标准成本价格
var StdCostPriceReader = workerContext.ServiceProvider.GetRequiredService<StdCostPriceReader>();
var StdCostPriceConverter = workerContext.ServiceProvider.GetRequiredService<StdCostPriceConverter>();
//读取并保存StdCostPrice
var stdCostPriceFromExternalList = await StdCostPriceReader.ReadAsync().ConfigureAwait(false);
//转换StdCostPrice
await StdCostPriceConverter.ConvertAsync(stdCostPriceFromExternalList).ConfigureAwait(false);
}
else
{
common.isupdate = true;
}
}
//已经挪至MES接口,tyrp暂不启动这个接口20230424(上海东阳改)
//Logger.LogInformation($"Read BackFlush");//耗用单
//var BackFlushReader = workerContext.ServiceProvider.GetRequiredService<BackFluReader>();
//var BackFlushConverter = workerContext.ServiceProvider.GetRequiredService<BackFluConverter>();
////读取并保存Customer
//var backFlushsFromExternalList = await BackFlushReader.ReadAsync().ConfigureAwait(false);
////转换Customer
//await BackFlushConverter.ConvertAsync(backFlushsFromExternalList).ConfigureAwait(false);
Logger.LogInformation($"Completed: Handling {Incoming}");
}
}