diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/Jobs/IssueJobs/CoatingIssueJobDbContextModelCreatingExtensions.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/Jobs/IssueJobs/CoatingIssueJob/CoatingIssueJobDbContextModelCreatingExtensions.cs similarity index 100% rename from be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/Jobs/IssueJobs/CoatingIssueJobDbContextModelCreatingExtensions.cs rename to be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/Jobs/IssueJobs/CoatingIssueJob/CoatingIssueJobDbContextModelCreatingExtensions.cs diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/Jobs/IssueJobs/CoatingIssueJobEfCoreRepository.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/Jobs/IssueJobs/CoatingIssueJob/CoatingIssueJobEfCoreRepository.cs similarity index 100% rename from be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/Jobs/IssueJobs/CoatingIssueJobEfCoreRepository.cs rename to be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/Jobs/IssueJobs/CoatingIssueJob/CoatingIssueJobEfCoreRepository.cs diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/StoreDbContextModelCreatingExtensions.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/StoreDbContextModelCreatingExtensions.cs index a69e04391..b9229727a 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/StoreDbContextModelCreatingExtensions.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/StoreDbContextModelCreatingExtensions.cs @@ -24,13 +24,11 @@ public static class StoreDbContextModelCreatingExtensions optionsAction?.Invoke(options); #region Orders - builder.ConfigurePurchaseOrder(options); builder.ConfigureSaleOrder(options); builder.ConfigureWorkOrder(options); builder.ConfigureEquipmentRecord(options); //builder.ConfigureEquipmentLocCap(options); - #endregion #region Plans diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/Win_in.Sfs.Wms.Store.EntityFrameworkCore.csproj b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/Win_in.Sfs.Wms.Store.EntityFrameworkCore.csproj index b0aebac8d..7f8204f22 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/Win_in.Sfs.Wms.Store.EntityFrameworkCore.csproj +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/Win_in.Sfs.Wms.Store.EntityFrameworkCore.csproj @@ -1,4 +1,4 @@ - + diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Jobs/CoatingIssueJobEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Jobs/CoatingIssueJobEventHandler.cs new file mode 100644 index 000000000..8a82f504c --- /dev/null +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Jobs/CoatingIssueJobEventHandler.cs @@ -0,0 +1,132 @@ +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.Basedata.Application.Contracts; +using Win_in.Sfs.Shared.Domain.Shared; +using Win_in.Sfs.Shared.Event; +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.Jobs.IssueJobs; +using Win_in.Sfs.Wms.Store.Notes.IssueNotes; + +namespace Win_in.Sfs.Wms.Store.Event.BusinessJob; + +public class CoatingIssueJobEventHandler : + StoreEventHandlerBase + , ILocalEventHandler> +{ + private const EnumTransType TransType = EnumTransType.Issue; + + private readonly ICoatingIssueNoteAppService _issueNoteAppService; + private readonly ILocationAppService _locationAppService; + + public CoatingIssueJobEventHandler(ICoatingIssueNoteAppService issueNoteAppService, ILocationAppService locationAppService) + { + _issueNoteAppService = issueNoteAppService; + _locationAppService = locationAppService; + } + + /// + /// 执行后 + /// + /// + /// + [UnitOfWork] + public virtual async Task HandleEventAsync(SfsCompletedEntityEventData eventData) + { + var entity = eventData.Entity; + var issueNote = await BuildIssueNoteAsync(entity).ConfigureAwait(false); + await _issueNoteAppService.CreateAsync(issueNote).ConfigureAwait(false); + } + + #region 私有 + + /// + /// 创建补料记录实体 + /// + /// + /// + private async Task BuildIssueNoteAsync(CoatingIssueJob entity) + { + var issueNoteCreateInput = ObjectMapper.Map(entity); + issueNoteCreateInput.JobNumber = entity.Number; + var locationCodes = issueNoteCreateInput.Details.Select(p => p.ToLocationCode).Distinct().ToList(); + var locations = await _locationAppService.GetByCodesAsync(locationCodes).ConfigureAwait(false); + + issueNoteCreateInput.Details.RemoveAll(p => p.Qty == 0); + + foreach (var detail in issueNoteCreateInput.Details) + { + var location = locations.First(p => p.Code == detail.ToLocationCode); + await RemovePackingCodeAndContainerCodeAndLotAsync(detail, location.Type).ConfigureAwait(false); //去箱 去托 去批 + + detail.ToLocationArea = location.AreaCode; + detail.ToLocationGroup = location.LocationGroupCode; + detail.ToLocationErpCode = location.ErpLocationCode; + detail.ToWarehouseCode = location.WarehouseCode; + } + + return issueNoteCreateInput; + } + + /// + /// 去除箱码 托码 批次 + /// + private async Task RemovePackingCodeAndContainerCodeAndLotAsync(CoatingIssueNoteDetailInput issueNoteDetail, + EnumLocationType locationType) + { + switch (locationType) + { + case EnumLocationType.WIP: + { + //用开关控制 发料到线边后去除箱码和托码 ??? + if (await SettingManager.IsTrueAsync(StoreSettings.Issue.ToWip.IsRemovePackingCode) + .ConfigureAwait(false)) + { + issueNoteDetail.ToPackingCode = ""; + } + + if (await SettingManager.IsTrueAsync(StoreSettings.Issue.ToWip.IsRemoveContainerCode) + .ConfigureAwait(false)) + { + issueNoteDetail.ToContainerCode = ""; + } + + if (await SettingManager.IsTrueAsync(StoreSettings.Issue.ToWip.IsRemoveLot).ConfigureAwait(false)) + { + issueNoteDetail.ToLot = ""; + } + + break; + } + case EnumLocationType.SEMI: + { + //用开关控制 发料到后去除箱码和托码 ??? + if (await SettingManager.IsTrueAsync(StoreSettings.Issue.ToSemi.IsRemovePackingCode) + .ConfigureAwait(false)) + { + issueNoteDetail.ToPackingCode = ""; + } + + if (await SettingManager.IsTrueAsync(StoreSettings.Issue.ToSemi.IsRemoveContainerCode) + .ConfigureAwait(false)) + { + issueNoteDetail.ToContainerCode = ""; + } + + if (await SettingManager.IsTrueAsync(StoreSettings.Issue.ToSemi.IsRemoveLot).ConfigureAwait(false)) + { + issueNoteDetail.ToLot = ""; + } + + break; + } + } + } + + #endregion +} diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/CoatingIssueJobEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/CoatingIssueJobEventHandler.cs new file mode 100644 index 000000000..e69de29bb diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/CoatingMaterialRequestEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/CoatingMaterialRequestEventHandler.cs new file mode 100644 index 000000000..3e811e586 --- /dev/null +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/CoatingMaterialRequestEventHandler.cs @@ -0,0 +1,306 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FluentValidation.Validators; +using Volo.Abp; +using Volo.Abp.EventBus; +using Volo.Abp.SettingManagement; +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; +using Win_in.Sfs.Wms.Store.Domain.Shared; +using Win_in.Sfs.Wms.Store.Jobs.IssueJobs; +using Win_in.Sfs.Wms.Store.Requests.MaterialRequests; + +namespace Win_in.Sfs.Wms.Store.Event.BusinessRequest; + +public class CoatingMaterialRequestEventHandler + : StoreEventHandlerBase + , ILocalEventHandler> + , ILocalEventHandler> + , ILocalEventHandler> + , ILocalEventHandler> + , ILocalEventHandler>> +{ + private readonly ICoatingIssueJobAppService _issueJobAppService; + private readonly IProductionLineAppService _productionLineAppService; + private readonly ICoatingMaterialRequestManager _CoatingMaterialRequestManager; + private readonly ILocationAppService _locationAppService; + private readonly IBalanceAppService _balanceAppService; + + public CoatingMaterialRequestEventHandler( + ICoatingIssueJobAppService issueJobAppService + , IProductionLineAppService productionLineAppService + , ICoatingMaterialRequestManager CoatingMaterialRequestManager + , ILocationAppService locationAppService + , IBalanceAppService balanceAppService) + { + _issueJobAppService = issueJobAppService; + _productionLineAppService = productionLineAppService; + _CoatingMaterialRequestManager = CoatingMaterialRequestManager; + _locationAppService = locationAppService; + _balanceAppService = balanceAppService; + } + + /// + /// 创建后 + /// + /// Event data + public virtual async Task HandleEventAsync(SfsCreatedEntityEventData eventData) + { + var entity = eventData.Entity; + + //if (entity.AutoSubmit) + //{ + // await _CoatingMaterialRequestManager.SubmitAsync(entity).ConfigureAwait(false); + //} + } + + /// + /// 批量创建后 + /// + /// Event data + public virtual async Task HandleEventAsync(SfsCreatedEntityEventData> eventData) + { + var entitys = eventData.Entity; + foreach (var entity in entitys) + { + if (entity.AutoSubmit) + { + await _CoatingMaterialRequestManager.SubmitAsync(entity).ConfigureAwait(false); + } + if (entity.Type == EnumMaterialRequestType.Issue_WIP.ToString()) + { + await _CoatingMaterialRequestManager.SubmitAsync(entity).ConfigureAwait(false); + } + } + } + + /// + /// 执行后 + /// + /// + /// + public virtual async Task HandleEventAsync(SfsHandledEntityEventData eventData) + { + var entity = eventData.Entity; + var issueJobs = await BuildIssueJobAsync(entity).ConfigureAwait(false); + if (issueJobs.Any()) + { + await _issueJobAppService.CreateManyAsync(issueJobs).ConfigureAwait(false); + } + } + + /// + /// 驳回后 + /// + /// + /// + public virtual async Task HandleEventAsync(SfsAbortedEntityEventData eventData) + { + var entity = eventData.Entity; + await _issueJobAppService.CancelByMaterialRequestAsync(entity.Number).ConfigureAwait(false); + } + + /// + /// 完成后 + /// + /// + /// + public virtual async Task HandleEventAsync(SfsCompletedEntityEventData eventData) + { + _ = eventData.Entity; + // await _issueJobAppService.CompleteByCoatingMaterialRequestAsync(entity.Number); + + await Task.CompletedTask.ConfigureAwait(false); + } + + #region 私有 + + private async Task> BuildIssueJobAsync + (CoatingMaterialRequest CoatingMaterialRequest) + { + var jobs = new List(); + + var transactionType = await TransactionTypeAclService.GetByTransTypeAsync(EnumTransType.Issue, EnumTransSubType.None).ConfigureAwait(false);//库存事务 + + var toLocationCodes = CoatingMaterialRequest.Details.Select(p => p.ToLocationCode).Distinct().ToList();//所有发送库位的集合 + var toLocations = await _locationAppService.GetByCodesAsync(toLocationCodes).ConfigureAwait(false);//所有库位的集合 + + var CoatingMaterialRequestDetails = CoatingMaterialRequest.Details.Where(p => p.ToBeIssuedQty > 0);//所有还没发送物品的集合 + foreach (var CoatingMaterialRequestDetail in CoatingMaterialRequestDetails)//如果有还有剩余未叫料的数量 则创建新的任务 + { + var toLocation = toLocations.FirstOrDefault(p => p.Code == CoatingMaterialRequestDetail.ToLocationCode);//判断目标库位是否存在 + Check.NotNull(toLocation, "库位代码", $"库位 {CoatingMaterialRequestDetail.ToLocationCode} 不存在"); + + //创建详情 + var jobDetails = await BuildIssueJobDetailInputsAsync(CoatingMaterialRequest, CoatingMaterialRequestDetail, transactionType, toLocation.LocationGroupCode).ConfigureAwait(false); + if (!jobDetails.Any()) + { + continue; + } + + var fromLocationCode = jobDetails[0].RecommendFromLocationCode; + var fromLocation = await _locationAppService.GetByCodeAsync(fromLocationCode).ConfigureAwait(false); + var job = jobs.FirstOrDefault(p => p.WorkGroupCode == fromLocation?.WorkGroupCode); + if (job == null || job.Details.Any(p => p.ToLocationCode != CoatingMaterialRequestDetail.ToLocationCode)) + { + job = BuildIssueJobCreateInput(CoatingMaterialRequest, fromLocation); + jobs.Add(job); + } + job.Details.AddRange(jobDetails); + if (CoatingMaterialRequestDetail.ToBeIssuedQty < 0) + { + CoatingMaterialRequestDetail.Status = EnumStatus.Close; + } + } + + jobs = jobs.Where(p => p.Details.Any()).ToList(); + + var openRequestDetails = + CoatingMaterialRequest.Details.Where(p => p.Status != EnumStatus.Close).ToList(); + + if (!openRequestDetails.Any()) + { + return jobs; + } + + var enableMultipleCreateIssueJob = await SettingManager.IsTrueAsync(StoreSettings.MaterialRequest.EnableMultipleCreateIssueJob).ConfigureAwait(false); + if (enableMultipleCreateIssueJob) + { + CoatingMaterialRequest.Partial(); + } + else + { + var sb = new StringBuilder(); + foreach (var openRequestDetail in openRequestDetails) + { + sb.AppendLine($"{openRequestDetail.ItemCode}请求数量 {openRequestDetail.Qty},可用库存数量 {openRequestDetail.IssuedQty}"); + } + throw new UserFriendlyException($"{sb} 可用库存数量不足, 无法生成发料任务"); + } + return jobs; + } + + private CoatingIssueJobEditInput BuildIssueJobCreateInput(CoatingMaterialRequest CoatingMaterialRequest, LocationDTO fromLocation) + { + CoatingIssueJobEditInput job; + job = ObjectMapper.Map(CoatingMaterialRequest); + job.JobType = EnumJobType.IssueJob; + job.JobStatus = EnumJobStatus.Open; + job.WorkGroupCode = fromLocation.WorkGroupCode; + job.WarehouseCode = fromLocation.WarehouseCode; + job.ProdLine = fromLocation.LocationGroupCode; + job.Worker = CoatingMaterialRequest.Worker; + job.MaterialRequestNumber = CoatingMaterialRequest.Number; + return job; + } + + private async Task> BuildIssueJobDetailInputsAsync(CoatingMaterialRequest CoatingMaterialRequest, + CoatingMaterialRequestDetail CoatingMaterialRequestDetail, TransactionTypeDTO transactionType, string toLocationGroupCode) + { + var jobDetails = new List(); + var input = new RecommendBalanceRequestInput() + { + ItemCode = CoatingMaterialRequestDetail.ItemCode, + Qty = CoatingMaterialRequestDetail.ToBeIssuedQty, + LocationTypes = transactionType.OutLocationTypes, + LocationAreas = new List { CoatingMaterialRequestDetail.FromLocationArea }, + Statuses = transactionType.OutInventoryStatuses, + }; + //获取推荐库存 + var recommendList = await _balanceAppService.GetRecommendBalancesAsync(input).ConfigureAwait(false); + //没有推荐库存时 跳过此明细 不生成任务 + if (recommendList.Count != 0) + { + foreach (var recommend in recommendList) + { + //拿走需求量 + var detail = await BuildIssueJobDetailAsync(CoatingMaterialRequestDetail, recommend, toLocationGroupCode).ConfigureAwait(false); + if (CoatingMaterialRequest.UseOnTheWayLocation) + { + //获取在途库 + var locationDto = await _locationAppService.GetFirstByTypeAsync(EnumLocationType.TRANSPORT).ConfigureAwait(false); + + detail.OnTheWayLocationCode = locationDto.Code; + } + + jobDetails.Add(detail); + CoatingMaterialRequestDetail.IssuedQty += recommend.Qty; + await _CoatingMaterialRequestManager.UpdateDetailsAsync(CoatingMaterialRequest).ConfigureAwait(false); + + } + } + return jobDetails; + } + + private async Task BuildIssueJobDetailAsync(CoatingMaterialRequestDetail CoatingMaterialRequestDetail, BalanceDTO balance, string toLocationGroupCode) + { + ProductionLineDTO prodLine = await _productionLineAppService.GetByLocationGroupCodeAsync(toLocationGroupCode).ConfigureAwait(false); + + var detail = ObjectMapper.Map(balance); + detail.RequestLocationCode = CoatingMaterialRequestDetail.ToLocationCode; + detail.WorkStation = CoatingMaterialRequestDetail.WorkStation; + detail.ExpiredTime = CoatingMaterialRequestDetail.ExpiredTime; + detail.PositionCode = CoatingMaterialRequestDetail.PositionCode; + detail.RecommendType = CoatingMaterialRequestDetail.RecommendType; + + detail.RecommendPackingCode = balance.PackingCode; + detail.RecommendContainerCode = balance.ContainerCode; + detail.RecommendSupplierBatch = balance.SupplierBatch; + detail.RecommendProduceDate = balance.ProduceDate; + detail.RecommendExpireDate = balance.ExpireDate; + detail.RecommendLot = balance.Lot; + detail.RecommendProduceDate = balance.ProduceDate; + detail.RecommendArriveDate = balance.ArriveDate; + detail.RecommendFromLocationArea = balance.LocationArea; + detail.RecommendFromLocationCode = balance.LocationCode; + detail.RecommendFromLocationErpCode = balance.LocationErpCode; + detail.RecommendFromLocationGroup = balance.LocationGroup; + detail.RecommendFromWarehouseCode = balance.WarehouseCode; + detail.RecommendQty = balance.Qty; + detail.Uom = balance.Uom; + + detail.ToLocationCode = CoatingMaterialRequestDetail.ToLocationCode; + detail.ToLocationErpCode = CoatingMaterialRequestDetail.ToLocationErpCode; + detail.ToLocationArea = CoatingMaterialRequestDetail.ToLocationArea; + detail.ToWarehouseCode = CoatingMaterialRequestDetail.ToWarehouseCode; + detail.ToLocationGroup = CoatingMaterialRequestDetail.ToLocationGroup; + //detail.Operation = //TODO + //detail.DistributionType =//TODO + //detail.TruncType = //TODO + //detail.RoundedQty =//TODO + //detail.PlannedSplitRule = //TODO + //detail.PlanBeginTime = //TODO + //detaiol.DeliveryQty = //TODO + + // var detail = ObjectMapper.Map(CoatingMaterialRequestDetail); + // + // detail.RecommendPackingCode = balance.PackingCode; + // detail.RecommendContainerCode = balance.ContainerCode; + // detail.RecommendLot = balance.Lot; + // detail.RecommendLocationCode = balance.LocationCode; + // detail.RecommendLocationArea = balance.LocationArea; + // detail.RecommendLocationGroup = balance.LocationGroup; + // detail.RecommendLocationErpCode = balance.LocationErpCode; + // detail.WarehouseCode = balance.WarehouseCode; + // detail.Status = balance.Status; + // detail.RecommendSupplierBatch = balance.SupplierBatch; + // detail.RecommendArriveDate = balance.ArriveDate; + // detail.RecommendProduceDate = balance.ProduceDate; + // detail.RecommendExpireDate = balance.ExpireDate; + // detail.RecommendQty = balance.Qty; + // detail.RecommendUom = balance.Uom; + + detail.ProdLine = prodLine == null ? toLocationGroupCode : prodLine.Code; + await Task.CompletedTask.ConfigureAwait(false); + return detail; + + } + + #endregion +} diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/Note/CoatingIssueNoteEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/Note/CoatingIssueNoteEventHandler.cs new file mode 100644 index 000000000..f41206079 --- /dev/null +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/Note/CoatingIssueNoteEventHandler.cs @@ -0,0 +1,100 @@ +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; +using Win_in.Sfs.Wms.Store.Notes.IssueNotes; +using Win_in.Sfs.Wms.Store.Requests.MaterialRequests; +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; + +public class CoatingIssueNoteEventHandler + : StoreEventHandlerBase + , ILocalEventHandler> + , ILocalEventHandler>> + , ILocalEventHandler> +{ + private readonly ICoatingMaterialRequestManager _materialRequestManager; + + public CoatingIssueNoteEventHandler( + ICoatingMaterialRequestManager materialRequestManager + ) + { + _materialRequestManager = materialRequestManager; + } + + /// + /// 当叫料记录创建后 修改请求的值 + /// + /// + /// + [UnitOfWork] + public virtual async Task HandleEventAsync(SfsConfirmedEntityEventData eventData) + { + var entity = eventData.Entity; + + await UpdateReceivedQtyMaterialRequestAsync(entity).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); + } + } + + private async Task UpdateReceivedQtyMaterialRequestAsync(CoatingIssueNote 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); + } + } +}