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.
134 lines
6.4 KiB
134 lines
6.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp;
|
|
using Volo.Abp.DependencyInjection;
|
|
using Volo.Abp.Domain.Entities.Events.Distributed;
|
|
using Volo.Abp.EventBus.Distributed;
|
|
using Volo.Abp.ObjectMapping;
|
|
using Volo.Abp.Uow;
|
|
using Win_in.Sfs.Shared.Domain.Shared;
|
|
using Win_in.Sfs.Shared.Event;
|
|
using Win_in.Sfs.Wms.Inventory.Domain;
|
|
|
|
namespace Win_in.Sfs.Wms.Inventory
|
|
{
|
|
/// <summary>
|
|
/// 检验记录触发的库存相关订阅事件
|
|
/// </summary>
|
|
public class InspectNoteCreatedEventHandler : IDistributedEventHandler<EntityCreatedEto<InspectNoteETO>>,
|
|
ITransientDependency
|
|
{
|
|
private readonly IObjectMapper _objectMapper;
|
|
private readonly IInventoryBalanceManager _inventoryBalanceManager;
|
|
private readonly IInventoryTransactionManager _inventoryTransactionManager;
|
|
public InspectNoteCreatedEventHandler(
|
|
IObjectMapper objectMapper,
|
|
IInventoryBalanceManager inventoryBalanceManager,
|
|
IInventoryTransactionManager inventoryTransactionManager
|
|
)
|
|
{
|
|
_objectMapper = objectMapper;
|
|
_inventoryBalanceManager = inventoryBalanceManager;
|
|
_inventoryTransactionManager = inventoryTransactionManager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检验记录创建时,根据不合格数量,报废数量分别变更库存状态;合格数量(未检数量+检验合格数量)不执行库存状态的变更,都是待检的状态。
|
|
/// </summary>
|
|
/// <param name="eventData"></param>
|
|
/// <returns></returns>
|
|
[UnitOfWork]
|
|
public virtual async Task HandleEventAsync(EntityCreatedEto<InspectNoteETO> eventData)
|
|
{
|
|
////判断
|
|
//Check.NotNull(eventData, nameof(eventData));
|
|
////订阅:检验记录创建时,根据不合格数量,报废数量分别变更库存状态;合格数量(未检数量+检验合格数量)不执行库存状态的变更,都是待检的状态。
|
|
//var entity = eventData.Entity;
|
|
////采购收货记录详细内容
|
|
//var details = eventData.Entity.Details;
|
|
|
|
//var balance = await _inventoryBalanceManager.UpdateFromInspectNoteAsync(eventData.Entity);
|
|
|
|
|
|
//List<InventoryBalance> inventoryBalances = new List<InventoryBalance>();
|
|
//try
|
|
//{
|
|
// foreach (var detail in details)
|
|
// {
|
|
// //1.先执行减少待检库存的操作
|
|
// var inventoryReduceInfo = _repository.FirstOrDefault(p => p.Company == entity.Company
|
|
// && p.PackingCode == detail.PackingCode && p.Status == EnumInventoryStatus.Inspect && p.LocationCode == detail.LocationCode && p.ItemCode == detail.ItemCode);
|
|
// if (inventoryReduceInfo != null)
|
|
// {
|
|
// //判断数量是否相等
|
|
|
|
// if (inventoryReduceInfo.Status == (EnumInventoryStatus)5)
|
|
// {
|
|
// throw new UserFriendlyException($"当前库存已【冻结】,不能使用,将执行回滚操作!");
|
|
// }
|
|
// inventoryReduceInfo.SetReduceQty(new Shared.Domain.UomQty
|
|
// {
|
|
// Uom = detail.ReceiveQty.Uom,
|
|
// Qty = detail.FailedQty + detail.CrackQty
|
|
// });
|
|
// }
|
|
|
|
// //2.根据状态查询有无当前物品不合格库存商品(更新不合格库存余额)
|
|
// var inventoryList = _repository.FirstOrDefault(p => p.Company == entity.Company
|
|
// && p.PackingCode == detail.PackingCode && p.Status == EnumInventoryStatus.UnQualified && p.LocationCode == detail.LocationCode && p.ItemCode == detail.ItemCode);
|
|
|
|
// if (inventoryList != null) //更新库存数量
|
|
// {
|
|
// if (inventoryList.Status == (EnumInventoryStatus)5)
|
|
// {
|
|
// throw new UserFriendlyException($"当前库存已【冻结】,不能使用,将执行回滚操作!");
|
|
// }
|
|
// //inventoryList.SetAddQty(entity.Qty);
|
|
// }
|
|
// else //执行新增操作
|
|
// {
|
|
// var inventoryBalance = new InventoryBalance();
|
|
// inventoryBalance.Company = entity.Company;
|
|
|
|
// inventoryBalance.PackingCode = detail.PackingCode;
|
|
// inventoryBalance.Item = detail.Item;
|
|
// inventoryBalance.ItemCode = detail.ItemCode;
|
|
// inventoryBalance.Batch = detail.Batch;
|
|
// inventoryBalance.Lot = detail.Lot;
|
|
// inventoryBalance.LocationCode = detail.LocationCode;
|
|
// inventoryBalance.PutInTime = DateTime.Now;
|
|
// inventoryBalance.ContainerCode = detail.ContainerCode;
|
|
// inventoryBalance.ExpireDate = DateTime.Now.AddYears(2);
|
|
// //新增不合格库存
|
|
// if (detail.FailedQty != 0)
|
|
// {
|
|
// detail.ReceiveQty.Qty = detail.FailedQty;
|
|
// inventoryBalance.Qty = detail.ReceiveQty;
|
|
// inventoryBalance.Status = EnumInventoryStatus.UnQualified;
|
|
// inventoryBalances.Add(inventoryBalance);
|
|
// }
|
|
// //新增破坏库存
|
|
// if (detail.CrackQty != 0)
|
|
// {
|
|
// detail.ReceiveQty.Qty = detail.CrackQty;
|
|
// inventoryBalance.Qty = detail.ReceiveQty;
|
|
// inventoryBalance.Status = EnumInventoryStatus.UnQualified;
|
|
// inventoryBalances.Add(inventoryBalance);
|
|
// }
|
|
// }
|
|
// }
|
|
// await _repository.InsertManyAsync(inventoryBalances);
|
|
|
|
//}
|
|
//catch (Exception e)
|
|
//{
|
|
// throw new UserFriendlyException($"检验记录创建时,根据不合格数量,报废数量分别变更库存状态失败!" + e.Message);
|
|
//}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|