8 changed files with 539 additions and 3 deletions
@ -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<SfsCompletedEntityEventData<CoatingIssueJob>> |
||||
|
{ |
||||
|
private const EnumTransType TransType = EnumTransType.Issue; |
||||
|
|
||||
|
private readonly ICoatingIssueNoteAppService _issueNoteAppService; |
||||
|
private readonly ILocationAppService _locationAppService; |
||||
|
|
||||
|
public CoatingIssueJobEventHandler(ICoatingIssueNoteAppService issueNoteAppService, ILocationAppService locationAppService) |
||||
|
{ |
||||
|
_issueNoteAppService = issueNoteAppService; |
||||
|
_locationAppService = locationAppService; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 执行后
|
||||
|
/// </summary>
|
||||
|
/// <param name="eventData"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[UnitOfWork] |
||||
|
public virtual async Task HandleEventAsync(SfsCompletedEntityEventData<CoatingIssueJob> eventData) |
||||
|
{ |
||||
|
var entity = eventData.Entity; |
||||
|
var issueNote = await BuildIssueNoteAsync(entity).ConfigureAwait(false); |
||||
|
await _issueNoteAppService.CreateAsync(issueNote).ConfigureAwait(false); |
||||
|
} |
||||
|
|
||||
|
#region 私有
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 创建补料记录实体
|
||||
|
/// </summary>
|
||||
|
/// <param name="entity"></param>
|
||||
|
/// <returns></returns>
|
||||
|
private async Task<CoatingIssueNoteEditInput> BuildIssueNoteAsync(CoatingIssueJob entity) |
||||
|
{ |
||||
|
var issueNoteCreateInput = ObjectMapper.Map<CoatingIssueJob, CoatingIssueNoteEditInput>(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; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 去除箱码 托码 批次
|
||||
|
/// </summary>
|
||||
|
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
|
||||
|
} |
@ -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<SfsHandledEntityEventData<CoatingMaterialRequest>> |
||||
|
, ILocalEventHandler<SfsAbortedEntityEventData<CoatingMaterialRequest>> |
||||
|
, ILocalEventHandler<SfsCompletedEntityEventData<CoatingMaterialRequest>> |
||||
|
, ILocalEventHandler<SfsCreatedEntityEventData<CoatingMaterialRequest>> |
||||
|
, ILocalEventHandler<SfsCreatedEntityEventData<List<CoatingMaterialRequest>>> |
||||
|
{ |
||||
|
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; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 创建后
|
||||
|
/// </summary>
|
||||
|
/// <param name="eventData">Event data</param>
|
||||
|
public virtual async Task HandleEventAsync(SfsCreatedEntityEventData<CoatingMaterialRequest> eventData) |
||||
|
{ |
||||
|
var entity = eventData.Entity; |
||||
|
|
||||
|
//if (entity.AutoSubmit)
|
||||
|
//{
|
||||
|
// await _CoatingMaterialRequestManager.SubmitAsync(entity).ConfigureAwait(false);
|
||||
|
//}
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 批量创建后
|
||||
|
/// </summary>
|
||||
|
/// <param name="eventData">Event data</param>
|
||||
|
public virtual async Task HandleEventAsync(SfsCreatedEntityEventData<List<CoatingMaterialRequest>> 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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 执行后
|
||||
|
/// </summary>
|
||||
|
/// <param name="eventData"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public virtual async Task HandleEventAsync(SfsHandledEntityEventData<CoatingMaterialRequest> eventData) |
||||
|
{ |
||||
|
var entity = eventData.Entity; |
||||
|
var issueJobs = await BuildIssueJobAsync(entity).ConfigureAwait(false); |
||||
|
if (issueJobs.Any()) |
||||
|
{ |
||||
|
await _issueJobAppService.CreateManyAsync(issueJobs).ConfigureAwait(false); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 驳回后
|
||||
|
/// </summary>
|
||||
|
/// <param name="eventData"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public virtual async Task HandleEventAsync(SfsAbortedEntityEventData<CoatingMaterialRequest> eventData) |
||||
|
{ |
||||
|
var entity = eventData.Entity; |
||||
|
await _issueJobAppService.CancelByMaterialRequestAsync(entity.Number).ConfigureAwait(false); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 完成后
|
||||
|
/// </summary>
|
||||
|
/// <param name="eventData"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public virtual async Task HandleEventAsync(SfsCompletedEntityEventData<CoatingMaterialRequest> eventData) |
||||
|
{ |
||||
|
_ = eventData.Entity; |
||||
|
// await _issueJobAppService.CompleteByCoatingMaterialRequestAsync(entity.Number);
|
||||
|
|
||||
|
await Task.CompletedTask.ConfigureAwait(false); |
||||
|
} |
||||
|
|
||||
|
#region 私有
|
||||
|
|
||||
|
private async Task<List<CoatingIssueJobEditInput>> BuildIssueJobAsync |
||||
|
(CoatingMaterialRequest CoatingMaterialRequest) |
||||
|
{ |
||||
|
var jobs = new List<CoatingIssueJobEditInput>(); |
||||
|
|
||||
|
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,CoatingIssueJobEditInput>(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<List<CoatingIssueJobDetailInput>> BuildIssueJobDetailInputsAsync(CoatingMaterialRequest CoatingMaterialRequest, |
||||
|
CoatingMaterialRequestDetail CoatingMaterialRequestDetail, TransactionTypeDTO transactionType, string toLocationGroupCode) |
||||
|
{ |
||||
|
var jobDetails = new List<CoatingIssueJobDetailInput>(); |
||||
|
var input = new RecommendBalanceRequestInput() |
||||
|
{ |
||||
|
ItemCode = CoatingMaterialRequestDetail.ItemCode, |
||||
|
Qty = CoatingMaterialRequestDetail.ToBeIssuedQty, |
||||
|
LocationTypes = transactionType.OutLocationTypes, |
||||
|
LocationAreas = new List<string> { 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<CoatingIssueJobDetailInput> BuildIssueJobDetailAsync(CoatingMaterialRequestDetail CoatingMaterialRequestDetail, BalanceDTO balance, string toLocationGroupCode) |
||||
|
{ |
||||
|
ProductionLineDTO prodLine = await _productionLineAppService.GetByLocationGroupCodeAsync(toLocationGroupCode).ConfigureAwait(false); |
||||
|
|
||||
|
var detail = ObjectMapper.Map<BalanceDTO, CoatingIssueJobDetailInput>(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, IssueJobDetailInput>(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
|
||||
|
} |
@ -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<SfsCreatedEntityEventData<CoatingIssueNote>> |
||||
|
, ILocalEventHandler<SfsCreatedEntityEventData<List<CoatingIssueNote>>> |
||||
|
, ILocalEventHandler<SfsConfirmedEntityEventData<CoatingIssueNote>> |
||||
|
{ |
||||
|
private readonly ICoatingMaterialRequestManager _materialRequestManager; |
||||
|
|
||||
|
public CoatingIssueNoteEventHandler( |
||||
|
ICoatingMaterialRequestManager materialRequestManager |
||||
|
) |
||||
|
{ |
||||
|
_materialRequestManager = materialRequestManager; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 当叫料记录创建后 修改请求的值
|
||||
|
/// </summary>
|
||||
|
/// <param name="eventData"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[UnitOfWork] |
||||
|
public virtual async Task HandleEventAsync(SfsConfirmedEntityEventData<CoatingIssueNote> eventData) |
||||
|
{ |
||||
|
var entity = eventData.Entity; |
||||
|
|
||||
|
await UpdateReceivedQtyMaterialRequestAsync(entity).ConfigureAwait(false); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 当叫料记录创建后 修改请求的值
|
||||
|
/// </summary>
|
||||
|
/// <param name="eventData"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[UnitOfWork] |
||||
|
public virtual async Task HandleEventAsync(SfsCreatedEntityEventData<CoatingIssueNote> eventData) |
||||
|
{ |
||||
|
var entity = eventData.Entity; |
||||
|
if (!entity.UseOnTheWayLocation) |
||||
|
{ |
||||
|
await UpdateReceivedQtyMaterialRequestAsync(entity).ConfigureAwait(false); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 当叫料记录创建后 修改请求的值
|
||||
|
/// </summary>
|
||||
|
/// <param name="eventData"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[UnitOfWork] |
||||
|
public virtual async Task HandleEventAsync(SfsCreatedEntityEventData<List<CoatingIssueNote>> 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); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue