From eb7df9a7329a367da3a0133c9f9191c6963265c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B8=A4=E6=97=AD=5BIrelia=5D?= <366601522@qq.com> Date: Wed, 19 Apr 2023 22:03:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Enums/Job/EnumJobStatus.cs | 9 ++ .../Bases/SfsJobAppServiceBase.cs | 7 + .../PurchaseReceiptJobManager.cs | 3 +- .../Requests/DeliverRequestEventHandler.cs | 140 ++++++++++++------ .../Requests/Note/IssueNoteEventHandler.cs | 56 +++---- .../ProductRecycleRequestEventHandler.cs | 45 +++++- .../UnplannedIssueRequestEventHandler.cs | 53 ++++++- .../UnplannedReceiptRequestEventHandler.cs | 57 ++++++- 8 files changed, 285 insertions(+), 85 deletions(-) diff --git a/be/Modules/Shared/src/Win_in.Sfs.Shared.Domain.Shared/Enums/Job/EnumJobStatus.cs b/be/Modules/Shared/src/Win_in.Sfs.Shared.Domain.Shared/Enums/Job/EnumJobStatus.cs index dfe744d20..55467616b 100644 --- a/be/Modules/Shared/src/Win_in.Sfs.Shared.Domain.Shared/Enums/Job/EnumJobStatus.cs +++ b/be/Modules/Shared/src/Win_in.Sfs.Shared.Domain.Shared/Enums/Job/EnumJobStatus.cs @@ -1,3 +1,6 @@ +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + namespace Win_in.Sfs.Shared.Domain.Shared; public enum EnumJobStatus @@ -5,30 +8,36 @@ public enum EnumJobStatus /// /// 空枚举 /// + [Display(Name = "空枚举")] None = 0, /// /// 待处理 /// + [Display(Name = "待处理")] Open = 1, /// /// 执行中 /// + [Display(Name = "执行中")] Doing = 2, /// /// 完成 /// + [Display(Name = "完成")] Done = 3, /// /// 关闭 /// + [Display(Name = "关闭")] Closed = 8, /// /// 作废 /// + [Display(Name = "作废")] Cancelled = 9 } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Bases/SfsJobAppServiceBase.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Bases/SfsJobAppServiceBase.cs index aa9cc4b2c..8aa54abe2 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Bases/SfsJobAppServiceBase.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Bases/SfsJobAppServiceBase.cs @@ -11,6 +11,7 @@ using Volo.Abp.Validation; using Win_in.Sfs.Shared.Application; using Win_in.Sfs.Shared.Application.Contracts; using Win_in.Sfs.Shared.Domain; +using Win_in.Sfs.Shared.Domain.Shared; using Win_in.Sfs.Wms.Store.Application.Contracts; using Win_in.Sfs.Wms.Store.Domain; @@ -153,6 +154,12 @@ public abstract class SfsJobAppServiceBase CompleteAsync(Guid id, TEntityDto dto) { var handleEntity = ObjectMapper.Map(dto); + var job= await _repository.GetAsync(id).ConfigureAwait(false); + if (job.JobStatus is EnumJobStatus.Closed or EnumJobStatus.Cancelled or EnumJobStatus.None or EnumJobStatus.Done)//需要考虑下 多次提交的问题 所以不判断 进行中 + { + throw new UserFriendlyException($"任务状态错误:编号为【{job.Number}】的任务已经【{job.JobStatus.GetDisplayName()}】"); + } + var handleResult = await _jobManager.CompleteAsync(handleEntity, CurrentUser).ConfigureAwait(false); var handleDto = ObjectMapper.Map(handleResult); return handleDto; diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Domain/Jobs/PurchaseReceiptJobs/PurchaseReceiptJobManager.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Domain/Jobs/PurchaseReceiptJobs/PurchaseReceiptJobManager.cs index 63a8d4584..11d85fc8d 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Domain/Jobs/PurchaseReceiptJobs/PurchaseReceiptJobManager.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Domain/Jobs/PurchaseReceiptJobs/PurchaseReceiptJobManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Users; using Volo.Abp.Validation; using Win_in.Sfs.Shared.Domain.Shared; @@ -31,9 +32,7 @@ public class PurchaseReceiptJobManager : SfsJobManagerBase CompleteAsync(PurchaseReceiptJob input, ICurrentUser user) { var entity = await Repository.FindAsync(input.Id).ConfigureAwait(false); - BuildDetailHandledAsync(input, entity); - //设置任务为完成 return await base.CompleteAsync(entity, user).ConfigureAwait(false); } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/DeliverRequestEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/DeliverRequestEventHandler.cs index acba1747c..f63574787 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/DeliverRequestEventHandler.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/DeliverRequestEventHandler.cs @@ -9,33 +9,89 @@ using Win_in.Sfs.Basedata.Application.Contracts; 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; namespace Win_in.Sfs.Wms.Store.Event.BusinessRequest; -using Win_in.Sfs.Wms.Store.Application.Contracts; - public class DeliverRequestEventHandler : StoreEventHandlerBase - , ILocalEventHandler> - , ILocalEventHandler> + , ILocalEventHandler> + , ILocalEventHandler> + , ILocalEventHandler> + , ILocalEventHandler>> { private readonly IDeliverNoteAppService _deliverNoteApp; private readonly IDeliverJobAppService _deliverJobApp; private readonly ICustomerAddressAppService _customerAddressApp; + private readonly IDeliverRequestManager _deliverRequestManager; public DeliverRequestEventHandler( IDeliverJobAppService deliverJobApp , IDeliverNoteAppService deliverNoteApp - , ICustomerAddressAppService customerAddressApp - ) + , ICustomerAddressAppService customerAddressApp, IDeliverRequestManager deliverRequestManager) { _deliverNoteApp = deliverNoteApp; _deliverJobApp = deliverJobApp; _customerAddressApp = customerAddressApp; + _deliverRequestManager = deliverRequestManager; + } + + + /// + /// 创建后 + /// + /// Event data + [UnitOfWork] + public async Task HandleEventAsync(SfsCreatedEntityEventData eventData) + { + var entity = eventData.Entity; + if (entity.AutoSubmit) + { + await _deliverRequestManager.SubmitAsync(entity).ConfigureAwait(false); + } + } + + /// + /// 批量创建后 + /// + /// Event data + [UnitOfWork] + public async Task HandleEventAsync(SfsCreatedEntityEventData> eventData) + { + var entitys = eventData.Entity; + foreach (var entity in entitys) + { + if (entity.AutoSubmit) + { + await _deliverRequestManager.SubmitAsync(entity).ConfigureAwait(false); + } + } } + /// + /// 审批后 + /// + /// + /// + [UnitOfWork] + public virtual async Task HandleEventAsync(SfsAbortedEntityEventData eventData) + { + var entity = eventData.Entity; + + //东阳特殊逻辑 + if (!entity.DirectCreateNote) + { + await _deliverJobApp.CancelByDeliverRequestAsync(entity.Number).ConfigureAwait(false); + } + } + + /// + /// 执行后 + /// + /// + /// [UnitOfWork] public virtual async Task HandleEventAsync(SfsHandledEntityEventData eventData) { @@ -54,26 +110,32 @@ public class DeliverRequestEventHandler } } + + #region 私有 + private async Task BuildDeliverNoteAsync(DeliverRequest request) { - var transactionType = await TransactionTypeAclService.GetByTransTypeAsync(EnumTransType.Deliver, EnumTransSubType.None).ConfigureAwait(false); + var transactionType = await TransactionTypeAclService + .GetByTransTypeAsync(EnumTransType.Deliver, EnumTransSubType.None).ConfigureAwait(false); if (request.DeliverRequestType == EnumDeliverRequestType.Normal) { transactionType = await TransactionTypeAclService.GetByTransTypeAsync( - EnumTransType.Deliver, - EnumTransSubType.Deliver_Standard).ConfigureAwait(false); + EnumTransType.Deliver, + EnumTransSubType.Deliver_Standard).ConfigureAwait(false); } else if (request.DeliverRequestType == EnumDeliverRequestType.FIS) { transactionType = await TransactionTypeAclService.GetByTransTypeAsync( - EnumTransType.Deliver, - EnumTransSubType.Deliver_FIS).ConfigureAwait(false); + EnumTransType.Deliver, + EnumTransSubType.Deliver_FIS).ConfigureAwait(false); } var createInput = ObjectMapper.Map(request); - var customerAddress = (await _customerAddressApp.GetByCustomerCodeAsync(request.CustomerCode).ConfigureAwait(false)).FirstOrDefault(); + var customerAddress = + (await _customerAddressApp.GetByCustomerCodeAsync(request.CustomerCode).ConfigureAwait(false)) + .FirstOrDefault(); LocationDTO toLocation = null; if (customerAddress != null && !string.IsNullOrEmpty(customerAddress.LocationCode)) @@ -88,14 +150,14 @@ public class DeliverRequestEventHandler foreach (var detail in request.Details) { var balances = await BalanceAclService.GetRecommendBalancesAsync( - new RecommendBalanceRequestInput() - { - ItemCode = detail.ItemCode, - Qty = detail.Qty, - LocationTypes = transactionType.OutLocationTypes, - LocationAreas = new List() { detail.AreaCode }, - Statuses = transactionType.OutInventoryStatuses - }).ConfigureAwait(false); + new RecommendBalanceRequestInput + { + ItemCode = detail.ItemCode, + Qty = detail.Qty, + LocationTypes = transactionType.OutLocationTypes, + LocationAreas = new List { detail.AreaCode }, + Statuses = transactionType.OutInventoryStatuses + }).ConfigureAwait(false); var sumQty = balances.Sum(t => t.Qty); @@ -150,9 +212,12 @@ public class DeliverRequestEventHandler throw new ArgumentOutOfRangeException(); } - var transactionType = await TransactionTypeAclService.GetByTransTypeAsync(EnumTransType.Deliver, transSubType).ConfigureAwait(false); + var transactionType = await TransactionTypeAclService.GetByTransTypeAsync(EnumTransType.Deliver, transSubType) + .ConfigureAwait(false); var createInput = ObjectMapper.Map(request); - var customerAddress = (await _customerAddressApp.GetByCustomerCodeAsync(request.CustomerCode).ConfigureAwait(false)).FirstOrDefault(); + var customerAddress = + (await _customerAddressApp.GetByCustomerCodeAsync(request.CustomerCode).ConfigureAwait(false)) + .FirstOrDefault(); LocationDTO toLocation = null; if (customerAddress != null && !string.IsNullOrEmpty(customerAddress.LocationCode)) { @@ -165,14 +230,14 @@ public class DeliverRequestEventHandler foreach (var detail in request.Details) { var balances = await BalanceAclService.GetRecommendBalancesAsync( - new RecommendBalanceRequestInput() - { - ItemCode = detail.ItemCode, - Qty = detail.Qty, - LocationTypes = transactionType.OutLocationTypes, - LocationAreas = new List() { detail.AreaCode }, - Statuses = transactionType.OutInventoryStatuses - }).ConfigureAwait(false); + new RecommendBalanceRequestInput + { + ItemCode = detail.ItemCode, + Qty = detail.Qty, + LocationTypes = transactionType.OutLocationTypes, + LocationAreas = new List { detail.AreaCode }, + Statuses = transactionType.OutInventoryStatuses + }).ConfigureAwait(false); var sumQty = balances.Sum(t => t.Qty); @@ -190,6 +255,7 @@ public class DeliverRequestEventHandler inputDetail.ToLocationErpCode = toLocation.ErpLocationCode; inputDetail.ToWarehouseCode = toLocation.WarehouseCode; } + var item = await ItemBasicAclService.GetByCodeAsync(balance.ItemCode).ConfigureAwait(false); if (item != null) @@ -214,18 +280,8 @@ public class DeliverRequestEventHandler createInput.Priority = PriorityHelper.GetPriority(Clock); createInput.PriorityIncrement = 1; - return new List() { createInput }; + return new List { createInput }; } - [UnitOfWork] - public virtual async Task HandleEventAsync(SfsAbortedEntityEventData eventData) - { - var entity = eventData.Entity; - - //东阳特殊逻辑 - if (!entity.DirectCreateNote) - { - await _deliverJobApp.CancelByDeliverRequestAsync(entity.Number).ConfigureAwait(false); - } - } + #endregion } 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 index 94d4e8369..8f718fb7e 100644 --- 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 @@ -6,6 +6,8 @@ using Volo.Abp.Uow; using Win_in.Sfs.Shared.Domain.Shared; using Win_in.Sfs.Shared.Event; using Win_in.Sfs.Wms.Store.Domain; +using static Win_in.Sfs.Wms.Store.Domain.Shared.StoreSettings; +using MaterialRequest = Win_in.Sfs.Wms.Store.Domain.MaterialRequest; namespace Win_in.Sfs.Wms.Store.Event.BusinessRequest; @@ -37,33 +39,6 @@ public class IssueNoteEventHandler 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.Issue_Direct.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); - } - } - /// /// 当叫料记录创建后 修改请求的值 /// @@ -93,4 +68,31 @@ public class IssueNoteEventHandler 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.Issue_Direct.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); + } + } } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/ProductRecycleRequestEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/ProductRecycleRequestEventHandler.cs index fa0a16a2e..2e0b3a9f8 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/ProductRecycleRequestEventHandler.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/ProductRecycleRequestEventHandler.cs @@ -16,20 +16,55 @@ using Application.Contracts; public class ProductRecycleRequestEventHandler : StoreEventHandlerBase , ILocalEventHandler> + , ILocalEventHandler> + , ILocalEventHandler>> { private readonly IProductRecycleNoteAppService _productRecycleNoteApp; private readonly IBackFlushNoteAppService _backFlushNoteApp; private readonly IBomAppService _bomApp; + private readonly IProductRecycleRequestManager _productRecycleRequestManager; public ProductRecycleRequestEventHandler( IProductRecycleNoteAppService productRecycleNoteApp, IBackFlushNoteAppService backFlushNoteApp, - IBomAppService bomApp - ) + IBomAppService bomApp, IProductRecycleRequestManager + productRecycleRequestManager) { _productRecycleNoteApp = productRecycleNoteApp; _backFlushNoteApp = backFlushNoteApp; _bomApp = bomApp; + _productRecycleRequestManager = productRecycleRequestManager; + } + + /// + /// 创建后 + /// + /// Event data + [UnitOfWork] + public async Task HandleEventAsync(SfsCreatedEntityEventData eventData) + { + var entity = eventData.Entity; + if (entity.AutoSubmit) + { + await _productRecycleRequestManager.SubmitAsync(entity).ConfigureAwait(false); + } + } + + /// + /// 批量创建后 + /// + /// Event data + [UnitOfWork] + public async Task HandleEventAsync(SfsCreatedEntityEventData> eventData) + { + var entitys = eventData.Entity; + foreach (var entity in entitys) + { + if (entity.AutoSubmit) + { + await _productRecycleRequestManager.SubmitAsync(entity).ConfigureAwait(false); + } + } } [UnitOfWork] @@ -49,6 +84,8 @@ public class ProductRecycleRequestEventHandler } } + #region 私有 + private async Task BuildProductRecycleNoteAsync(ProductRecycleRequest request) { var createInput = ObjectMapper.Map(request); @@ -115,6 +152,10 @@ public class ProductRecycleRequestEventHandler return detailInput; } + #endregion + + + /* private async Task> BuildFlushNotesAsync(ProductRecycleRequest request) { diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/UnplannedIssueRequestEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/UnplannedIssueRequestEventHandler.cs index 4969e34e8..acfe68f31 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/UnplannedIssueRequestEventHandler.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/UnplannedIssueRequestEventHandler.cs @@ -10,20 +10,58 @@ namespace Win_in.Sfs.Wms.Store.Event.BusinessRequest; public class UnplannedIssueRequestEventHandler : StoreEventHandlerBase - , ILocalEventHandler> + , ILocalEventHandler> + , ILocalEventHandler>> + , ILocalEventHandler> { private readonly IUnplannedIssueJobAppService _unplannedIssueJobApp; private readonly IUnplannedIssueNoteAppService _unplannedIssueNoteAppService; + private readonly IUnplannedIssueRequestManager _unplannedIssueRequestManager; public UnplannedIssueRequestEventHandler( - IUnplannedIssueJobAppService unplannedIssueJobApp - , IUnplannedIssueNoteAppService unplannedIssueNoteAppService - ) + IUnplannedIssueJobAppService unplannedIssueJobApp, + IUnplannedIssueNoteAppService unplannedIssueNoteAppService, + IUnplannedIssueRequestManager unplannedIssueRequestManager) { _unplannedIssueJobApp = unplannedIssueJobApp; _unplannedIssueNoteAppService = unplannedIssueNoteAppService; + _unplannedIssueRequestManager = unplannedIssueRequestManager; } + /// + /// 创建后 + /// + /// Event data + public async Task HandleEventAsync(SfsCreatedEntityEventData eventData) + { + var entity = eventData.Entity; + if (entity.AutoSubmit) + { + await _unplannedIssueRequestManager.SubmitAsync(entity).ConfigureAwait(false); + } + } + + /// + /// 批量创建后 + /// + /// Event data + public async Task HandleEventAsync(SfsCreatedEntityEventData> eventData) + { + var entitys = eventData.Entity; + foreach (var entity in entitys) + { + if (entity.AutoSubmit) + { + await _unplannedIssueRequestManager.SubmitAsync(entity).ConfigureAwait(false); + } + } + } + + /// + /// 执行后 + /// + /// + /// public virtual async Task HandleEventAsync(SfsHandledEntityEventData eventData) { var entity = eventData.Entity; @@ -39,7 +77,10 @@ public class UnplannedIssueRequestEventHandler } } - private async Task BuildUnplannedIssueNoteCreateInputAsync(UnplannedIssueRequest entity) + #region 私有 + + private async Task BuildUnplannedIssueNoteCreateInputAsync( + UnplannedIssueRequest entity) { await Task.CompletedTask.ConfigureAwait(false); var createInput = ObjectMapper.Map(entity); @@ -50,6 +91,8 @@ public class UnplannedIssueRequestEventHandler return createInput; } + #endregion + private async Task BuildUnplannedIssueJobCreateInputAsync(UnplannedIssueRequest entity) { await Task.CompletedTask.ConfigureAwait(false); diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/UnplannedReceiptRequestEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/UnplannedReceiptRequestEventHandler.cs index 5e93227dc..dcec7d221 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/UnplannedReceiptRequestEventHandler.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/UnplannedReceiptRequestEventHandler.cs @@ -10,20 +10,58 @@ namespace Win_in.Sfs.Wms.Store.Event.BusinessRequest; public class UnplannedReceiptRequestEventHandler : StoreEventHandlerBase - , ILocalEventHandler> + , ILocalEventHandler> + , ILocalEventHandler>> + , ILocalEventHandler> { private readonly IUnplannedReceiptJobAppService _unplannedReceiptJobApp; private readonly IUnplannedReceiptNoteAppService _unplannedReceiptNoteApp; + private readonly IUnplannedReceiptRequestManager _unplannedReceiptRequestManager; public UnplannedReceiptRequestEventHandler( - IUnplannedReceiptJobAppService unplannedReceiptJobApp - , IUnplannedReceiptNoteAppService unplannedReceiptNoteApp - ) + IUnplannedReceiptJobAppService unplannedReceiptJobApp, + IUnplannedReceiptNoteAppService unplannedReceiptNoteApp, + IUnplannedReceiptRequestManager unplannedReceiptRequestManager) { _unplannedReceiptNoteApp = unplannedReceiptNoteApp; + _unplannedReceiptRequestManager = unplannedReceiptRequestManager; _unplannedReceiptJobApp = unplannedReceiptJobApp; } + /// + /// 创建后 + /// + /// Event data + public async Task HandleEventAsync(SfsCreatedEntityEventData eventData) + { + var entity = eventData.Entity; + if (entity.AutoSubmit) + { + await _unplannedReceiptRequestManager.SubmitAsync(entity).ConfigureAwait(false); + } + } + + /// + /// 批量创建后 + /// + /// Event data + public async Task HandleEventAsync(SfsCreatedEntityEventData> eventData) + { + var entitys = eventData.Entity; + foreach (var entity in entitys) + { + if (entity.AutoSubmit) + { + await _unplannedReceiptRequestManager.SubmitAsync(entity).ConfigureAwait(false); + } + } + } + + /// + /// 执行后 + /// + /// + /// public virtual async Task HandleEventAsync(SfsHandledEntityEventData eventData) { var entity = eventData.Entity; @@ -41,7 +79,10 @@ public class UnplannedReceiptRequestEventHandler } } - private async Task BuildUnplannedReceiptNoteCreateInputAsync(UnplannedReceiptRequest entity) + #region 私有 + + private async Task BuildUnplannedReceiptNoteCreateInputAsync( + UnplannedReceiptRequest entity) { await Task.CompletedTask.ConfigureAwait(false); var createInput = ObjectMapper.Map(entity); @@ -52,7 +93,8 @@ public class UnplannedReceiptRequestEventHandler return createInput; } - private async Task BuildToUnplannedReceiptJobCreateInputAsync(UnplannedReceiptRequest entity) + private async Task BuildToUnplannedReceiptJobCreateInputAsync( + UnplannedReceiptRequest entity) { await Task.CompletedTask.ConfigureAwait(false); var createInput = ObjectMapper.Map(entity); @@ -75,6 +117,8 @@ public class UnplannedReceiptRequestEventHandler return createInput; } + #endregion + /* 改用AutoMapper实现 private void SetUnplannedReceiptJobDetails(UnplannedReceiptJobCreateInput createInput, List details) { @@ -111,5 +155,4 @@ public class UnplannedReceiptRequestEventHandler } } */ - }