You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
5.9 KiB
155 lines
5.9 KiB
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp.EventBus;
|
|
using Volo.Abp.Uow;
|
|
using Volo.Abp.Validation;
|
|
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.Job.Domain;
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts;
|
|
|
|
namespace Win_in.Sfs.Wms.Job.Event.BusinessJob;
|
|
|
|
public class JisDeliverJobEventHandler :
|
|
JobBusinessJobEventHandlerBase
|
|
, ILocalEventHandler<SfsCompletedEntityEventData<JisDeliverJob>>
|
|
{
|
|
private readonly IJisDeliverNoteAppService _deliverNoteAppService;
|
|
private readonly IContainerAppService _containerAppService;
|
|
|
|
public JisDeliverJobEventHandler(
|
|
IJisDeliverNoteAppService deliverNoteAppService
|
|
, IContainerAppService containerAppService
|
|
)
|
|
{
|
|
_deliverNoteAppService = deliverNoteAppService;
|
|
_containerAppService = containerAppService;
|
|
}
|
|
|
|
[UnitOfWork]
|
|
public virtual async Task HandleEventAsync(SfsCompletedEntityEventData<JisDeliverJob> eventData)
|
|
{
|
|
var entity = eventData.Entity;
|
|
var jisDeliverNoteCreateInput = await BuildJisDeliverNoteCreateInput(entity).ConfigureAwait(false);
|
|
await _deliverNoteAppService.CreateWithL7Async(jisDeliverNoteCreateInput).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
private async Task<JisDeliverNoteEditInput> BuildJisDeliverNoteCreateInput(JisDeliverJob entity)
|
|
{
|
|
var result = new AbpValidationResult();
|
|
|
|
var input = ObjectMapper.Map<JisDeliverJob, JisDeliverNoteEditInput>(entity);
|
|
input.DeliverTime = Clock.Now;
|
|
input.Details = new List<JisDeliverNoteDetailInput>();
|
|
|
|
foreach (var jobDetail in entity.Details)
|
|
{
|
|
|
|
//获取容器的明细,并生成对应的发货Note
|
|
#region 更新对应的容器
|
|
|
|
var container =
|
|
//获取容器的明细,并生成对应的发货Note
|
|
await _containerAppService.GetByCodeAsync(jobDetail.ContainerCode).ConfigureAwait(false);
|
|
|
|
if (container == null)
|
|
{
|
|
result.Errors.Add(new ValidationResult($"找不到对应的容器数据{jobDetail.ContainerCode}"));
|
|
|
|
return input;
|
|
}
|
|
|
|
//在库待发
|
|
if (container.BusinessStatus != EnumContainerBusinessStatus.PreDeliver)
|
|
{
|
|
switch (jobDetail.Status)
|
|
{
|
|
case EnumJobStatus.Done:
|
|
result.Errors.Add(new ValidationResult($"容器数据{jobDetail.ContainerCode}状态为{container.BusinessStatus},不是在库状态,不能发货!"));
|
|
break;
|
|
case EnumJobStatus.Closed:
|
|
result.Errors.Add(new ValidationResult($"容器数据{jobDetail.ContainerCode}状态为{container.BusinessStatus},不是在库状态,不能设置成隔离状态!"));
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (result.Errors.Any())
|
|
{
|
|
return input;
|
|
}
|
|
|
|
//获取对应的容器信息,并更新容器状态
|
|
if (jobDetail.Status == EnumJobStatus.Done)
|
|
{
|
|
container.BusinessStatus = EnumContainerBusinessStatus.Delivered; //已发
|
|
container.LocationCode = jobDetail.ToLocationCode;
|
|
input.ContainerQty++; //赋值发货容器数量
|
|
input.ItemQty += container.Capacity;//赋值数量
|
|
|
|
//TODO 获取库存余额后没有使用?
|
|
//根据库存查询对应库存余额,然后构建发货明细
|
|
//var balances = await _balanceAppService.GetListByContainerCodeAsync(jobDetail.ContainerCode);
|
|
|
|
//遍历这个集合 然后生成对应的明细
|
|
|
|
foreach (var balance in container.Details)
|
|
{
|
|
var detailInput = BuildJisDeliverNoteDetailInput(entity, balance, container, jobDetail);
|
|
|
|
input.Details.Add(detailInput);
|
|
}
|
|
|
|
}
|
|
else if (jobDetail.Status == EnumJobStatus.Closed)
|
|
{
|
|
container.BusinessStatus = EnumContainerBusinessStatus.Hold; //隔离
|
|
}
|
|
|
|
var containerUpdateInput = ObjectMapper.Map<ContainerDTO, ContainerEditInput>(container);
|
|
|
|
await _containerAppService.UpdateAsync(container.Id, containerUpdateInput).ConfigureAwait(false);//已发
|
|
#endregion
|
|
|
|
}
|
|
return input;
|
|
}
|
|
|
|
private static JisDeliverNoteDetailInput BuildJisDeliverNoteDetailInput(JisDeliverJob entity,
|
|
ContainerDetailDTO balance, ContainerDTO container, JisDeliverJobDetail jobDetail)
|
|
{
|
|
var detailInput = new JisDeliverNoteDetailInput()
|
|
{
|
|
ItemCode = balance.ItemCode,
|
|
FromLot = balance.Lot,
|
|
ToLot = balance.Lot,
|
|
FromPackingCode = balance.PackingCode,
|
|
ToPackingCode = balance.PackingCode,
|
|
FromLocationCode = container.LocationCode,
|
|
ToLocationCode = jobDetail.ToLocationCode,
|
|
FromWarehouseCode = container.WarehouseCode,
|
|
ToWarehouseCode = entity.CustomerWarehouseCode,
|
|
FromStatus = balance.Status,
|
|
ToStatus = balance.Status,
|
|
ProductNo = balance.ProductNo,
|
|
Year = balance.Year,
|
|
ProjectCode = entity.ProjectCode,
|
|
Position = balance.Position,
|
|
SeqNo = balance.SeqNo,
|
|
SupplierBatch = balance.SupplierBatch,
|
|
ProduceDate = balance.ProduceDate,
|
|
ExpireDate = balance.ExpireDate,
|
|
ItemName = balance.ItemName,
|
|
ItemDesc1 = balance.ItemDesc1,
|
|
ItemDesc2 = balance.ItemDesc2,
|
|
Uom = balance.Uom,
|
|
Qty = balance.Qty,
|
|
|
|
};
|
|
return detailInput;
|
|
}
|
|
|
|
}
|
|
|