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.

249 lines
14 KiB

2 years ago
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;
10 months ago
using Win_in.Sfs.Wms.DataExchange.Domain;
2 years ago
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
{
10 months ago
private readonly string Incoming = "TYRP接收";
2 years ago
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)
{
10 months ago
Logger.LogInformation($"开始: 执行 {Incoming}");
10 months ago
var configManager = workerContext.ServiceProvider.GetRequiredService<IInterfaceConfigManager>();
var confitem = await configManager.GetInterfaceConfig("TYRP-IN").ConfigureAwait(false);
if (confitem == null)
2 years ago
{
10 months ago
if (!_options.Value.IncomingOptions.Active)
{
Logger.LogInformation($"{Incoming} 已关闭没有执行!");
return;
}
}
else
{
if (!confitem.Active)
{
Logger.LogInformation($"{Incoming} 已关闭没有执行!");
10 months ago
if (confitem.Status == 0)
{
await configManager.UpsertStatusAsync("TYRP-IN").ConfigureAwait(false);
Logger.LogInformation($"{Incoming} 运行已结束,更新接口运行状态!");
}
10 months ago
return;
}
2 years ago
}
//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;
10 months ago
#region 物品 ItemBasic
Logger.LogInformation($"读取物品 ItemBasic");//物品
2 years ago
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);
10 months ago
Logger.LogInformation($"处理物品【{itemBasicOutsFromExternalList.Count}】条数据");
#endregion
2 years ago
10 months ago
#region 用户和部门 User
Logger.LogInformation($"读取用户和部门 User");//用户和部门
2 years ago
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);
10 months ago
Logger.LogInformation($"处理用户【{userOutsFromExternalList.Count}】条数据");
Logger.LogInformation($"处理部门【{departmentOutsFromExternalList.Count}】条数据");
#endregion
2 years ago
10 months ago
#region 账期 InterfaceCalendar
Logger.LogInformation($"读取账期 InterfaceCalendar");//账期
2 years ago
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);
10 months ago
Logger.LogInformation($"处理账期【{interfaceCalendarOutsFromExternalList.Count}】条数据");
#endregion
2 years ago
10 months ago
#region 系统代码 Dict
Logger.LogInformation($"读取系统代码 Dict");//系统代码
2 years ago
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);
10 months ago
Logger.LogInformation($"处理系统代码【{dictOutsFromExternalList.Count}】条数据");
#endregion
2 years ago
10 months ago
#region Bom
Logger.LogInformation($"读取报目 Bom");
2 years ago
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);
10 months ago
Logger.LogInformation($"处理Bom【{bomsFromExternalList.Count}】条数据");
#endregion
2 years ago
10 months ago
#region 供应商 Supplier
Logger.LogInformation($"读取供应商 Supplier");//供应商
2 years ago
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);
10 months ago
Logger.LogInformation($"处理供应商【{suppliersFromExternalList.Count}】条数据");
#endregion
2 years ago
10 months ago
#region 专案代码 Dictpj
Logger.LogInformation($"读取专案代码 Dictpj");//专案代码
2 years ago
var DictpjReader = workerContext.ServiceProvider.GetRequiredService<DictpjReader>();
//读取并保存Dictpj
var dictpjOutsFromExternalList = await DictpjReader.ReadAsync().ConfigureAwait(false);
//转换Dictpj
2 years ago
await dictConverter.ConvertAsync(dictpjOutsFromExternalList).ConfigureAwait(false);
10 months ago
Logger.LogInformation($"处理专案代码【{dictpjOutsFromExternalList.Count}】条数据");
#endregion
2 years ago
10 months ago
#region ERP库位 ErpLocation
Logger.LogInformation($"读取ERP库位 ErpLocation");//ERP库位
11 months ago
var ErpLocationReader = workerContext.ServiceProvider.GetRequiredService<ErpLocationReader>();
var ErpLocationConverter = workerContext.ServiceProvider.GetRequiredService<ErpLocationConverter>();
//读取并保存ErpLocationItem
var erpLocationFromExternalList = await ErpLocationReader.ReadAsync().ConfigureAwait(false);
//转换ErpLocationItem
await ErpLocationConverter.ConvertAsync(erpLocationFromExternalList).ConfigureAwait(false);
10 months ago
Logger.LogInformation($"处理ERP库位【{erpLocationFromExternalList.Count}】条数据");
#endregion
11 months ago
10 months ago
#region 客户资料 Customer
Logger.LogInformation($"读取客户资料 Customer");//客户资料
2 years ago
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);
10 months ago
Logger.LogInformation($"处理客户资料【{customersFromExternalList.Count}】条数据");
#endregion
10 months ago
#region 储位与物品对应关系(开账) ErpLocationItem
Logger.LogInformation($"读取储位与物品对应关系(开账) 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);
10 months ago
Logger.LogInformation($"处理开账【{erpLocationItemFromExternalList.Count}】条数据");
#endregion
10 months ago
#region 采购价格 PurchasePrice
Logger.LogInformation($"读取采购价格 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);
10 months ago
Logger.LogInformation($"处理采购价格【{purchasePriceFromExternalList.Count}】条数据");
#endregion
10 months ago
#region 销售价格 SalePrice
Logger.LogInformation($"读取销售价格 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);
10 months ago
Logger.LogInformation($"处理销售价格【{salePriceFromExternalList.Count}】条数据");
#endregion
10 months ago
#region 标准成本价格 StdCostPrice
Logger.LogInformation($"读取标准成本价格 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);
10 months ago
Logger.LogInformation($"处理标准成本价格【{stdCostPriceFromExternalList.Count}】条数据");
#endregion
2 years ago
}
else
{
common.isupdate = true;
}
}
2 years ago
//已经挪至MES接口,tyrp暂不启动这个接口20230424(上海东阳改)
2 years ago
//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);
2 years ago
10 months ago
Logger.LogInformation($"提交: 执行 {Incoming}");
2 years ago
}
}