using Kean.Application.Command.Interfaces;
using Kean.Application.Command.ViewModels;
using Kean.Domain;
using Kean.Domain.Stock.Commands;
using Orleans;
using System.Linq;
using System.Threading.Tasks;
namespace Kean.Application.Command.Implements
{
///
/// 库存交互颗粒
///
internal class StockGrain : Grain, IStockGrain
{
private readonly ICommandBus _bus; // 命令总线
private readonly INotification _notifications; // 总线通知
///
/// 依赖注入
///
public StockGrain(
ICommandBus bus,
INotification notifications)
{
_bus = bus;
_notifications = notifications;
}
/*
* 实现 Kean.Application.Command.Interfaces.IStockGrain.Inbound 方法
*/
public async Task Inbound(InboundCommand command)
{
DeactivateOnIdle();
await _bus.Execute(command);
return _notifications.FirstOrDefault();
}
/*
* 实现 Kean.Application.Command.Interfaces.IStockGrain.Outbound 方法
*/
public async Task Outbound(OutboundCommand command)
{
DeactivateOnIdle();
await _bus.Execute(command);
return _notifications.FirstOrDefault();
}
/*
* 实现 Kean.Application.Command.Interfaces.IStockGrain.Update 方法
*/
public async Task Update(UpdateCommand command)
{
DeactivateOnIdle();
await _bus.Execute(command);
return _notifications.FirstOrDefault();
}
/*
* 实现 Kean.Application.Command.Interfaces.IStockGrain.Combine 方法
*/
public async Task Combine(CombineCommand command)
{
DeactivateOnIdle();
await _bus.Execute(command);
return _notifications.FirstOrDefault();
}
/*
* 实现 Kean.Application.Command.Interfaces.IStockGrain.Inventory 方法
*/
public async Task Inventory(InventoryCommand command)
{
DeactivateOnIdle();
await _bus.Execute(command);
return _notifications.FirstOrDefault();
}
////////////////////////////////////////////////
/*
* 实现 Kean.Application.Command.Interfaces.IStockGrain.ScanInbound 方法
*/
public async Task<(string Device, Failure Failure)> ScanInbound(ScanInboundCommand command)
{
DeactivateOnIdle();
await _bus.Execute(command);
return (command.Tag, _notifications.FirstOrDefault());
}
/*
* 实现 Kean.Application.Command.Interfaces.IStockGrain.PalletIn 方法
*/
public async Task PalletIn(PalletInCommand command)
{
DeactivateOnIdle();
await _bus.Execute(command);
return _notifications.FirstOrDefault();
}
/*
* 实现 Kean.Application.Command.Interfaces.IStockGrain.PreScanInbound 方法
*/
public async Task<(string Device, Failure Failure)> PreScanInbound(PreScanInboundCommand command)
{
DeactivateOnIdle();
await _bus.Execute(command);
return (command.Source, _notifications.FirstOrDefault());
}
/*
* 实现 Kean.Application.Command.Interfaces.IStockGrain.RecordInterface 方法
*/
public async Task RecordInterface(InterfaceRecordCommand command)
{
DeactivateOnIdle();
await _bus.Execute(command);
return _notifications.FirstOrDefault();
}
/*
* 实现 Kean.Application.Command.Interfaces.IStockGrain.SetRollResult 方法
*/
public async Task SetRollResult(SetRollResultCommand command)
{
DeactivateOnIdle();
await _bus.Execute(command);
return _notifications.FirstOrDefault();
}
/*
* 实现 Kean.Application.Command.Interfaces.IStockGrain.PreScanInbound 方法
*/
public async Task<(int barcodeCount, Failure Failure)> PreSetQcStatus(PreSetQcStatusCommand command)
{
DeactivateOnIdle();
await _bus.Execute(command);
return (command.BarcodeCount, _notifications.FirstOrDefault());
}
/*
* 实现 Kean.Application.Command.Interfaces.IStockGrain.ChangeStorageProperty 方法
*/
public async Task ChangeStorageProperty(ChangeStoragePropertyCommand command)
{
DeactivateOnIdle();
await _bus.Execute(command);
return _notifications.FirstOrDefault();
}
/*
* 实现 Kean.Application.Command.Interfaces.IStockGrain.BatchReFeedback 方法
*/
public async Task BatchReFeedback(BatchReFeedbackCommand command)
{
DeactivateOnIdle();
await _bus.Execute(command);
return _notifications.FirstOrDefault();
}
}
}