|
|
@ -31,10 +31,11 @@ public class DeliverRequestEventHandler |
|
|
|
private readonly IDeliverRequestManager _deliverRequestManager; |
|
|
|
private readonly IBalanceAppService _balanceAppService; |
|
|
|
private readonly ILocationAppService _locationAppService; |
|
|
|
private readonly IProductionLineItemAppService _productionLineItemAppService; |
|
|
|
public DeliverRequestEventHandler( |
|
|
|
IDeliverJobAppService deliverJobApp |
|
|
|
, IDeliverNoteAppService deliverNoteApp |
|
|
|
, ICustomerAddressAppService customerAddressApp, IDeliverRequestManager deliverRequestManager, IBalanceAppService balanceAppService, ILocationAppService locationAppService) |
|
|
|
, ICustomerAddressAppService customerAddressApp, IDeliverRequestManager deliverRequestManager, IBalanceAppService balanceAppService, ILocationAppService locationAppService, IProductionLineItemAppService productionLineItemAppService) |
|
|
|
{ |
|
|
|
_deliverNoteApp = deliverNoteApp; |
|
|
|
_deliverJobApp = deliverJobApp; |
|
|
@ -42,6 +43,7 @@ public class DeliverRequestEventHandler |
|
|
|
_deliverRequestManager = deliverRequestManager; |
|
|
|
_balanceAppService = balanceAppService; |
|
|
|
_locationAppService = locationAppService; |
|
|
|
_productionLineItemAppService = productionLineItemAppService; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -98,11 +100,11 @@ public class DeliverRequestEventHandler |
|
|
|
var noteCreateInput = await BuildDeliverNoteAsync(entity).ConfigureAwait(false); |
|
|
|
await _deliverNoteApp.CreateAsync(noteCreateInput).ConfigureAwait(false); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var deliverJobCreateInputs = await BuildDeliverJobsAsync(entity).ConfigureAwait(false); |
|
|
|
await _deliverJobApp.CreateManyAsync(deliverJobCreateInputs).ConfigureAwait(false); |
|
|
|
} |
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// var deliverJobCreateInputs = await BuildDeliverJobsAsync(entity).ConfigureAwait(false);
|
|
|
|
// await _deliverJobApp.CreateManyAsync(deliverJobCreateInputs).ConfigureAwait(false);
|
|
|
|
//}
|
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 执行后
|
|
|
@ -156,7 +158,7 @@ public class DeliverRequestEventHandler |
|
|
|
} |
|
|
|
|
|
|
|
createInput.Details = new List<DeliverNoteDetailInput>(); |
|
|
|
|
|
|
|
List<BalanceDTO> oldBalances = new List<BalanceDTO>(); |
|
|
|
foreach (var detail in requests.SelectMany(r=>r.Details)) |
|
|
|
{ |
|
|
|
var locations = await _locationAppService.GetListByTypesAndErpCodeAsync(transactionType.OutLocationTypes, detail.AreaCode).ConfigureAwait(false); |
|
|
@ -165,13 +167,14 @@ public class DeliverRequestEventHandler |
|
|
|
throw new UserFriendlyException($"储位 {detail.AreaCode} 未找到对应的成品库和半成品库。"); |
|
|
|
} |
|
|
|
|
|
|
|
var balances = await _balanceAppService.GetRecommendBalancesByLocationsAsync( |
|
|
|
var balances = await _balanceAppService.GetRecommendBalancesByLocationsExpectOldBalancesAsync( |
|
|
|
new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = detail.ItemCode, |
|
|
|
Qty = detail.Qty, |
|
|
|
Locations = locations.Select(r => r.Code).ToList(), |
|
|
|
Statuses = transactionType.OutInventoryStatuses |
|
|
|
Statuses = transactionType.OutInventoryStatuses, |
|
|
|
OldBalances=oldBalances, |
|
|
|
}).ConfigureAwait(false); |
|
|
|
|
|
|
|
var sumQty = balances.Sum(t => t.Qty); |
|
|
@ -180,7 +183,7 @@ public class DeliverRequestEventHandler |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"物料号 {detail.ItemCode} 库存余额 {sumQty} 小于 {detail.Qty}。"); |
|
|
|
} |
|
|
|
|
|
|
|
oldBalances.AddRange(balances); |
|
|
|
foreach (var balance in balances) |
|
|
|
{ |
|
|
|
var inputDetail = ObjectMapper.Map<BalanceDTO, DeliverNoteDetailInput>(balance); |
|
|
@ -241,7 +244,7 @@ public class DeliverRequestEventHandler |
|
|
|
} |
|
|
|
|
|
|
|
createInput.Details = new List<DeliverNoteDetailInput>(); |
|
|
|
|
|
|
|
List<BalanceDTO> oldBalances = new List<BalanceDTO>(); |
|
|
|
foreach (var detail in request.Details) |
|
|
|
{ |
|
|
|
var locations = await _locationAppService.GetListByTypesAndErpCodeAsync(transactionType.OutLocationTypes, detail.AreaCode).ConfigureAwait(false); |
|
|
@ -250,13 +253,14 @@ public class DeliverRequestEventHandler |
|
|
|
throw new UserFriendlyException($"储位 {detail.AreaCode} 未找到对应的成品库和半成品库。"); |
|
|
|
} |
|
|
|
|
|
|
|
var balances = await _balanceAppService.GetRecommendBalancesByLocationsAsync( |
|
|
|
var balances = await _balanceAppService.GetRecommendBalancesByLocationsExpectOldBalancesAsync( |
|
|
|
new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = detail.ItemCode, |
|
|
|
Qty = detail.Qty, |
|
|
|
Locations = locations.Select(r=>r.Code).ToList(), |
|
|
|
Statuses = transactionType.OutInventoryStatuses |
|
|
|
Statuses = transactionType.OutInventoryStatuses, |
|
|
|
OldBalances=oldBalances, |
|
|
|
}).ConfigureAwait(false); |
|
|
|
|
|
|
|
var sumQty = balances.Sum(t => t.Qty); |
|
|
@ -265,7 +269,7 @@ public class DeliverRequestEventHandler |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"物料号 {detail.ItemCode} 库存余额 {sumQty} 小于 {detail.Qty}。"); |
|
|
|
} |
|
|
|
|
|
|
|
oldBalances.AddRange(balances); |
|
|
|
foreach (var balance in balances) |
|
|
|
{ |
|
|
|
var inputDetail = ObjectMapper.Map<BalanceDTO, DeliverNoteDetailInput>(balance); |
|
|
@ -295,96 +299,96 @@ public class DeliverRequestEventHandler |
|
|
|
return createInput; |
|
|
|
} |
|
|
|
|
|
|
|
private async Task<List<DeliverJobEditInput>> BuildDeliverJobsAsync(DeliverRequest request) |
|
|
|
{ |
|
|
|
var transSubType = EnumTransSubType.None; |
|
|
|
switch (request.DeliverRequestType) |
|
|
|
{ |
|
|
|
case EnumDeliverRequestType.Normal: |
|
|
|
transSubType = EnumTransSubType.Deliver_Standard; |
|
|
|
break; |
|
|
|
case EnumDeliverRequestType.FIS: |
|
|
|
transSubType = EnumTransSubType.Deliver_FIS; |
|
|
|
break; |
|
|
|
case EnumDeliverRequestType.RAW: |
|
|
|
transSubType = EnumTransSubType.Deliver_RAW; |
|
|
|
break; |
|
|
|
case EnumDeliverRequestType.None: |
|
|
|
default: |
|
|
|
throw new ArgumentOutOfRangeException(); |
|
|
|
} |
|
|
|
|
|
|
|
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(); |
|
|
|
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<DeliverJobDetailInput>(); |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
var sumQty = balances.Sum(t => t.Qty); |
|
|
|
|
|
|
|
if (sumQty < detail.Qty) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"物料号 {detail.ItemCode} 库存余额 {sumQty} 小于 {detail.Qty}。"); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var balance in balances) |
|
|
|
{ |
|
|
|
var inputDetail = ObjectMapper.Map<BalanceDTO, DeliverJobDetailInput>(balance); |
|
|
|
if (toLocation != null) |
|
|
|
{ |
|
|
|
inputDetail.ToLocationCode = toLocation.Code; |
|
|
|
inputDetail.ToLocationErpCode = toLocation.ErpLocationCode; |
|
|
|
inputDetail.ToWarehouseCode = toLocation.WarehouseCode; |
|
|
|
} |
|
|
|
|
|
|
|
var item = await ItemBasicAclService.GetByCodeAsync(balance.ItemCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (item != null) |
|
|
|
{ |
|
|
|
inputDetail.StdPackQty = item.StdPackQty; |
|
|
|
} |
|
|
|
|
|
|
|
createInput.Details.Add(inputDetail); |
|
|
|
} |
|
|
|
|
|
|
|
var firstBalance = balances.FirstOrDefault(); |
|
|
|
|
|
|
|
var location = await LocationAclService.GetByCodeAsync(firstBalance.LocationCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (location != null) |
|
|
|
{ |
|
|
|
createInput.WarehouseCode = location.WarehouseCode; |
|
|
|
createInput.WorkGroupCode = location.WorkGroupCode; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
createInput.Priority = PriorityHelper.GetPriority(Clock); |
|
|
|
createInput.PriorityIncrement = 1; |
|
|
|
|
|
|
|
return new List<DeliverJobEditInput> { createInput }; |
|
|
|
} |
|
|
|
//private async Task<List<DeliverJobEditInput>> BuildDeliverJobsAsync(DeliverRequest request)
|
|
|
|
//{
|
|
|
|
// var transSubType = EnumTransSubType.None;
|
|
|
|
// switch (request.DeliverRequestType)
|
|
|
|
// {
|
|
|
|
// case EnumDeliverRequestType.Normal:
|
|
|
|
// transSubType = EnumTransSubType.Deliver_Standard;
|
|
|
|
// break;
|
|
|
|
// case EnumDeliverRequestType.FIS:
|
|
|
|
// transSubType = EnumTransSubType.Deliver_FIS;
|
|
|
|
// break;
|
|
|
|
// case EnumDeliverRequestType.RAW:
|
|
|
|
// transSubType = EnumTransSubType.Deliver_RAW;
|
|
|
|
// break;
|
|
|
|
// case EnumDeliverRequestType.None:
|
|
|
|
// default:
|
|
|
|
// throw new ArgumentOutOfRangeException();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
// 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<DeliverJobDetailInput>();
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
// var sumQty = balances.Sum(t => t.Qty);
|
|
|
|
|
|
|
|
// if (sumQty < detail.Qty)
|
|
|
|
// {
|
|
|
|
// throw new UserFriendlyException($"物料号 {detail.ItemCode} 库存余额 {sumQty} 小于 {detail.Qty}。");
|
|
|
|
// }
|
|
|
|
|
|
|
|
// foreach (var balance in balances)
|
|
|
|
// {
|
|
|
|
// var inputDetail = ObjectMapper.Map<BalanceDTO, DeliverJobDetailInput>(balance);
|
|
|
|
// if (toLocation != null)
|
|
|
|
// {
|
|
|
|
// inputDetail.ToLocationCode = toLocation.Code;
|
|
|
|
// inputDetail.ToLocationErpCode = toLocation.ErpLocationCode;
|
|
|
|
// inputDetail.ToWarehouseCode = toLocation.WarehouseCode;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// var item = await ItemBasicAclService.GetByCodeAsync(balance.ItemCode).ConfigureAwait(false);
|
|
|
|
|
|
|
|
// if (item != null)
|
|
|
|
// {
|
|
|
|
// inputDetail.StdPackQty = item.StdPackQty;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// createInput.Details.Add(inputDetail);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// var firstBalance = balances.FirstOrDefault();
|
|
|
|
|
|
|
|
// var location = await LocationAclService.GetByCodeAsync(firstBalance.LocationCode).ConfigureAwait(false);
|
|
|
|
|
|
|
|
// if (location != null)
|
|
|
|
// {
|
|
|
|
// createInput.WarehouseCode = location.WarehouseCode;
|
|
|
|
// createInput.WorkGroupCode = location.WorkGroupCode;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// createInput.Priority = PriorityHelper.GetPriority(Clock);
|
|
|
|
// createInput.PriorityIncrement = 1;
|
|
|
|
|
|
|
|
// return new List<DeliverJobEditInput> { createInput };
|
|
|
|
//}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|