From ddc03472ff7b5e04e7f492bbeb3bd238e796bc17 Mon Sep 17 00:00:00 2001 From: "boxu.zheng" Date: Thu, 13 Apr 2023 19:10:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E5=8F=91=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProductionReturnNoteAutoMapperProfile.cs | 8 + .../Requests/IssueNoteEventHandler.cs | 78 ------ .../Requests/MaterialRequestEventHandler.cs | 5 +- .../Requests/Note/IssueNoteEventHandler.cs | 82 ++++++ .../Requests/Note/ScrapNoteEventHandler.cs | 6 - .../Transactions/IssueNoteEventHandler.cs | 264 ++++++++---------- 6 files changed, 212 insertions(+), 231 deletions(-) delete mode 100644 be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/IssueNoteEventHandler.cs create mode 100644 be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/Note/IssueNoteEventHandler.cs diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/ProductionReturnNotes/ProductionReturnNoteAutoMapperProfile.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/ProductionReturnNotes/ProductionReturnNoteAutoMapperProfile.cs index 313efa987..497df3542 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/ProductionReturnNotes/ProductionReturnNoteAutoMapperProfile.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/ProductionReturnNotes/ProductionReturnNoteAutoMapperProfile.cs @@ -20,5 +20,13 @@ public partial class StoreApplicationAutoMapperProfile : Profile .Ignore(x => x.TenantId) .Ignore(x => x.Number) .Ignore(x => x.Id); + CreateMap() + .IgnoreAuditedObjectProperties() + .Ignore(x => x.TenantId) + .Ignore(x => x.Number) + .Ignore(x => x.Id) + .Ignore(x=>x.Remark) + .Ignore(x=>x.ExtraProperties) + ; } } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/IssueNoteEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/IssueNoteEventHandler.cs deleted file mode 100644 index 5305923a6..000000000 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/IssueNoteEventHandler.cs +++ /dev/null @@ -1,78 +0,0 @@ -//using System.Collections.Generic; -//using System.Linq; -//using System.Threading.Tasks; -//using Volo.Abp.EventBus; -//using Volo.Abp.Uow; -//using Win_in.Sfs.Shared.Event; -//using Win_in.Sfs.Wms.Store.Domain; - -//namespace Win_in.Sfs.Wms.Store.Event.BusinessRequest; - -//public class IssueNoteEventHandler -// : StoreEventHandlerBase -// , ILocalEventHandler> -// , ILocalEventHandler>> -// , ILocalEventHandler> -//{ -// private readonly IMaterialRequestManager _materialRequestManager; - -// public IssueNoteEventHandler( -// IMaterialRequestManager materialRequestManager -// ) -// { -// _materialRequestManager = materialRequestManager; -// } - -// [UnitOfWork] -// public virtual async Task HandleEventAsync(SfsConfirmedEntityEventData eventData) -// { -// var entity = eventData.Entity; - -// await UpdateReceivedQtyMaterialRequestAsync(entity).ConfigureAwait(false); -// } - -// private async Task UpdateReceivedQtyMaterialRequestAsync(IssueNote entity) -// { -// var receiveQtyGroup = entity.Details -// .GroupBy(p => new { p.ItemCode, p.ToLocationCode }) -// .Select(p => new { p.Key.ItemCode, p.Key.ToLocationCode, Qty = p.Sum(d => d.Qty) }) -// .ToList(); - -// var materialRequest = await _materialRequestManager.GetByNumberAsync(entity.RequestNumber).ConfigureAwait(false); - -// //更新叫料请求的已收数量 -// foreach (var materialRequestDetail in materialRequest.Details) -// { -// var receiveQty = receiveQtyGroup.FirstOrDefault(p => -// p.ItemCode == materialRequestDetail.ItemCode && -// p.ToLocationCode == materialRequestDetail.ToLocationCode)?.Qty; -// if (receiveQty != null) -// { -// materialRequestDetail.ReceivedQty += receiveQty.Value; -// } -// } - -// await _materialRequestManager.UpdateDetailsAsync(materialRequest).ConfigureAwait(false); -// } - -// [UnitOfWork] -// public virtual async Task HandleEventAsync(SfsCreatedEntityEventData eventData) -// { -// var entity = eventData.Entity; -// if (!entity.UseOnTheWayLocation) -// { -// await UpdateReceivedQtyMaterialRequestAsync(entity).ConfigureAwait(false); -// } - -// } - -// [UnitOfWork] -// public virtual async Task HandleEventAsync(SfsCreatedEntityEventData> eventData) -// { -// var entities = eventData.Entity; -// foreach (var entity in entities.Where(entity => !entity.UseOnTheWayLocation)) -// { -// await UpdateReceivedQtyMaterialRequestAsync(entity).ConfigureAwait(false); -// } -// } -//} diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/MaterialRequestEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/MaterialRequestEventHandler.cs index 830bba2b0..897d7af99 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/MaterialRequestEventHandler.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/MaterialRequestEventHandler.cs @@ -110,7 +110,8 @@ public class MaterialRequestEventHandler await Task.CompletedTask.ConfigureAwait(false); } - private async Task> BuildIssueJobAsync(MaterialRequest materialRequest) + private async Task> BuildIssueJobAsync + (MaterialRequest materialRequest) { var jobs = new List(); @@ -239,6 +240,8 @@ public class MaterialRequestEventHandler detail.RecommendFromLocationErpCode= balance.LocationErpCode; detail.RecommendFromLocationGroup= balance.LocationGroup; detail.RecommendFromWarehouseCode= balance.WarehouseCode; + detail.RecommendQty = balance.Qty; + detail.Uom = balance.Uom; detail.ToLocationCode = materialRequestDetail.ToLocationCode; detail.ToLocationErpCode = materialRequestDetail.ToLocationErpCode; diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/Note/IssueNoteEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/Note/IssueNoteEventHandler.cs new file mode 100644 index 000000000..8d28b137e --- /dev/null +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/Note/IssueNoteEventHandler.cs @@ -0,0 +1,82 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.EventBus; +using Volo.Abp.Uow; +using Win_in.Sfs.Shared.Domain.Shared; +using Win_in.Sfs.Shared.Event; +using Win_in.Sfs.Wms.Store.Domain; + +namespace Win_in.Sfs.Wms.Store.Event.BusinessRequest; + +public class IssueNoteEventHandler + : StoreEventHandlerBase + , ILocalEventHandler> + , ILocalEventHandler>> + , ILocalEventHandler> +{ + private readonly IMaterialRequestManager _materialRequestManager; + + public IssueNoteEventHandler( + IMaterialRequestManager materialRequestManager + ) + { + _materialRequestManager = materialRequestManager; + } + + [UnitOfWork] + public virtual async Task HandleEventAsync(SfsConfirmedEntityEventData eventData) + { + var entity = eventData.Entity; + + await UpdateReceivedQtyMaterialRequestAsync(entity).ConfigureAwait(false); + } + + private async Task UpdateReceivedQtyMaterialRequestAsync(IssueNote entity) + { + var receiveQtyGroup = entity.Details + .GroupBy(p => new { p.ItemCode, p.ToLocationCode }) + .Select(p => new { p.Key.ItemCode, p.Key.ToLocationCode, Qty = p.Sum(d => d.Qty) }) + .ToList(); + + var materialRequest = await _materialRequestManager.GetByNumberAsync(entity.RequestNumber).ConfigureAwait(false); + + if (entity.RequestType != EnumMaterialRequestType.Direct_Issue.ToString()) + { + //更新叫料请求的已收数量 + foreach (var materialRequestDetail in materialRequest.Details) + { + var receiveQty = receiveQtyGroup.FirstOrDefault(p => + p.ItemCode == materialRequestDetail.ItemCode && + p.ToLocationCode == materialRequestDetail.ToLocationCode)?.Qty; + if (receiveQty != null) + { + materialRequestDetail.ReceivedQty += receiveQty.Value; + } + } + + await _materialRequestManager.UpdateDetailsAsync(materialRequest).ConfigureAwait(false); + } + } + + + [UnitOfWork] + public virtual async Task HandleEventAsync(SfsCreatedEntityEventData eventData) + { + var entity = eventData.Entity; + if (!entity.UseOnTheWayLocation) + { + await UpdateReceivedQtyMaterialRequestAsync(entity).ConfigureAwait(false); + } + } + + [UnitOfWork] + public virtual async Task HandleEventAsync(SfsCreatedEntityEventData> eventData) + { + var entities = eventData.Entity; + foreach (var entity in entities.Where(entity => !entity.UseOnTheWayLocation)) + { + await UpdateReceivedQtyMaterialRequestAsync(entity).ConfigureAwait(false); + } + } +} diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/Note/ScrapNoteEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/Note/ScrapNoteEventHandler.cs index f9270b9be..6b4ed7381 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/Note/ScrapNoteEventHandler.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/Note/ScrapNoteEventHandler.cs @@ -1,15 +1,9 @@ -using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using Volo.Abp.EventBus; using Volo.Abp.Uow; -using Win_in.Sfs.Shared.Domain.Shared; using Win_in.Sfs.Shared.Event; -using Win_in.Sfs.Wms.Inventory.Application.Contracts; -using Win_in.Sfs.Wms.Store.Application.Contracts; using Win_in.Sfs.Wms.Store.Domain; -using Win_in.Sfs.Wms.Store.Domain.Shared; using Win_in.Sfs.Wms.Store.Event.Transaction; namespace Win_in.Sfs.Wms.Store.Event.BusinessRequest; diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Transactions/IssueNoteEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Transactions/IssueNoteEventHandler.cs index f43b6e406..1ec0f954a 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Transactions/IssueNoteEventHandler.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Transactions/IssueNoteEventHandler.cs @@ -4,156 +4,128 @@ using System.Linq; using System.Threading.Tasks; using Volo.Abp.EventBus; using Volo.Abp.Uow; -using Win_in.Sfs.Basedata.Application.Contracts; -using Win_in.Sfs.Shared.Domain; using Win_in.Sfs.Shared.Domain.Shared; using Win_in.Sfs.Shared.Event; using Win_in.Sfs.Wms.Inventory.Application.Contracts; using Win_in.Sfs.Wms.Store.Domain; -using Win_in.Sfs.Wms.Store.Event.Transactions; +using Win_in.Sfs.Wms.Store.Event.Transaction; -namespace Win_in.Sfs.Wms.Store.Event.BusinessNote +namespace Win_in.Sfs.Wms.Store.Event.Transactions; + +public class IssueNoteEventHandler + : StoreInventoryEventHandlerBase + , ILocalEventHandler> + , ILocalEventHandler>> + , ILocalEventHandler> { - //public class IssueNoteEventHandler - // : StoreEventHandlerBase - // , ILocalEventHandler> - // , ILocalEventHandler>> - // , ILocalEventHandler> - //{ - // private const EnumTransType TransType = EnumTransType.Issue; - // private readonly Itranlog - - - // [UnitOfWork] - // public virtual async Task HandleEventAsync(SfsCreatedEntityEventData eventData) - // { - // var entity = eventData.Entity; - // var transferLogs = new List(); - // var route = entity.UseOnTheWayLocation - // ? EnumTransferRoute.SourceToOnTheWay - // : EnumTransferRoute.SourceToDestination; - - // //如果是mes拉动 先发到在途 - // if (entity.RequestType == EnumMaterialRequestType.Issue_WIP.ToString()) - // { - // route = EnumTransferRoute.SourceToOnTheWay; - // } - - // transferLogs.AddRange(await BuildTransferLogsAsync(entity, route)); - - // await TransferLogAppService.AddManyAsync(transferLogs); - // } - - - // [UnitOfWork] - // public virtual async Task HandleEventAsync(SfsCreatedEntityEventData> eventData) - // { - // var entities = eventData.Entity; - // var transferLogs = new List(); - // //如果要做库存事务汇总,可以修改此处 - // foreach (var issueNote in entities) - // { - // var route = issueNote.UseOnTheWayLocation - // ? EnumTransferRoute.SourceToOnTheWay - // : EnumTransferRoute.SourceToDestination; - // transferLogs.AddRange(await BuildTransferLogsAsync(issueNote, route)); - // } - - // await TransferLogAppService.AddManyAsync(transferLogs); - // } - - - // [UnitOfWork] - - // public virtual async Task HandleEventAsync(SfsConfirmedEntityEventData eventData) - // { - // var entity = eventData.Entity; - - // var inputList = await BuildTransferLogsAsync(entity, EnumTransferRoute.OnTheWayToDestination); - // await AddTransferLogsAsync(inputList); - // } - - // private async Task AddTransferLogsAsync(List inputList) - // { - // var transferLogs = new List(); - - // transferLogs.AddRange(inputList); - - // await TransferLogAppService.AddManyAsync(transferLogs); - - // } - - // private async Task> BuildTransferLogsAsync(IssueNote issueNote, EnumTransferRoute route) - // { - // var transferLogs = new List(); - // foreach (var detail in issueNote.Details.Where(detail => detail.Qty.Qty != 0)) - // { - // var transferLog = ObjectMapper.Map(detail); - - // LocationDTO fromLocationDTO = null; - // LocationDTO toLocationDTO = null; - - // if (issueNote.UseOnTheWayLocation) - // { - // var location = await LocationAppService.GetByCodeAsync(detail.OnTheWayLocationCode); - // switch (route) - // { - // case EnumTransferRoute.SourceToOnTheWay: - // fromLocationDTO = await LocationAppService.GetByCodeAsync(detail.FromLocationCode); - - // toLocationDTO = await LocationAppService.GetByCodeAsync(detail.OnTheWayLocationCode); - // break; - // case EnumTransferRoute.OnTheWayToDestination: - // fromLocationDTO = await LocationAppService.GetByCodeAsync(detail.OnTheWayLocationCode); - - // toLocationDTO = await LocationAppService.GetByCodeAsync(detail.ToLocationCode); - - // await RemovePackingCodeAndContainerCodeAndLotAsync(transferLog); - // break; - // case EnumTransferRoute.SourceToDestination: - // default: - // throw new ArgumentOutOfRangeException(nameof(route), route, null); - // } - // } - // else - // { - // fromLocationDTO = await LocationAppService.GetByCodeAsync(detail.FromLocationCode); - // toLocationDTO = await LocationAppService.GetByCodeAsync(detail.ToLocationCode); - // } - - // transferLog.FromLocationCode = fromLocationDTO.Code; - // transferLog.FromLocationArea = fromLocationDTO.AreaCode; - // transferLog.FromLocationErpCode = fromLocationDTO.ErpLocationCode; - // transferLog.FromLocationGroup = fromLocationDTO.LocationGroupCode; - - // transferLog.ToLocationCode = toLocationDTO.Code; - // transferLog.ToLocationArea = toLocationDTO.AreaCode; - // transferLog.ToLocationErpCode = toLocationDTO.ErpLocationCode; - // transferLog.ToLocationGroup = toLocationDTO.LocationGroupCode; - - // transferLog.TransType = TransType; - // transferLog.TransSubType = Enum.Parse(issueNote.RequestType); - // transferLog.Company = issueNote.Company; - // transferLog.Worker = issueNote.Worker; - // transferLog.DocNumber = issueNote.Number; - // transferLog.JobNumber = issueNote.JobNumber; - - // transferLogs.Add(transferLog); - // } - - // return transferLogs; - // } - // private async Task RemovePackingCodeAndContainerCodeAndLotAsync(TransferLogCreateInput transferLogCreateInput) - // { - // transferLogCreateInput.ToPackingCode = ""; - // transferLogCreateInput.ToLot = ""; - // transferLogCreateInput.ToContainerCode = ""; - - // transferLogCreateInput.FromPackingCode = ""; - // transferLogCreateInput.FromLot = ""; - // transferLogCreateInput.FromContainerCode = ""; - - - // } - //} + private const EnumTransType TransType = EnumTransType.Issue; + + [UnitOfWork] + public virtual async Task HandleEventAsync(SfsCreatedEntityEventData eventData) + { + var entity = eventData.Entity; + var transferLogs = new List(); + var route = entity.UseOnTheWayLocation + ? EnumTransferRoute.SourceToOnTheWay + : EnumTransferRoute.SourceToDestination; + transferLogs.AddRange(await BuildTransferLogsAsync(entity, route).ConfigureAwait(false)); + + //如果是mes拉动 先发到在途 + if (entity.RequestType == EnumMaterialRequestType.Issue_WIP.ToString()) + { + route = EnumTransferRoute.SourceToOnTheWay; + } + + await TransferLogAppService.AddManyAsync(transferLogs).ConfigureAwait(false); + } + + [UnitOfWork] + public virtual async Task HandleEventAsync(SfsCreatedEntityEventData> eventData) + { + var entities = eventData.Entity; + var transferLogs = new List(); + //如果要做库存事务汇总,可以修改此处 + foreach (var issueNote in entities) + { + var route = issueNote.UseOnTheWayLocation + ? EnumTransferRoute.SourceToOnTheWay + : EnumTransferRoute.SourceToDestination; + transferLogs.AddRange(await BuildTransferLogsAsync(issueNote, route).ConfigureAwait(false)); + } + + await TransferLogAppService.AddManyAsync(transferLogs).ConfigureAwait(false); + } + + [UnitOfWork] + + public virtual async Task HandleEventAsync(SfsConfirmedEntityEventData eventData) + { + var entity = eventData.Entity; + + var inputList = await BuildTransferLogsAsync(entity, EnumTransferRoute.OnTheWayToDestination).ConfigureAwait(false); + await AddTransferLogsAsync(inputList).ConfigureAwait(false); + } + + private async Task AddTransferLogsAsync(List inputList) + { + var transferLogs = new List(); + + transferLogs.AddRange(inputList); + + await TransferLogAppService.AddManyAsync(transferLogs).ConfigureAwait(false); + + } + + private async Task> BuildTransferLogsAsync(IssueNote issueNote, EnumTransferRoute route) + { + var transferLogs = new List(); + foreach (var detail in issueNote.Details.Where(detail => detail.Qty != 0)) + { + var transferLog = ObjectMapper.Map(detail); + + if (issueNote.UseOnTheWayLocation) + { + var location = await LocationAclService.GetByCodeAsync(detail.OnTheWayLocationCode).ConfigureAwait(false); + switch (route) + { + case EnumTransferRoute.SourceToOnTheWay: + detail.ToLocationCode = detail.OnTheWayLocationCode; + detail.ToLocationErpCode = location.ErpLocationCode; + detail.ToWarehouseCode = location.WarehouseCode; + detail.ToLocationArea = location.AreaCode; + break; + case EnumTransferRoute.OnTheWayToDestination: + detail.FromLocationCode = detail.OnTheWayLocationCode; + detail.FromLocationErpCode = location.ErpLocationCode; + detail.FromWarehouseCode = location.WarehouseCode; + detail.FromLocationArea = location.AreaCode; + break; + case EnumTransferRoute.SourceToDestination: + default: + throw new ArgumentOutOfRangeException(nameof(route), route, null); + } + } + + if (issueNote.UseOnTheWayLocation) + { + transferLog.FromLocationCode = detail.OnTheWayLocationCode; + var location = await LocationAclService.GetByCodeAsync(detail.OnTheWayLocationCode).ConfigureAwait(false); + transferLog.FromLocationGroup = location.LocationGroupCode; + transferLog.FromLocationArea = location.AreaCode; + transferLog.FromLocationErpCode = location.ErpLocationCode; + transferLog.FromWarehouseCode=location.WarehouseCode; + } + + transferLog.TransType = TransType; + transferLog.TransSubType = Enum.Parse(issueNote.RequestType); + transferLog.Worker = issueNote.Worker; + transferLog.DocNumber = issueNote.Number; + transferLog.JobNumber = issueNote.JobNumber; + + transferLogs.Add(transferLog); + } + + return transferLogs; + } + }