|
|
@ -4,6 +4,8 @@ using System.Linq; |
|
|
|
using System.Linq.Expressions; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Castle.Components.DictionaryAdapter; |
|
|
|
using IdentityServer4.Models; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
@ -12,10 +14,13 @@ using Volo.Abp.Application.Dtos; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.ObjectMapping; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
using Win_in.Sfs.Basedata.Application.Contracts; |
|
|
|
using Win_in.Sfs.Basedata.Domain.Shared; |
|
|
|
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; |
|
|
@ -29,12 +34,264 @@ public class ThirdLocationJobAppService |
|
|
|
IThirdLocationJobAppService |
|
|
|
{ |
|
|
|
private readonly IThirdLocationJobManager _thirdLocationJobManager; |
|
|
|
private readonly ITransferLogAppService _transferLogAppService; |
|
|
|
private readonly ILocationAppService _locationAppService; |
|
|
|
private readonly IThirdLocationNoteAppService _thirdLocationNoteAppService; |
|
|
|
|
|
|
|
protected IThirdLocationRequestAppService ThirdLocationRequestAppService => |
|
|
|
LazyServiceProvider.LazyGetRequiredService<IThirdLocationRequestAppService>(); |
|
|
|
|
|
|
|
public ThirdLocationJobAppService( |
|
|
|
IThirdLocationJobRepository repository, IThirdLocationJobManager thirdLocationJobManager |
|
|
|
) : base(repository, thirdLocationJobManager) |
|
|
|
IThirdLocationJobRepository repository, IThirdLocationJobManager thirdLocationJobManager, |
|
|
|
ITransferLogAppService transferLogAppService, ILocationAppService locationAppService, IThirdLocationNoteAppService thirdLocationNoteAppService) : base(repository, thirdLocationJobManager) |
|
|
|
{ |
|
|
|
_thirdLocationJobManager = thirdLocationJobManager; |
|
|
|
_transferLogAppService = transferLogAppService; |
|
|
|
_locationAppService = locationAppService; |
|
|
|
_thirdLocationNoteAppService = thirdLocationNoteAppService; |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost("")] |
|
|
|
public override async Task<ThirdLocationJobDTO> CreateAsync(ThirdLocationJobEditInput input) |
|
|
|
{ |
|
|
|
input.JobStatus = EnumJobStatus.Open; |
|
|
|
var result = await base.CreateAsync(input).ConfigureAwait(false); |
|
|
|
|
|
|
|
var buildTransferLogsAsync = await BuildTransferLogsByToTransportAsync(result).ConfigureAwait(false); |
|
|
|
|
|
|
|
await AddTransferLogsAsync(buildTransferLogsAsync).ConfigureAwait(false); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost("add-many")] |
|
|
|
public override async Task<List<ThirdLocationJobDTO>> CreateManyAsync(List<ThirdLocationJobEditInput> inputs) |
|
|
|
{ |
|
|
|
var thirdLocationJobDtos = new List<ThirdLocationJobDTO>(); |
|
|
|
|
|
|
|
foreach (var input in inputs) |
|
|
|
{ |
|
|
|
thirdLocationJobDtos.Add(await CreateAsync(input).ConfigureAwait(false)); |
|
|
|
} |
|
|
|
|
|
|
|
return thirdLocationJobDtos; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 执行任务明细
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("ExecuteDetail/{masterId}")] |
|
|
|
public async Task ExecuteDetailAsync(Guid masterId,List<ThirdLocationJobDetailDTO> detailDtoList) |
|
|
|
{ |
|
|
|
var thirdLocationJob=await _repository.GetAsync(masterId).ConfigureAwait(false); |
|
|
|
thirdLocationJob.JobStatus = EnumJobStatus.Partial; |
|
|
|
|
|
|
|
var tempDetailDto= new List<ThirdLocationJobDetailDTO>(); |
|
|
|
var entityList=ObjectMapper.Map<List<ThirdLocationJobDetail>, List<ThirdLocationJobDetailDTO>>(thirdLocationJob.Details); |
|
|
|
foreach (var detailDto in detailDtoList)//为了不用DTO的赋值
|
|
|
|
{ |
|
|
|
var jobDetailDto=entityList.First(p => p.Id == detailDto.Id); |
|
|
|
jobDetailDto.HandledQty = detailDto.HandledQty; |
|
|
|
jobDetailDto.RecommendQty = detailDto.RecommendQty; |
|
|
|
tempDetailDto.Add(jobDetailDto); |
|
|
|
|
|
|
|
thirdLocationJob.Details.First(p => p.Id == detailDto.Id).ReceivedQty += detailDto.HandledQty; |
|
|
|
} |
|
|
|
|
|
|
|
var transferLogs = await BuildTransferLogsByFromTransportAsync(thirdLocationJob, tempDetailDto).ConfigureAwait(false); |
|
|
|
await _transferLogAppService.AddManyAsync(transferLogs).ConfigureAwait(false); |
|
|
|
|
|
|
|
var jobDto=await GetAsync(masterId).ConfigureAwait(false); |
|
|
|
var tempDetailDtos = new List<ThirdLocationJobDetailDTO>(); |
|
|
|
foreach (var detailDto in detailDtoList) |
|
|
|
{ |
|
|
|
var temp=jobDto.Details.First(p => p.Id == detailDto.Id); |
|
|
|
temp.HandledQty=detailDto.HandledQty; |
|
|
|
temp.RecommendQty = detailDto.RecommendQty; |
|
|
|
tempDetailDtos.Add(temp); |
|
|
|
} |
|
|
|
|
|
|
|
jobDto.Details = tempDetailDtos; |
|
|
|
|
|
|
|
var input =await BuildThirdLocationNoteAsync(jobDto).ConfigureAwait(false); |
|
|
|
var noteDto = await _thirdLocationNoteAppService.CreateByNumberAsync(input).ConfigureAwait(false); |
|
|
|
|
|
|
|
await UpdateJobStatusAsync(thirdLocationJob).ConfigureAwait(false); |
|
|
|
|
|
|
|
await _repository.UpdateAsync(thirdLocationJob).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 完成任务
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("Complete/{id}")] |
|
|
|
public async Task CompleteAsync(Guid id) |
|
|
|
{ |
|
|
|
var kittingIssueJob = await _repository.FindAsync(id).ConfigureAwait(false); |
|
|
|
|
|
|
|
kittingIssueJob.JobStatus = EnumJobStatus.Done; |
|
|
|
|
|
|
|
var entity=await _repository.UpdateAsync(kittingIssueJob).ConfigureAwait(false); |
|
|
|
|
|
|
|
var dto=ObjectMapper.Map<ThirdLocationJob, ThirdLocationJobDTO>(entity); |
|
|
|
|
|
|
|
var transferLogEditInputs=await BuildTransferLogsByBackFromAsync(dto).ConfigureAwait(false); |
|
|
|
|
|
|
|
await AddTransferLogsAsync(transferLogEditInputs).ConfigureAwait(false); |
|
|
|
|
|
|
|
await ThirdLocationRequestAppService.UpdateRequestStatusAsync(kittingIssueJob.RequestNumber).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost("Get-By-Request-Number")] |
|
|
|
public async Task<List<ThirdLocationJobDTO>> GetByRequestNumberAsync(string requestNumber) |
|
|
|
{ |
|
|
|
var list=await _repository.GetListAsync(p => p.RequestNumber == requestNumber).ConfigureAwait(false); |
|
|
|
return ObjectMapper.Map<List<ThirdLocationJob>, List<ThirdLocationJobDTO>>(list); |
|
|
|
} |
|
|
|
|
|
|
|
#region 私有
|
|
|
|
|
|
|
|
private async Task UpdateJobStatusAsync(ThirdLocationJob thirdLocationJob) |
|
|
|
{ |
|
|
|
var flag = true; |
|
|
|
foreach (var detail in thirdLocationJob.Details) |
|
|
|
{ |
|
|
|
if (detail.IssuedQty > detail.ReceivedQty) |
|
|
|
{ |
|
|
|
flag = false; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (flag) |
|
|
|
{ |
|
|
|
thirdLocationJob.JobStatus = EnumJobStatus.Done; |
|
|
|
} |
|
|
|
|
|
|
|
await _repository.UpdateAsync(thirdLocationJob).ConfigureAwait(false); |
|
|
|
await ThirdLocationRequestAppService.UpdateRequestStatusAsync(thirdLocationJob.RequestNumber).ConfigureAwait(false); |
|
|
|
await Task.CompletedTask.ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task AddTransferLogsAsync(List<TransferLogEditInput> inputList) |
|
|
|
{ |
|
|
|
var transferLogs = new List<TransferLogEditInput>(); |
|
|
|
|
|
|
|
transferLogs.AddRange(inputList); |
|
|
|
|
|
|
|
await _transferLogAppService.AddManyAsync(transferLogs).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task<ThirdLocationNoteEditInput> BuildThirdLocationNoteAsync(ThirdLocationJobDTO jobDto) |
|
|
|
{ |
|
|
|
await Task.CompletedTask.ConfigureAwait(false); |
|
|
|
|
|
|
|
return ObjectMapper.Map<ThirdLocationJobDTO, ThirdLocationNoteEditInput>(jobDto); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 创建库移 从from到在途
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dto"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task<List<TransferLogEditInput>> BuildTransferLogsByToTransportAsync(ThirdLocationJobDTO dto) |
|
|
|
{ |
|
|
|
//获取在途库
|
|
|
|
var transportLocation =await _locationAppService.GetFirstByTypeAsync(EnumLocationType.TRANSPORT).ConfigureAwait(false); |
|
|
|
|
|
|
|
var transferLog = new List<TransferLogEditInput>(); |
|
|
|
foreach (var detailDto in dto.Details) |
|
|
|
{ |
|
|
|
var transferLogEditInput = ObjectMapper.Map<ThirdLocationJobDetailDTO, TransferLogEditInput>(detailDto); |
|
|
|
transferLogEditInput.TransType = EnumTransType.Transfer; |
|
|
|
transferLogEditInput.DocNumber = dto.Number; |
|
|
|
transferLogEditInput.JobNumber = dto.Number; |
|
|
|
transferLogEditInput.Remark = $"目标库位:{detailDto.ToLocationCode.Clone()}"; |
|
|
|
transferLogEditInput.ToLocationCode = transportLocation.Code; |
|
|
|
transferLogEditInput.ToLocationErpCode = transportLocation.ErpLocationCode; |
|
|
|
transferLogEditInput.ToLocationArea = transportLocation.AreaCode; |
|
|
|
transferLogEditInput.ToLocationGroup = transportLocation.LocationGroupCode; |
|
|
|
transferLogEditInput.ToWarehouseCode = transportLocation.WarehouseCode; |
|
|
|
|
|
|
|
transferLog.Add(transferLogEditInput); |
|
|
|
} |
|
|
|
|
|
|
|
await Task.CompletedTask.ConfigureAwait(false); |
|
|
|
|
|
|
|
return transferLog; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 创建库移 从在途到To
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="entity"></param>
|
|
|
|
/// <param name="detailDtos"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task<List<TransferLogEditInput>> BuildTransferLogsByFromTransportAsync(ThirdLocationJob entity, List<ThirdLocationJobDetailDTO> detailDtos) |
|
|
|
{ |
|
|
|
//获取在途库
|
|
|
|
var transportLocation =await _locationAppService.GetFirstByTypeAsync(EnumLocationType.TRANSPORT).ConfigureAwait(false); |
|
|
|
|
|
|
|
var transferLog = new List<TransferLogEditInput>(); |
|
|
|
foreach (var detail in entity.Details) |
|
|
|
{ |
|
|
|
var transferLogEditInput = ObjectMapper.Map<ThirdLocationJobDetail, TransferLogEditInput>(detail); |
|
|
|
transferLogEditInput.TransType = EnumTransType.Transfer; |
|
|
|
transferLogEditInput.DocNumber = entity.Number; |
|
|
|
transferLogEditInput.JobNumber = entity.Number; |
|
|
|
transferLogEditInput.Remark = $"来源库位:{detail.FromLocationCode.Clone()}"; |
|
|
|
transferLogEditInput.FromLocationCode = transportLocation.Code; |
|
|
|
transferLogEditInput.FromLocationErpCode = transportLocation.ErpLocationCode; |
|
|
|
transferLogEditInput.FromLocationArea = transportLocation.AreaCode; |
|
|
|
transferLogEditInput.FromLocationGroup = transportLocation.LocationGroupCode; |
|
|
|
transferLogEditInput.FromWarehouseCode = transportLocation.WarehouseCode; |
|
|
|
transferLogEditInput.Qty = detailDtos.First(p => p.Id == detail.Id).HandledQty; |
|
|
|
|
|
|
|
transferLog.Add(transferLogEditInput); |
|
|
|
} |
|
|
|
|
|
|
|
await Task.CompletedTask.ConfigureAwait(false); |
|
|
|
|
|
|
|
return transferLog; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async Task<List<TransferLogEditInput>> BuildTransferLogsByBackFromAsync(ThirdLocationJobDTO dto) |
|
|
|
{ |
|
|
|
//获取在途库
|
|
|
|
var transportLocation = await _locationAppService.GetFirstByTypeAsync(EnumLocationType.TRANSPORT).ConfigureAwait(false); |
|
|
|
|
|
|
|
var transferLog = new List<TransferLogEditInput>(); |
|
|
|
foreach (var detailDto in dto.Details) |
|
|
|
{ |
|
|
|
var transferLogEditInput = ObjectMapper.Map<ThirdLocationJobDetailDTO, TransferLogEditInput>(detailDto); |
|
|
|
transferLogEditInput.TransType = EnumTransType.Transfer; |
|
|
|
transferLogEditInput.DocNumber = dto.Number; |
|
|
|
transferLogEditInput.JobNumber = dto.Number; |
|
|
|
|
|
|
|
transferLogEditInput.FromLocationCode = transportLocation.Code; |
|
|
|
transferLogEditInput.FromLocationErpCode = transportLocation.ErpLocationCode; |
|
|
|
transferLogEditInput.FromLocationArea = transportLocation.AreaCode; |
|
|
|
transferLogEditInput.FromLocationGroup = transportLocation.LocationGroupCode; |
|
|
|
transferLogEditInput.FromWarehouseCode = transportLocation.WarehouseCode; |
|
|
|
|
|
|
|
transferLogEditInput.ToLocationCode = detailDto.FromLocationCode; |
|
|
|
transferLogEditInput.ToLocationErpCode = detailDto.FromLocationErpCode; |
|
|
|
transferLogEditInput.ToLocationArea = detailDto.FromLocationArea; |
|
|
|
transferLogEditInput.ToLocationGroup = detailDto.FromLocationGroup; |
|
|
|
transferLogEditInput.ToWarehouseCode = detailDto.ToWarehouseCode; |
|
|
|
|
|
|
|
transferLogEditInput.Qty = detailDto.IssuedQty - detailDto.ReceivedQty; |
|
|
|
|
|
|
|
transferLog.Add(transferLogEditInput); |
|
|
|
} |
|
|
|
|
|
|
|
await Task.CompletedTask.ConfigureAwait(false); |
|
|
|
|
|
|
|
return transferLog; |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|