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; 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接收"; private readonly IOptions _options; public TyrpIncomingBackgroundWorker( AbpAsyncTimer timer, IOptions 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($"开始: 执行 {Incoming}"); var configManager = workerContext.ServiceProvider.GetRequiredService(); var confitem = await configManager.GetInterfaceConfig("TYRP-IN").ConfigureAwait(false); if (confitem == null) { if (!_options.Value.IncomingOptions.Active) { Logger.LogInformation($"{Incoming} 已关闭没有执行!"); return; } } else { if (!confitem.Active) { Logger.LogInformation($"{Incoming} 已关闭没有执行!"); return; } } //var repository = workerContext.ServiceProvider.GetRequiredService(); //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; #region 物品 ItemBasic Logger.LogInformation($"读取物品 ItemBasic");//物品 var itemBasicReader = workerContext.ServiceProvider.GetRequiredService(); var itemBasicConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存itemBasic var itemBasicOutsFromExternalList = await itemBasicReader.ReadAsync().ConfigureAwait(false); //转换itemBasic await itemBasicConverter.ConvertAsync(itemBasicOutsFromExternalList).ConfigureAwait(false); Logger.LogInformation($"处理物品【{itemBasicOutsFromExternalList.Count}】条数据"); #endregion #region 用户和部门 User Logger.LogInformation($"读取用户和部门 User");//用户和部门 var userReader = workerContext.ServiceProvider.GetRequiredService(); var userConverter = workerContext.ServiceProvider.GetRequiredService(); var departmentConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存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($"处理用户【{userOutsFromExternalList.Count}】条数据"); Logger.LogInformation($"处理部门【{departmentOutsFromExternalList.Count}】条数据"); #endregion #region 账期 InterfaceCalendar Logger.LogInformation($"读取账期 InterfaceCalendar");//账期 var interfaceCalendarReader = workerContext.ServiceProvider.GetRequiredService(); var interfaceCalendarConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存InterfaceCalendar var interfaceCalendarOutsFromExternalList = await interfaceCalendarReader.ReadAsync().ConfigureAwait(false); //转换InterfaceCalendar await interfaceCalendarConverter.ConvertAsync(interfaceCalendarOutsFromExternalList).ConfigureAwait(false); Logger.LogInformation($"处理账期【{interfaceCalendarOutsFromExternalList.Count}】条数据"); #endregion #region 系统代码 Dict Logger.LogInformation($"读取系统代码 Dict");//系统代码 var dictReader = workerContext.ServiceProvider.GetRequiredService(); var dictConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存Dict var dictOutsFromExternalList = await dictReader.ReadAsync().ConfigureAwait(false); //转换Dict await dictConverter.ConvertAsync(dictOutsFromExternalList).ConfigureAwait(false); Logger.LogInformation($"处理系统代码【{dictOutsFromExternalList.Count}】条数据"); #endregion #region Bom Logger.LogInformation($"读取报目 Bom"); var BomReader = workerContext.ServiceProvider.GetRequiredService(); var BomConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存Bom var bomsFromExternalList = await BomReader.ReadAsync().ConfigureAwait(false); //转换Bom await BomConverter.ConvertAsync(bomsFromExternalList).ConfigureAwait(false); Logger.LogInformation($"处理Bom【{bomsFromExternalList.Count}】条数据"); #endregion #region 供应商 Supplier Logger.LogInformation($"读取供应商 Supplier");//供应商 var SupplierReader = workerContext.ServiceProvider.GetRequiredService(); var SupplierConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存Supplier var suppliersFromExternalList = await SupplierReader.ReadAsync().ConfigureAwait(false); //转换Supplier await SupplierConverter.ConvertAsync(suppliersFromExternalList).ConfigureAwait(false); Logger.LogInformation($"处理供应商【{suppliersFromExternalList.Count}】条数据"); #endregion #region 专案代码 Dictpj Logger.LogInformation($"读取专案代码 Dictpj");//专案代码 var DictpjReader = workerContext.ServiceProvider.GetRequiredService(); //读取并保存Dictpj var dictpjOutsFromExternalList = await DictpjReader.ReadAsync().ConfigureAwait(false); //转换Dictpj await dictConverter.ConvertAsync(dictpjOutsFromExternalList).ConfigureAwait(false); Logger.LogInformation($"处理专案代码【{dictpjOutsFromExternalList.Count}】条数据"); #endregion #region ERP库位 ErpLocation Logger.LogInformation($"读取ERP库位 ErpLocation");//ERP库位 var ErpLocationReader = workerContext.ServiceProvider.GetRequiredService(); var ErpLocationConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存ErpLocationItem var erpLocationFromExternalList = await ErpLocationReader.ReadAsync().ConfigureAwait(false); //转换ErpLocationItem await ErpLocationConverter.ConvertAsync(erpLocationFromExternalList).ConfigureAwait(false); Logger.LogInformation($"处理ERP库位【{erpLocationFromExternalList.Count}】条数据"); #endregion #region 客户资料 Customer Logger.LogInformation($"读取客户资料 Customer");//客户资料 var CustomerReader = workerContext.ServiceProvider.GetRequiredService(); var CustomerConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存Customer var customersFromExternalList = await CustomerReader.ReadAsync().ConfigureAwait(false); //转换Customer await CustomerConverter.ConvertAsync(customersFromExternalList).ConfigureAwait(false); Logger.LogInformation($"处理客户资料【{customersFromExternalList.Count}】条数据"); #endregion #region 储位与物品对应关系(开账) ErpLocationItem Logger.LogInformation($"读取储位与物品对应关系(开账) ErpLocationItem");//储位与物品对应关系(开账) var ErpLocationItemReader = workerContext.ServiceProvider.GetRequiredService(); var ErpLocationItemConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存ErpLocationItem var erpLocationItemFromExternalList = await ErpLocationItemReader.ReadAsync().ConfigureAwait(false); //转换ErpLocationItem await ErpLocationItemConverter.ConvertAsync(erpLocationItemFromExternalList).ConfigureAwait(false); Logger.LogInformation($"处理开账【{erpLocationItemFromExternalList.Count}】条数据"); #endregion #region 采购价格 PurchasePrice Logger.LogInformation($"读取采购价格 PurchasePrice");//采购价格 var PurchasePriceReader = workerContext.ServiceProvider.GetRequiredService(); var PurchasePriceConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存PurchasePrice var purchasePriceFromExternalList = await PurchasePriceReader.ReadAsync().ConfigureAwait(false); //转换PurchasePrice await PurchasePriceConverter.ConvertAsync(purchasePriceFromExternalList).ConfigureAwait(false); Logger.LogInformation($"处理采购价格【{purchasePriceFromExternalList.Count}】条数据"); #endregion #region 销售价格 SalePrice Logger.LogInformation($"读取销售价格 SalePrice");//销售价格 var SalePriceReader = workerContext.ServiceProvider.GetRequiredService(); var SalePriceConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存SalePrice var salePriceFromExternalList = await SalePriceReader.ReadAsync().ConfigureAwait(false); //转换SalePrice await SalePriceConverter.ConvertAsync(salePriceFromExternalList).ConfigureAwait(false); Logger.LogInformation($"处理销售价格【{salePriceFromExternalList.Count}】条数据"); #endregion #region 标准成本价格 StdCostPrice Logger.LogInformation($"读取标准成本价格 StdCostPrice");//标准成本价格 var StdCostPriceReader = workerContext.ServiceProvider.GetRequiredService(); var StdCostPriceConverter = workerContext.ServiceProvider.GetRequiredService(); //读取并保存StdCostPrice var stdCostPriceFromExternalList = await StdCostPriceReader.ReadAsync().ConfigureAwait(false); //转换StdCostPrice await StdCostPriceConverter.ConvertAsync(stdCostPriceFromExternalList).ConfigureAwait(false); Logger.LogInformation($"处理标准成本价格【{stdCostPriceFromExternalList.Count}】条数据"); #endregion } else { common.isupdate = true; } } //已经挪至MES接口,tyrp暂不启动这个接口20230424(上海东阳改) //Logger.LogInformation($"Read BackFlush");//耗用单 //var BackFlushReader = workerContext.ServiceProvider.GetRequiredService(); //var BackFlushConverter = workerContext.ServiceProvider.GetRequiredService(); ////读取并保存Customer //var backFlushsFromExternalList = await BackFlushReader.ReadAsync().ConfigureAwait(false); ////转换Customer //await BackFlushConverter.ConvertAsync(backFlushsFromExternalList).ConfigureAwait(false); Logger.LogInformation($"提交: 执行 {Incoming}"); } }