using Kean.Domain.Stock.Enums;
using Kean.Domain.Stock.Repositories;
using Kean.Domain.Stock.SharedServices.Proxies;
using System.Linq;
using System.Threading.Tasks;
namespace Kean.Domain.Stock.Strategies
{
///
/// 默认状态判定策略
///
public sealed class StateStrategy_Default : StateStrategy
{
private readonly IStockRepository _stockRepository; // 存储仓库
private readonly MaterialProxy _materialProxy;
///
/// 依赖注入
///
public StateStrategy_Default(
IStockRepository stockRepository,
MaterialProxy materialProxy)
{
_stockRepository = stockRepository;
_materialProxy = materialProxy;
}
/*
* 实现 Kean.Domain.Stock.Strategies.StateStrategy.GetState 方法
*/
public override async Task GetState(string barcode)
{
var stock = await _stockRepository.GetStock(barcode);
if (stock == null)
{
return CellState.Empty;
}
if (stock.Full == true)
{
return CellState.Full;
}
else
{
if (await _materialProxy.IsPallet(stock.Lines.Any() ? stock.Lines.First().Material : 0))
{
return CellState.Pallet;
}
else
{
return CellState.Have;
}
}
}
}
}