|
|
@ -8,6 +8,7 @@ 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.Event.Transaction; |
|
|
|
|
|
|
|
namespace Win_in.Sfs.Wms.Store.Event.Transactions; |
|
|
@ -17,78 +18,83 @@ public class CustomerProductionReturnNoteEventHandler |
|
|
|
, ILocalEventHandler<SfsCreatedEntityEventData<CustomerProductionReturnNote>> |
|
|
|
, ILocalEventHandler<SfsCreatedEntityEventData<List<CustomerProductionReturnNote>>> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
private const EnumTransType TransType = EnumTransType.CustomerReturn; |
|
|
|
|
|
|
|
private readonly IProductionReturnRequestAppService _productionReturnRequestApp; |
|
|
|
|
|
|
|
public CustomerProductionReturnNoteEventHandler(IProductionReturnRequestAppService productionReturnRequestApp) |
|
|
|
{ |
|
|
|
this._productionReturnRequestApp = productionReturnRequestApp; |
|
|
|
} |
|
|
|
private const EnumTransInOut TransInOut = EnumTransInOut.In; |
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
|
public virtual async Task HandleEventAsync(SfsCreatedEntityEventData<CustomerProductionReturnNote> eventData) |
|
|
|
{ |
|
|
|
var entity = eventData.Entity; |
|
|
|
await AddTransactionsAsync(entity).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(entity.ProductionReturnRequestNumber)) |
|
|
|
{ |
|
|
|
await _productionReturnRequestApp.CompleteByNumberAsync(entity.ProductionReturnRequestNumber).ConfigureAwait(false); |
|
|
|
} |
|
|
|
await AddTransactionsAsync(entity).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task AddTransactionsAsync(CustomerProductionReturnNote CustomerProductionReturnNote) |
|
|
|
{ |
|
|
|
var inboundTransactions = new List<TransferLogEditInput>(); |
|
|
|
////如果WMS管理客户寄售库,生成库存转移
|
|
|
|
//if (await SettingManager.IsTrueAsync(StoreSettings.Common.EnableCustomerLocation).ConfigureAwait(false))
|
|
|
|
//{
|
|
|
|
|
|
|
|
inboundTransactions.AddRange(BuildTransferLogs(CustomerProductionReturnNote)); |
|
|
|
// var transferLogs = BuildTransferLogs(CustomerProductionReturnNote);
|
|
|
|
// await TransferLogAppService.AddManyAsync(transferLogs).ConfigureAwait(false);
|
|
|
|
|
|
|
|
await TransferLogAppService.AddManyAsync(inboundTransactions).ConfigureAwait(false); |
|
|
|
//}
|
|
|
|
//else //如果WMS不管理客户寄售库,生成入库
|
|
|
|
//{
|
|
|
|
|
|
|
|
} |
|
|
|
var transactions = BuildTransactions(CustomerProductionReturnNote); |
|
|
|
await TransactionAppService.AddManyAsync(transactions).ConfigureAwait(false); |
|
|
|
//}
|
|
|
|
|
|
|
|
[UnitOfWork] |
|
|
|
public virtual async Task HandleEventAsync(SfsCreatedEntityEventData<List<CustomerProductionReturnNote>> eventData) |
|
|
|
{ |
|
|
|
var entities = eventData.Entity; |
|
|
|
await AddTransactionsAsync(entities).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task AddTransactionsAsync(List<CustomerProductionReturnNote> CustomerProductionReturnNotes) |
|
|
|
/// <summary>
|
|
|
|
/// 构造 库存转移日志实体
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="CustomerProductionReturnNote"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private List<TransferLogEditInput> BuildTransferLogs(CustomerProductionReturnNote CustomerProductionReturnNote) |
|
|
|
{ |
|
|
|
var inboundTransactions = new List<TransferLogEditInput>(); |
|
|
|
var transferLogCreateInputs = new List<TransferLogEditInput>(); |
|
|
|
|
|
|
|
//如果要做库存事务汇总,可以修改此处
|
|
|
|
foreach (var CustomerProductionReturnNote in CustomerProductionReturnNotes) |
|
|
|
foreach (var detail in CustomerProductionReturnNote.Details.Where(detail => detail.Qty != 0)) |
|
|
|
{ |
|
|
|
inboundTransactions.AddRange(BuildTransferLogs(CustomerProductionReturnNote)); |
|
|
|
var transferLog = ObjectMapper.Map<CustomerProductionReturnNoteDetail, TransferLogEditInput>(detail); |
|
|
|
transferLog.TransType = TransType; |
|
|
|
transferLog.Worker = CustomerProductionReturnNote.Worker; |
|
|
|
transferLog.DocNumber = CustomerProductionReturnNote.Number; |
|
|
|
transferLog.JobNumber = CustomerProductionReturnNote.JobNumber; |
|
|
|
transferLogCreateInputs.Add(transferLog); |
|
|
|
} |
|
|
|
|
|
|
|
await TransferLogAppService.AddManyAsync(inboundTransactions).ConfigureAwait(false); |
|
|
|
return transferLogCreateInputs; |
|
|
|
} |
|
|
|
|
|
|
|
private List<TransferLogEditInput> BuildTransferLogs(CustomerProductionReturnNote CustomerProductionReturnNote) |
|
|
|
private List<TransactionEditInput> BuildTransactions(CustomerProductionReturnNote CustomerProductionReturnNote) |
|
|
|
{ |
|
|
|
var transferLogs = new List<TransferLogEditInput>(); |
|
|
|
foreach (var detail in CustomerProductionReturnNote.Details.Where(detail => detail.Qty != 0)) |
|
|
|
var transactions = new List<TransactionEditInput>(); |
|
|
|
|
|
|
|
foreach (var detail in CustomerProductionReturnNote.Details) |
|
|
|
{ |
|
|
|
var transferLog = ObjectMapper.Map<CustomerProductionReturnNoteDetail, TransferLogEditInput>(detail); |
|
|
|
var transaction = ObjectMapper.Map<CustomerProductionReturnNoteDetail, TransactionEditInput>(detail); |
|
|
|
|
|
|
|
transferLog.TransType = TransType; |
|
|
|
transaction.TransType = TransType; |
|
|
|
transaction.TransInOut = TransInOut; |
|
|
|
|
|
|
|
transferLog.Worker = CustomerProductionReturnNote.Worker; |
|
|
|
transferLog.DocNumber = CustomerProductionReturnNote.Number; |
|
|
|
transferLog.JobNumber = CustomerProductionReturnNote.JobNumber; |
|
|
|
transaction.Worker = CustomerProductionReturnNote.Worker; |
|
|
|
transaction.DocNumber = CustomerProductionReturnNote.Number; |
|
|
|
transaction.JobNumber = CustomerProductionReturnNote.JobNumber; |
|
|
|
transaction.Status = EnumInventoryStatus.OK; |
|
|
|
|
|
|
|
transferLogs.Add(transferLog); |
|
|
|
transactions.Add(transaction); |
|
|
|
} |
|
|
|
|
|
|
|
return transferLogs; |
|
|
|
return transactions; |
|
|
|
} |
|
|
|
|
|
|
|
public Task HandleEventAsync(SfsCreatedEntityEventData<List<CustomerProductionReturnNote>> eventData) |
|
|
|
{ |
|
|
|
throw new System.NotImplementedException(); |
|
|
|
} |
|
|
|
} |
|
|
|