|
|
@ -119,97 +119,95 @@ public class DeliverRequestEventHandler |
|
|
|
//东阳特殊逻辑
|
|
|
|
if (entitys.First().DirectCreateNote) |
|
|
|
{ |
|
|
|
var noteCreateInput = await BuildDeliverNoteAsync(entitys).ConfigureAwait(false); |
|
|
|
await _deliverNoteApp.CreateAsync(noteCreateInput).ConfigureAwait(false); |
|
|
|
var noteCreateInputs = await BuildDeliverNotesAsync(entitys).ConfigureAwait(false); |
|
|
|
await _deliverNoteApp.CreateManyAsync(noteCreateInputs).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#region 私有
|
|
|
|
private async Task<DeliverNoteEditInput> BuildDeliverNoteAsync(List<DeliverRequest> requests) |
|
|
|
private async Task<List<DeliverNoteEditInput>> BuildDeliverNotesAsync(List<DeliverRequest> requests) |
|
|
|
{ |
|
|
|
var transactionType = await TransactionTypeAclService |
|
|
|
.GetByTransTypeAsync(EnumTransType.Deliver, EnumTransSubType.None).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (requests.First().DeliverRequestType == EnumDeliverRequestType.Normal) |
|
|
|
{ |
|
|
|
transactionType = await TransactionTypeAclService.GetByTransTypeAsync( |
|
|
|
EnumTransType.Deliver, |
|
|
|
EnumTransSubType.Deliver_Standard).ConfigureAwait(false); |
|
|
|
} |
|
|
|
else if (requests.First().DeliverRequestType == EnumDeliverRequestType.FIS) |
|
|
|
List<DeliverNoteEditInput> createInputs = new List<DeliverNoteEditInput>(); |
|
|
|
var transactionType = await TransactionTypeAclService.GetByTransTypeAsync(EnumTransType.Deliver, EnumTransSubType.None).ConfigureAwait(false); |
|
|
|
foreach (var request in requests) |
|
|
|
{ |
|
|
|
transactionType = await TransactionTypeAclService.GetByTransTypeAsync( |
|
|
|
EnumTransType.Deliver, |
|
|
|
EnumTransSubType.Deliver_FIS).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
var createInput = ObjectMapper.Map<DeliverRequest, DeliverNoteEditInput>(requests.First()); |
|
|
|
|
|
|
|
var customerAddress = |
|
|
|
(await _customerAddressApp.GetByCustomerCodeAsync(createInput.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<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); |
|
|
|
if (locations.Count <= 0) |
|
|
|
if (request.DeliverRequestType == EnumDeliverRequestType.Normal) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"储位 {detail.AreaCode} 未找到对应的成品库和半成品库。"); |
|
|
|
transactionType = await TransactionTypeAclService.GetByTransTypeAsync( |
|
|
|
EnumTransType.Deliver, |
|
|
|
EnumTransSubType.Deliver_Standard).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
var balances = await _balanceAppService.GetRecommendBalancesByLocationsExpectOldBalancesAsync( |
|
|
|
new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = detail.ItemCode, |
|
|
|
Qty = detail.Qty, |
|
|
|
Locations = locations.Select(r => r.Code).ToList(), |
|
|
|
Statuses = transactionType.OutInventoryStatuses, |
|
|
|
OldBalances=oldBalances, |
|
|
|
}).ConfigureAwait(false); |
|
|
|
|
|
|
|
var sumQty = balances.Sum(t => t.Qty); |
|
|
|
|
|
|
|
if (sumQty < detail.Qty) |
|
|
|
else if (request.DeliverRequestType == EnumDeliverRequestType.FIS) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"ERP料号 {detail.ItemCode} 库存余额 {sumQty} 小于 {detail.Qty}。"); |
|
|
|
transactionType = await TransactionTypeAclService.GetByTransTypeAsync( |
|
|
|
EnumTransType.Deliver, |
|
|
|
EnumTransSubType.Deliver_FIS).ConfigureAwait(false); |
|
|
|
} |
|
|
|
oldBalances.AddRange(balances); |
|
|
|
foreach (var balance in balances) |
|
|
|
var createInput = ObjectMapper.Map<DeliverRequest, DeliverNoteEditInput>(request); |
|
|
|
var customerAddress = (await _customerAddressApp.GetByCustomerCodeAsync(createInput.CustomerCode).ConfigureAwait(false)).FirstOrDefault(); |
|
|
|
LocationDTO toLocation = null; |
|
|
|
if (customerAddress != null && !string.IsNullOrEmpty(customerAddress.LocationCode)) |
|
|
|
{ |
|
|
|
var inputDetail = ObjectMapper.Map<BalanceDTO, DeliverNoteDetailInput>(balance); |
|
|
|
toLocation = await LocationAclService.GetByCodeAsync(customerAddress.LocationCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
var item = await ItemBasicAclService.GetByCodeAsync(balance.ItemCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (item != null) |
|
|
|
Check.NotNull(toLocation, $"客户库位 {customerAddress.LocationCode} 不存在"); |
|
|
|
} |
|
|
|
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); |
|
|
|
if (locations.Count <= 0) |
|
|
|
{ |
|
|
|
inputDetail.StdPackQty = item.StdPackQty; |
|
|
|
throw new UserFriendlyException($"储位 {detail.AreaCode} 未找到对应的成品库和半成品库。"); |
|
|
|
} |
|
|
|
|
|
|
|
if (toLocation != null) |
|
|
|
{ |
|
|
|
inputDetail.ToLocationCode = toLocation.Code; |
|
|
|
var balances = await _balanceAppService.GetRecommendBalancesByLocationsExpectOldBalancesAsync( |
|
|
|
new RecommendBalanceRequestInput |
|
|
|
{ |
|
|
|
ItemCode = detail.ItemCode, |
|
|
|
Qty = detail.Qty, |
|
|
|
Locations = locations.Select(r => r.Code).ToList(), |
|
|
|
Statuses = transactionType.OutInventoryStatuses, |
|
|
|
OldBalances = oldBalances, |
|
|
|
}).ConfigureAwait(false); |
|
|
|
|
|
|
|
inputDetail.ToLocationErpCode = toLocation.ErpLocationCode; |
|
|
|
var sumQty = balances.Sum(t => t.Qty); |
|
|
|
|
|
|
|
if (sumQty < detail.Qty) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"ERP料号 {detail.ItemCode} 库存余额 {sumQty} 小于 {detail.Qty}。"); |
|
|
|
} |
|
|
|
oldBalances.AddRange(balances); |
|
|
|
foreach (var balance in balances) |
|
|
|
{ |
|
|
|
var inputDetail = ObjectMapper.Map<BalanceDTO, DeliverNoteDetailInput>(balance); |
|
|
|
|
|
|
|
inputDetail.ExtraProperties = detail.ExtraProperties; |
|
|
|
inputDetail.MesDeliveryNo = detail.MesDeliveryNo; |
|
|
|
inputDetail.IdentityNo = detail.IdentityNo; |
|
|
|
inputDetail.MesDeliveryPlan = detail.MesDeliveryPlan; |
|
|
|
createInput.Details.Add(inputDetail); |
|
|
|
var item = await ItemBasicAclService.GetByCodeAsync(balance.ItemCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (item != null) |
|
|
|
{ |
|
|
|
inputDetail.StdPackQty = item.StdPackQty; |
|
|
|
} |
|
|
|
|
|
|
|
if (toLocation != null) |
|
|
|
{ |
|
|
|
inputDetail.ToLocationCode = toLocation.Code; |
|
|
|
|
|
|
|
inputDetail.ToLocationErpCode = toLocation.ErpLocationCode; |
|
|
|
} |
|
|
|
|
|
|
|
inputDetail.ExtraProperties = detail.ExtraProperties; |
|
|
|
inputDetail.MesDeliveryNo = detail.MesDeliveryNo; |
|
|
|
inputDetail.IdentityNo = detail.IdentityNo; |
|
|
|
inputDetail.MesDeliveryPlan = detail.MesDeliveryPlan; |
|
|
|
createInput.Details.Add(inputDetail); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
createInputs.Add(createInput); |
|
|
|
} |
|
|
|
return createInput; |
|
|
|
return createInputs; |
|
|
|
} |
|
|
|
private async Task<DeliverNoteEditInput> BuildDeliverNoteAsync(DeliverRequest request) |
|
|
|
{ |
|
|
|