|
|
@ -22,6 +22,7 @@ using Win_in.Sfs.Shared.Domain; |
|
|
|
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.Inventory.Domain; |
|
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts; |
|
|
|
using Win_in.Sfs.Wms.Store.Domain; |
|
|
|
using Win_in.Sfs.Wms.Store.Domain.Shared; |
|
|
@ -49,10 +50,13 @@ public class ThirdLocationRequestAppService : SfsStoreRequestAppServiceBase<Thir |
|
|
|
private readonly IExpectOutAppService _expectOutAppService; |
|
|
|
private readonly IBalanceAppService _balanceAppService; |
|
|
|
private readonly IThirdLocationJobAppService _thirdLocationJobAppService; |
|
|
|
private readonly IThirdLocationJobRepository _thirdLocationJobRepository; |
|
|
|
private readonly IBalanceManager _balanceManager; |
|
|
|
|
|
|
|
public ThirdLocationRequestAppService( |
|
|
|
IThirdLocationRequestRepository repository, |
|
|
|
IThirdLocationJobAppService thirdLocationJobAppService, |
|
|
|
IThirdLocationJobRepository thirdLocationJobRepository, |
|
|
|
IThirdLocationRequestManager thirdLocationRequestManager, |
|
|
|
IPreparationPlanManager preparationPlanManager, |
|
|
|
IItemStoreRelationAppService itemStoreRelationApp, |
|
|
@ -63,6 +67,7 @@ public class ThirdLocationRequestAppService : SfsStoreRequestAppServiceBase<Thir |
|
|
|
ITransactionTypeAppService transactionTypeAppService, |
|
|
|
IExpectOutAppService expectOutAppService, |
|
|
|
IBalanceAppService balanceAppService, |
|
|
|
IBalanceManager balanceManager, |
|
|
|
IInjectionIssueJobAppService issueJobAppService) |
|
|
|
: base(repository, thirdLocationRequestManager) |
|
|
|
{ |
|
|
@ -77,6 +82,8 @@ public class ThirdLocationRequestAppService : SfsStoreRequestAppServiceBase<Thir |
|
|
|
_expectOutAppService= expectOutAppService; |
|
|
|
_balanceAppService= balanceAppService; |
|
|
|
_thirdLocationJobAppService= thirdLocationJobAppService; |
|
|
|
_thirdLocationJobRepository= thirdLocationJobRepository; |
|
|
|
_balanceManager= balanceManager; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -144,26 +151,56 @@ public class ThirdLocationRequestAppService : SfsStoreRequestAppServiceBase<Thir |
|
|
|
CheckLocation(toLocationDto, detailInput.ToLocationCode); |
|
|
|
|
|
|
|
var itemBasicDto = await _itemBasicAppService.GetByCodeAsync(detailInput.ItemCode).ConfigureAwait(false); |
|
|
|
CheckItemBasic(itemBasicDto, detailInput.ItemCode); |
|
|
|
var balanceNums= await _balanceAppService.GetListByLocationCodeAndItemCodeAsync(detailInput.FromLocationCode, detailInput.ItemCode).ConfigureAwait(false); |
|
|
|
decimal balanceSum = 0; |
|
|
|
foreach (var item in balanceNums) |
|
|
|
CheckItemBasic(itemBasicDto, detailInput.ItemCode); |
|
|
|
|
|
|
|
List<string> locationCodes=new List<string>(); |
|
|
|
locationCodes.Add(detailInput.FromLocationCode); |
|
|
|
List<EnumInventoryStatus> inventoryStatusList = new List<EnumInventoryStatus>(); |
|
|
|
inventoryStatusList.Add(EnumInventoryStatus.OK); |
|
|
|
|
|
|
|
var fromLocationDto = await _locationAppService.GetByCodeAsync(detailInput.FromLocationCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
List<Balance> inventoryBalances; |
|
|
|
if (fromLocationDto.Type== EnumLocationType.RAW) |
|
|
|
{ |
|
|
|
balanceSum += item.Qty; |
|
|
|
inventoryBalances = await _balanceManager.GetUsableListAsync(detailInput.ItemCode, locationCodes, inventoryStatusList, true).ConfigureAwait(false); |
|
|
|
} |
|
|
|
var expectOutNums= await _expectOutAppService.GetListByItemAsync(detailInput.ItemCode).ConfigureAwait(false); |
|
|
|
decimal expectOutSum = 0; |
|
|
|
foreach (var item in expectOutNums) |
|
|
|
else |
|
|
|
{ |
|
|
|
expectOutSum += item.Qty; |
|
|
|
inventoryBalances = await _balanceManager.GetNoPackCodeUsableListAsync(detailInput.ItemCode, locationCodes, inventoryStatusList, true).ConfigureAwait(false); |
|
|
|
} |
|
|
|
decimal realityBalance = balanceSum - expectOutSum; |
|
|
|
if (detailInput.Qty> realityBalance) |
|
|
|
|
|
|
|
decimal balanceSum = 0; |
|
|
|
foreach (var item in inventoryBalances) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"{detailInput.ItemCode} 物品的库存为 {realityBalance} ,库存不够"); |
|
|
|
balanceSum += item.Qty; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (detailInput.Qty > balanceSum) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"{detailInput.ItemCode} 物品的库存为 {balanceSum} ,库存不够"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//var balanceNums= await _balanceAppService.GetListByLocationCodeAndItemCodeAsync(detailInput.FromLocationCode, detailInput.ItemCode).ConfigureAwait(false);
|
|
|
|
//decimal balanceSum = 0;
|
|
|
|
//foreach (var item in balanceNums)
|
|
|
|
//{
|
|
|
|
// balanceSum += item.Qty;
|
|
|
|
//}
|
|
|
|
//var expectOutNums= await _expectOutAppService.GetListByItemAsync(detailInput.ItemCode).ConfigureAwait(false);
|
|
|
|
//decimal expectOutSum = 0;
|
|
|
|
//foreach (var item in expectOutNums)
|
|
|
|
//{
|
|
|
|
// expectOutSum += item.Qty;
|
|
|
|
//}
|
|
|
|
//decimal realityBalance = balanceSum - expectOutSum;
|
|
|
|
//if (detailInput.Qty> realityBalance)
|
|
|
|
//{
|
|
|
|
// throw new UserFriendlyException($"{detailInput.ItemCode} 物品的库存为 {realityBalance} ,库存不够");
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
detailInput.ToLocationErpCode = toLocationDto.ErpLocationCode; |
|
|
|
|
|
|
|
|
|
|
@ -212,7 +249,7 @@ public class ThirdLocationRequestAppService : SfsStoreRequestAppServiceBase<Thir |
|
|
|
{ |
|
|
|
foreach (var thirdLocationJobDto in list) |
|
|
|
{ |
|
|
|
if (thirdLocationJobDto.JobStatus == EnumJobStatus.Open) |
|
|
|
if (thirdLocationJobDto.JobStatus == EnumJobStatus.Open || thirdLocationJobDto.JobStatus == EnumJobStatus.Doing) |
|
|
|
{ |
|
|
|
await _thirdLocationJobAppService.CancelAsync(thirdLocationJobDto.Id).ConfigureAwait(false); |
|
|
|
} |
|
|
@ -240,6 +277,58 @@ public class ThirdLocationRequestAppService : SfsStoreRequestAppServiceBase<Thir |
|
|
|
return ObjectMapper.Map<ThirdLocationRequest, ThirdLocationRequestDTO>(request); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 用来重写 完成请求
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public override async Task<ThirdLocationRequestDTO> CompleteAsync(Guid id) |
|
|
|
{ |
|
|
|
var request = await _repository.GetAsync(id).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (request.RequestStatus == EnumRequestStatus.Partial) |
|
|
|
{ |
|
|
|
request.RequestStatus = EnumRequestStatus.Completed; |
|
|
|
await Task.CompletedTask.ConfigureAwait(false); |
|
|
|
//await LocalEventBus.PublishAsync(new SfsCompletedEntityEventData<ThirdLocationRequest>(request), false).ConfigureAwait(false);
|
|
|
|
await _repository.UpdateAsync(request).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"【{request.RequestStatus.GetDisplayName()}】状态不允许取消"); |
|
|
|
} |
|
|
|
var entitys = await _thirdLocationJobRepository.GetListAsync(p => p.RequestNumber == request.Number, "", true).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (entitys.Any()) |
|
|
|
{ |
|
|
|
foreach (var thirdLocationJob in entitys) |
|
|
|
{ |
|
|
|
if (thirdLocationJob.JobStatus == EnumJobStatus.Partial) |
|
|
|
{ |
|
|
|
thirdLocationJob.JobStatus = EnumJobStatus.Done; |
|
|
|
await Task.CompletedTask.ConfigureAwait(false); |
|
|
|
await LocalEventBus.PublishAsync(new SfsClosedEntityEventData<ThirdLocationJob>(thirdLocationJob), false).ConfigureAwait(false); |
|
|
|
await _thirdLocationJobRepository.UpdateAsync(thirdLocationJob).ConfigureAwait(false); |
|
|
|
} |
|
|
|
else if (thirdLocationJob.JobStatus == EnumJobStatus.Open || thirdLocationJob.JobStatus == EnumJobStatus.Doing) |
|
|
|
{ |
|
|
|
thirdLocationJob.JobStatus = EnumJobStatus.Closed; |
|
|
|
await Task.CompletedTask.ConfigureAwait(false); |
|
|
|
await LocalEventBus.PublishAsync(new SfsClosedEntityEventData<ThirdLocationJob>(thirdLocationJob), false).ConfigureAwait(false); |
|
|
|
await _thirdLocationJobRepository.UpdateAsync(thirdLocationJob).ConfigureAwait(false); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return ObjectMapper.Map<ThirdLocationRequest, ThirdLocationRequestDTO>(request); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 赋值Request业务属性
|
|
|
|
/// </summary>
|
|
|
|