|
|
@ -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<SfsHandledEntityEventData<DeliverRequest>> |
|
|
|
, ILocalEventHandler<SfsAbortedEntityEventData<DeliverRequest>> |
|
|
|
, ILocalEventHandler<SfsHandledEntityEventData<DeliverRequest>> |
|
|
|
, ILocalEventHandler<SfsAbortedEntityEventData<DeliverRequest>> |
|
|
|
, ILocalEventHandler<SfsCreatedEntityEventData<DeliverRequest>> |
|
|
|
, ILocalEventHandler<SfsCreatedEntityEventData<List<DeliverRequest>>> |
|
|
|
|
|
|
|
{ |
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 创建后
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="eventData">Event data</param>
|
|
|
|
[UnitOfWork] |
|
|
|
public async Task HandleEventAsync(SfsCreatedEntityEventData<DeliverRequest> eventData) |
|
|
|
{ |
|
|
|
var entity = eventData.Entity; |
|
|
|
if (entity.AutoSubmit) |
|
|
|
{ |
|
|
|
await _deliverRequestManager.SubmitAsync(entity).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 批量创建后
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="eventData">Event data</param>
|
|
|
|
[UnitOfWork] |
|
|
|
public async Task HandleEventAsync(SfsCreatedEntityEventData<List<DeliverRequest>> eventData) |
|
|
|
{ |
|
|
|
var entitys = eventData.Entity; |
|
|
|
foreach (var entity in entitys) |
|
|
|
{ |
|
|
|
if (entity.AutoSubmit) |
|
|
|
{ |
|
|
|
await _deliverRequestManager.SubmitAsync(entity).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 审批后
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="eventData"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[UnitOfWork] |
|
|
|
public virtual async Task HandleEventAsync(SfsAbortedEntityEventData<DeliverRequest> eventData) |
|
|
|
{ |
|
|
|
var entity = eventData.Entity; |
|
|
|
|
|
|
|
//东阳特殊逻辑
|
|
|
|
if (!entity.DirectCreateNote) |
|
|
|
{ |
|
|
|
await _deliverJobApp.CancelByDeliverRequestAsync(entity.Number).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 执行后
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="eventData"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[UnitOfWork] |
|
|
|
public virtual async Task HandleEventAsync(SfsHandledEntityEventData<DeliverRequest> eventData) |
|
|
|
{ |
|
|
@ -54,26 +110,32 @@ public class DeliverRequestEventHandler |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#region 私有
|
|
|
|
|
|
|
|
private async Task<DeliverNoteEditInput> 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<DeliverRequest, DeliverNoteEditInput>(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<string>() { detail.AreaCode }, |
|
|
|
Statuses = transactionType.OutInventoryStatuses |
|
|
|
}).ConfigureAwait(false); |
|
|
|
new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = detail.ItemCode, |
|
|
|
Qty = detail.Qty, |
|
|
|
LocationTypes = transactionType.OutLocationTypes, |
|
|
|
LocationAreas = new List<string> { 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<DeliverRequest, DeliverJobEditInput>(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<string>() { detail.AreaCode }, |
|
|
|
Statuses = transactionType.OutInventoryStatuses |
|
|
|
}).ConfigureAwait(false); |
|
|
|
new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = detail.ItemCode, |
|
|
|
Qty = detail.Qty, |
|
|
|
LocationTypes = transactionType.OutLocationTypes, |
|
|
|
LocationAreas = new List<string> { 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<DeliverJobEditInput>() { createInput }; |
|
|
|
return new List<DeliverJobEditInput> { createInput }; |
|
|
|
} |
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
|
public virtual async Task HandleEventAsync(SfsAbortedEntityEventData<DeliverRequest> eventData) |
|
|
|
{ |
|
|
|
var entity = eventData.Entity; |
|
|
|
|
|
|
|
//东阳特殊逻辑
|
|
|
|
if (!entity.DirectCreateNote) |
|
|
|
{ |
|
|
|
await _deliverJobApp.CancelByDeliverRequestAsync(entity.Number).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|