From 89524f37ce3a242fae5de1e773526b3d7aca184a Mon Sep 17 00:00:00 2001 From: zhouhongjun <565221961@qq.com> Date: Mon, 8 Apr 2024 16:31:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ERP=E5=BA=93=E4=BD=8D?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataExchangeDapperFawtygModule.cs | 2 + .../ErpLocationLinq2DbRepository.cs | 13 +++ .../TyrpDb.cs | 1 + .../ErpLocation/ErpLocationManager.cs | 22 ++++ .../IErpLocationLinq2DbRepository.cs | 6 + .../ErpLocation/IErpLocationManager.cs | 9 ++ .../ErpLocation/locmout.cs | 21 ++++ .../Incoming/ErpLocationConverter.cs | 69 ++++++++++++ .../Incoming/ErpLocationReader.cs | 106 ++++++++++++++++++ .../WMS/ErpLocation/ErpLocationExchangeDto.cs | 48 ++++++++ 10 files changed, 297 insertions(+) create mode 100644 be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp/ErpLocation/ErpLocationLinq2DbRepository.cs create mode 100644 be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/ErpLocationManager.cs create mode 100644 be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/IErpLocationLinq2DbRepository.cs create mode 100644 be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/IErpLocationManager.cs create mode 100644 be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/locmout.cs create mode 100644 be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/Incoming/ErpLocationConverter.cs create mode 100644 be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/Incoming/ErpLocationReader.cs create mode 100644 be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Application.Contracts/WMS/ErpLocation/ErpLocationExchangeDto.cs diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp/DataExchangeDapperFawtygModule.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp/DataExchangeDapperFawtygModule.cs index 93c8a6cae..a7ec816a6 100644 --- a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp/DataExchangeDapperFawtygModule.cs +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp/DataExchangeDapperFawtygModule.cs @@ -10,6 +10,7 @@ using Win_in.Sfs.Wms.DataExchange.LinqToDB.Fawtyg.Tyrp.Backflushs; using Win_in.Sfs.Wms.DataExchange.LinqToDB.Fawtyg.Tyrp.Boms; using Win_in.Sfs.Wms.DataExchange.LinqToDB.Fawtyg.Tyrp.Customers; using Win_in.Sfs.Wms.DataExchange.LinqToDB.Fawtyg.Tyrp.Dictpjs; +using Win_in.Sfs.Wms.DataExchange.LinqToDB.Fawtyg.Tyrp.ErpLocations; using Win_in.Sfs.Wms.DataExchange.LinqToDB.Fawtyg.Tyrp.Products; using Win_in.Sfs.Wms.DataExchange.LinqToDB.Fawtyg.Tyrp.PurchasePrices; using Win_in.Sfs.Wms.DataExchange.LinqToDB.Fawtyg.Tyrp.SalePrices; @@ -46,6 +47,7 @@ public class DataExchangeDapperFawtygModule : AbpModule context.Services.AddTransient(); context.Services.AddTransient(); context.Services.AddTransient(); + context.Services.AddTransient(); context.Services.AddTransient(); context.Services.AddTransient(); context.Services.AddTransient(); diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp/ErpLocation/ErpLocationLinq2DbRepository.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp/ErpLocation/ErpLocationLinq2DbRepository.cs new file mode 100644 index 000000000..ddef90a3f --- /dev/null +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp/ErpLocation/ErpLocationLinq2DbRepository.cs @@ -0,0 +1,13 @@ +using Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp; +using Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp.Bases; +using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp; + +namespace Win_in.Sfs.Wms.DataExchange.LinqToDB.Fawtyg.Tyrp.ErpLocations; + +public class ErpLocationLinq2DbRepository : Linq2DbCrudRepository, IErpLocationLinq2DbRepository +{ + public ErpLocationLinq2DbRepository(TyrpDb tyrpDb) : base(tyrpDb) + { + + } +} diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp/TyrpDb.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp/TyrpDb.cs index e59acea0b..4c684d0f7 100644 --- a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp/TyrpDb.cs +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Dapper.Fawtyg.Tyrp/TyrpDb.cs @@ -18,6 +18,7 @@ public class TyrpDb : DataConnection, ITransientDependency public ITable Supplier => this.GetTable(); public ITable Dictpj => this.GetTable(); public ITable Customer => this.GetTable(); + public ITable ErpLocation => this.GetTable(); public ITable PurchasePrice => this.GetTable(); public ITable SalePrice => this.GetTable(); public ITable Backflu => this.GetTable(); diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/ErpLocationManager.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/ErpLocationManager.cs new file mode 100644 index 000000000..2565a82e5 --- /dev/null +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/ErpLocationManager.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.Domain.Services; + +namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp; + +public class ErpLocationManager : DomainService, IErpLocationManager +{ + private readonly IErpLocationLinq2DbRepository _repository; + + public ErpLocationManager(IErpLocationLinq2DbRepository repository) + { + _repository = repository; + } + public virtual async Task> GetToBeProcessedListAsync() + { + var products = await _repository.GetListAsync().ConfigureAwait(false); + return products.ToList(); + + } +} diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/IErpLocationLinq2DbRepository.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/IErpLocationLinq2DbRepository.cs new file mode 100644 index 000000000..8cf9d880b --- /dev/null +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/IErpLocationLinq2DbRepository.cs @@ -0,0 +1,6 @@ +namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp; + +public interface IErpLocationLinq2DbRepository : ILinq2DbRepository +{ + +} diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/IErpLocationManager.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/IErpLocationManager.cs new file mode 100644 index 000000000..b25390474 --- /dev/null +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/IErpLocationManager.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp; + +public interface IErpLocationManager +{ + Task> GetToBeProcessedListAsync(); +} diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/locmout.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/locmout.cs new file mode 100644 index 000000000..c71f0d524 --- /dev/null +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp/ErpLocation/locmout.cs @@ -0,0 +1,21 @@ +using Volo.Abp.Domain.Entities; + +namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp; + +public class locmout : Entity +{ + /// + /// 库位 + /// + public string locmout_loc { get; set; } + /// + /// 库位类型 + /// + public string locmout_stat2 { get; set; } + + + public override object[] GetKeys() + { + return new object[] { locmout_loc }; + } +} diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/Incoming/ErpLocationConverter.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/Incoming/ErpLocationConverter.cs new file mode 100644 index 000000000..10b6b2b0d --- /dev/null +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/Incoming/ErpLocationConverter.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text.Json; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Volo.Abp.ObjectMapping; +using Win_in.Sfs.Basedata.Application.Contracts; +using Win_in.Sfs.Wms.DataExchange.Domain; +using Win_in.Sfs.Wms.DataExchange.WMS.ErpLocation; + +namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent.Incoming; + +public class ErpLocationConverter : IIncomingConverter +{ + private readonly IIncomingToWmsManager _incomingToWmsManager; + private readonly IObjectMapper _objectMapper; + private readonly ILogger _logger; + private readonly IIncomingFromExternalManager _incomingFromExternalManager; + + public ErpLocationConverter( + IIncomingToWmsManager incomingToWmsManager + , IObjectMapper objectMapper + , ILogger logger, + IIncomingFromExternalManager incomingFromExternalManager) + { + _incomingToWmsManager = incomingToWmsManager; + _objectMapper = objectMapper; + _logger = logger; + _incomingFromExternalManager = incomingFromExternalManager; + } + + public virtual async Task ConvertAsync(List incomingFromExternalList) + { + if (!incomingFromExternalList.Any()) + { + _logger.LogInformation("No ErpLocations"); + return; + } + + //按流水号创建单据 + var erpLocationRequestList = await BuildIncomingToWmsOfErpLocationRequestAsync(incomingFromExternalList).ConfigureAwait(false); + await _incomingToWmsManager.CreateManyAsync(erpLocationRequestList).ConfigureAwait(false); + //归档 + await _incomingFromExternalManager.ArchiveManyAsync(incomingFromExternalList).ConfigureAwait(false); + } + + private async Task> BuildIncomingToWmsOfErpLocationRequestAsync(List incomingDataList) + { + await Task.CompletedTask.ConfigureAwait(false); + var incomingToWmsList = new List(); + foreach (var item in incomingDataList) + { + var incomingToWms = new IncomingToWms() + { + DataType = item.DataType, + DataAction = item.DataAction, + SourceSystem = item.SourceSystem, + DataIdentityCode = item.SourceDataGroupCode, + }; + incomingToWms.SetEffectiveDate(item.EffectiveDate); + var exchangeErpLocationRequest = JsonSerializer.Deserialize(item.DestinationDataContent); + var wmsErpLocationRequest = _objectMapper.Map(exchangeErpLocationRequest); + incomingToWms.DataContent = JsonSerializer.Serialize(wmsErpLocationRequest); + incomingToWmsList.Add(incomingToWms); + } + return incomingToWmsList; + } + +} diff --git a/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/Incoming/ErpLocationReader.cs b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/Incoming/ErpLocationReader.cs new file mode 100644 index 000000000..c56546a43 --- /dev/null +++ b/be/DataExchange/Fawtyg/Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent/Incoming/ErpLocationReader.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.Json; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Win_in.Sfs.Wms.DataExchange.Domain; +using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp; +using Win_in.Sfs.Wms.DataExchange.Domain.Shared; +using Win_in.Sfs.Wms.DataExchange.WMS.ErpLocation; + +namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent.Incoming; + +public class ErpLocationReader : IReader +{ + private readonly IErpLocationManager _erpLocationManager; + private readonly IIncomingFromExternalManager _incomingFromExternalManager; + private readonly ILogger _logger; + + public ErpLocationReader( + IErpLocationManager erpLocationManager + , IIncomingFromExternalManager incomingFromExternalManager + , ILogger logger + ) + { + _erpLocationManager = erpLocationManager; + _incomingFromExternalManager = incomingFromExternalManager; + _logger = logger; + } + + public virtual async Task> ReadAsync() + { + //从MES读取待处理locmout + var toBeProcessedDatas = await _erpLocationManager.GetToBeProcessedListAsync().ConfigureAwait(false); + if (!toBeProcessedDatas.Any()) + { + _logger.LogInformation("no erpLocations"); + return new List(); + } + //locmout逐一转换为ErpLocation + var incomingDataList = BuildIncomingFromExternalFromShipAsync(toBeProcessedDatas); + await _incomingFromExternalManager.CreateManyAsync(incomingDataList).ConfigureAwait(false); + + return incomingDataList; + } + + private static List BuildIncomingFromExternalFromShipAsync(List toBeProcessedDatas) + { + var incomingDataList = new List(); + foreach (var item in toBeProcessedDatas) + { + var incomingData = BuildIncomingFromExternal(item); + + incomingData.SetEffectiveDate(DateTime.Now); + incomingData.SetSuccess(); + try + { + var erpLocationNote = BuildErpLocationCreateInput(item); + incomingData.DestinationDataContent = JsonSerializer.Serialize(erpLocationNote); + } + catch (Exception ex) + { + incomingData.SetError(EnumExchangeDataErrorCode.Exception, ex.Message, ex.ToString()); + } + + incomingDataList.Add(incomingData); + + } + + return incomingDataList; + } + + private static IncomingFromExternal BuildIncomingFromExternal(locmout locmout) + { + var incomingData = new IncomingFromExternal() + { + DataType = EnumIncomingDataType.ErpLocation.ToString(), + DataAction = EnumExchangeDataAction.Add, + SourceSystem = EnumSystemType.ERP.ToString(), + SourceDataId = locmout.locmout_loc, + SourceDataGroupCode = locmout.locmout_loc, + SourceDataDetailCode = locmout.locmout_loc, + SourceDataContent = JsonSerializer.Serialize(locmout), + WriteTime = DateTime.Now, + Writer = nameof(TyrpIncomingBackgroundWorker), + + DestinationSystem = EnumSystemType.WMS.ToString(), + }; + return incomingData; + } + + private static ErpLocationExchangeDto BuildErpLocationCreateInput(locmout locmout) + { + + var erpLocation = new ErpLocationExchangeDto() + { + Code = locmout.locmout_loc, + Name = locmout.locmout_loc, + Type = locmout.locmout_stat2, + WarehouseCode = locmout.locmout_stat2, + + }; + return erpLocation; + } + +} diff --git a/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Application.Contracts/WMS/ErpLocation/ErpLocationExchangeDto.cs b/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Application.Contracts/WMS/ErpLocation/ErpLocationExchangeDto.cs new file mode 100644 index 000000000..e9a9eb19b --- /dev/null +++ b/be/DataExchange/src/Win_in.Sfs.Wms.DataExchange.Application.Contracts/WMS/ErpLocation/ErpLocationExchangeDto.cs @@ -0,0 +1,48 @@ +using System.ComponentModel.DataAnnotations; +using Win_in.Sfs.Shared.Domain; + +namespace Win_in.Sfs.Wms.DataExchange.WMS.ErpLocation; + +public class ErpLocationExchangeDto +{ + /// + /// 代码 + /// + + [Display(Name = "代码")] + [Required] + [StringLength(SfsEfCorePropertyConst.CodeLength, ErrorMessage = "{0}最多输入{1}个字符")] + public string Code { get; set; } + + /// + /// 名称 + /// + [Display(Name = "名称")] + [Required(ErrorMessage = "{0}是必填项")] + [StringLength(SfsEfCorePropertyConst.CodeLength, ErrorMessage = "{0}最多输入{1}个字符")] + public string Name { get; set; } + + /// + /// 描述 + /// + [Display(Name = "描述")] + [StringLength(SfsEfCorePropertyConst.NameLength, ErrorMessage = "{0}最多输入{1}个字符")] + public string Description { get; set; } + + /// + /// 类型 + /// + [Display(Name = "类型")] + [Required(ErrorMessage = "{0}是必填项")] + [StringLength(SfsEfCorePropertyConst.CodeLength, ErrorMessage = "{0}最多输入{1}个字符")] + public string Type { get; set; } + + /// + /// 仓库代码 + /// + [Display(Name = "仓库代码")] + [StringLength(SfsEfCorePropertyConst.CodeLength, ErrorMessage = "{0}最多输入{1}个字符")] + public string WarehouseCode { get; set; } + + +}