From af5f739091ff7f87c7e6d051438f0b376b97eb33 Mon Sep 17 00:00:00 2001 From: lvzb <35200379@qq.com> Date: Tue, 11 Jun 2024 09:13:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=90=E5=93=81=E5=8F=91=E8=BF=90=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeliverNotes/IDeliverNoteAppService.cs | 2 + .../DeliverNotes/DeliverNoteAppService.cs | 14 ++ .../DeliverRequestAppService.cs | 8 +- .../Requests/DeliverRequestEventHandler.cs | 142 +++++++++--------- 4 files changed, 90 insertions(+), 76 deletions(-) diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Notes/DeliverNotes/IDeliverNoteAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Notes/DeliverNotes/IDeliverNoteAppService.cs index b0aab9524..03fee92c8 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Notes/DeliverNotes/IDeliverNoteAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Notes/DeliverNotes/IDeliverNoteAppService.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -35,4 +36,5 @@ public interface IDeliverNoteAppService : Task ExportForRAWAsync(SfsExportRequestInput requestInput); Task SumPrintAsync(string number); + Task> CreateManyAsync(List inputs); } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/DeliverNotes/DeliverNoteAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/DeliverNotes/DeliverNoteAppService.cs index c50a174bb..03ab41c6e 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/DeliverNotes/DeliverNoteAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/DeliverNotes/DeliverNoteAppService.cs @@ -13,6 +13,7 @@ using Win_in.Sfs.Wms.Store.Domain.Shared; namespace Win_in.Sfs.Wms.Store.Application; +using Volo.Abp.ObjectMapping; using Win_in.Sfs.Shared.Application.Contracts; using Win_in.Sfs.Shared.Domain; @@ -50,7 +51,20 @@ public class DeliverNoteAppService : var dto = ObjectMapper.Map(entity); return dto; } + /// + /// 新增接口 + /// + /// + /// + [HttpPost("create-many")] + public async Task> CreateManyAsync(List inputs) + { + var entitys = ObjectMapper.Map, List>(inputs); + await _deliverNoteManager.CreateManyAsync(entitys).ConfigureAwait(false); + var dtos = ObjectMapper.Map, List>(entitys); + return dtos; + } /// /// 新增接口 /// diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Requests/DeliverRequests/DeliverRequestAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Requests/DeliverRequests/DeliverRequestAppService.cs index 8d712414e..2146cf2d2 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Requests/DeliverRequests/DeliverRequestAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Requests/DeliverRequests/DeliverRequestAppService.cs @@ -163,10 +163,10 @@ IItemBasicAppService itemBasicAppService) public virtual async Task> HandleListAsync(List ids) { var entitys = await _repository.GetListAsync(r=> ids.Contains(r.Id),true).ConfigureAwait(false); - if (entitys.Select(r => r.CustomerCode).Distinct().Count()>1) - { - throw new UserFriendlyException($"所选申请涉及多个客户不能创建为一个发货单,请重新选择!"); - } + //if (entitys.Select(r => r.CustomerCode).Distinct().Count()>1) + //{ + // throw new UserFriendlyException($"所选申请涉及多个客户不能创建为一个发货单,请重新选择!"); + //} Check.NotNull(entitys, typeof(DeliverRequest).Name); var result = await _deliverRequestManager.HandleListAsync(entitys).ConfigureAwait(false); var dtos = ObjectMapper.Map, List>(entitys); 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 68af62e6e..669794694 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 @@ -119,98 +119,96 @@ public class DeliverRequestEventHandler //东阳特殊逻辑 if (entitys.First().DirectCreateNote) { - var noteCreateInput = await BuildDeliverNoteAsync(entitys).ConfigureAwait(false); - await _deliverNoteApp.CreateAsync(noteCreateInput).ConfigureAwait(false); + var noteCreateInputs = await BuildDeliverNotesAsync(entitys).ConfigureAwait(false); + await _deliverNoteApp.CreateManyAsync(noteCreateInputs).ConfigureAwait(false); } } #region 私有 - private async Task BuildDeliverNoteAsync(List requests) + private async Task> BuildDeliverNotesAsync(List requests) { - var transactionType = await TransactionTypeAclService - .GetByTransTypeAsync(EnumTransType.Deliver, EnumTransSubType.None).ConfigureAwait(false); - - if (requests.First().DeliverRequestType == EnumDeliverRequestType.Normal) - { - transactionType = await TransactionTypeAclService.GetByTransTypeAsync( - EnumTransType.Deliver, - EnumTransSubType.Deliver_Standard).ConfigureAwait(false); - } - else if (requests.First().DeliverRequestType == EnumDeliverRequestType.FIS) + List createInputs = new List(); + var transactionType = await TransactionTypeAclService.GetByTransTypeAsync(EnumTransType.Deliver, EnumTransSubType.None).ConfigureAwait(false); + foreach (var request in requests) { - transactionType = await TransactionTypeAclService.GetByTransTypeAsync( - EnumTransType.Deliver, - EnumTransSubType.Deliver_FIS).ConfigureAwait(false); - } - - var createInput = ObjectMapper.Map(requests.First()); - - var customerAddress = - (await _customerAddressApp.GetByCustomerCodeAsync(createInput.CustomerCode).ConfigureAwait(false)) - .FirstOrDefault(); - - LocationDTO toLocation = null; - if (customerAddress != null && !string.IsNullOrEmpty(customerAddress.LocationCode)) - { - toLocation = await LocationAclService.GetByCodeAsync(customerAddress.LocationCode).ConfigureAwait(false); - - Check.NotNull(toLocation, $"客户库位 {customerAddress.LocationCode} 不存在"); - } - - createInput.Details = new List(); - List oldBalances = new List(); - foreach (var detail in requests.SelectMany(r=>r.Details)) - { - var locations = await _locationAppService.GetListByTypesAndErpCodeAsync(transactionType.OutLocationTypes, detail.AreaCode).ConfigureAwait(false); - if (locations.Count <= 0) + if (request.DeliverRequestType == EnumDeliverRequestType.Normal) { - throw new UserFriendlyException($"储位 {detail.AreaCode} 未找到对应的成品库和半成品库。"); + transactionType = await TransactionTypeAclService.GetByTransTypeAsync( + EnumTransType.Deliver, + EnumTransSubType.Deliver_Standard).ConfigureAwait(false); } - - var balances = await _balanceAppService.GetRecommendBalancesByLocationsExpectOldBalancesAsync( - new RecommendBalanceRequestInput - { - ItemCode = detail.ItemCode, - Qty = detail.Qty, - Locations = locations.Select(r => r.Code).ToList(), - Statuses = transactionType.OutInventoryStatuses, - OldBalances=oldBalances, - }).ConfigureAwait(false); - - var sumQty = balances.Sum(t => t.Qty); - - if (sumQty < detail.Qty) + else if (request.DeliverRequestType == EnumDeliverRequestType.FIS) { - throw new UserFriendlyException($"ERP料号 {detail.ItemCode} 库存余额 {sumQty} 小于 {detail.Qty}。"); + transactionType = await TransactionTypeAclService.GetByTransTypeAsync( + EnumTransType.Deliver, + EnumTransSubType.Deliver_FIS).ConfigureAwait(false); } - oldBalances.AddRange(balances); - foreach (var balance in balances) + var createInput = ObjectMapper.Map(request); + var customerAddress = (await _customerAddressApp.GetByCustomerCodeAsync(createInput.CustomerCode).ConfigureAwait(false)).FirstOrDefault(); + LocationDTO toLocation = null; + if (customerAddress != null && !string.IsNullOrEmpty(customerAddress.LocationCode)) { - var inputDetail = ObjectMapper.Map(balance); - - var item = await ItemBasicAclService.GetByCodeAsync(balance.ItemCode).ConfigureAwait(false); + toLocation = await LocationAclService.GetByCodeAsync(customerAddress.LocationCode).ConfigureAwait(false); - if (item != null) + Check.NotNull(toLocation, $"客户库位 {customerAddress.LocationCode} 不存在"); + } + createInput.Details = new List(); + List oldBalances = new List(); + foreach (var detail in request.Details) + { + var locations = await _locationAppService.GetListByTypesAndErpCodeAsync(transactionType.OutLocationTypes, detail.AreaCode).ConfigureAwait(false); + if (locations.Count <= 0) { - inputDetail.StdPackQty = item.StdPackQty; + throw new UserFriendlyException($"储位 {detail.AreaCode} 未找到对应的成品库和半成品库。"); } - if (toLocation != null) - { - inputDetail.ToLocationCode = toLocation.Code; + var balances = await _balanceAppService.GetRecommendBalancesByLocationsExpectOldBalancesAsync( + new RecommendBalanceRequestInput + { + ItemCode = detail.ItemCode, + Qty = detail.Qty, + Locations = locations.Select(r => r.Code).ToList(), + Statuses = transactionType.OutInventoryStatuses, + OldBalances = oldBalances, + }).ConfigureAwait(false); - inputDetail.ToLocationErpCode = toLocation.ErpLocationCode; + var sumQty = balances.Sum(t => t.Qty); + + if (sumQty < detail.Qty) + { + throw new UserFriendlyException($"ERP料号 {detail.ItemCode} 库存余额 {sumQty} 小于 {detail.Qty}。"); } + oldBalances.AddRange(balances); + foreach (var balance in balances) + { + var inputDetail = ObjectMapper.Map(balance); - inputDetail.ExtraProperties = detail.ExtraProperties; - inputDetail.MesDeliveryNo = detail.MesDeliveryNo; - inputDetail.IdentityNo = detail.IdentityNo; - inputDetail.MesDeliveryPlan = detail.MesDeliveryPlan; - createInput.Details.Add(inputDetail); + var item = await ItemBasicAclService.GetByCodeAsync(balance.ItemCode).ConfigureAwait(false); + + if (item != null) + { + inputDetail.StdPackQty = item.StdPackQty; + } + + if (toLocation != null) + { + inputDetail.ToLocationCode = toLocation.Code; + + inputDetail.ToLocationErpCode = toLocation.ErpLocationCode; + } + + inputDetail.ExtraProperties = detail.ExtraProperties; + inputDetail.MesDeliveryNo = detail.MesDeliveryNo; + inputDetail.IdentityNo = detail.IdentityNo; + inputDetail.MesDeliveryPlan = detail.MesDeliveryPlan; + createInput.Details.Add(inputDetail); + } } + + createInputs.Add(createInput); } - return createInput; - } + return createInputs; + } private async Task BuildDeliverNoteAsync(DeliverRequest request) { var transactionType = await TransactionTypeAclService