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.
87 lines
3.0 KiB
87 lines
3.0 KiB
3 months ago
|
using Kean.Domain.Stock.Commands;
|
||
|
using Kean.Domain.Stock.Repositories;
|
||
|
using System.Linq;
|
||
|
using System.Threading;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
namespace Kean.Domain.Stock.CommandHandlers
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 命令处理程序
|
||
|
/// </summary>
|
||
|
public sealed class PreSetQcStatusCommandHandler : CommandHandler<PreSetQcStatusCommand>
|
||
|
{
|
||
|
private readonly ICommandBus _commandBus; // 命令总线
|
||
|
private readonly IStockRepository _stockRepository; // 存储仓库
|
||
|
|
||
|
/// <summary>
|
||
|
/// 依赖注入
|
||
|
/// </summary>
|
||
|
public PreSetQcStatusCommandHandler(
|
||
|
ICommandBus commandBus,
|
||
|
IStockRepository stockRepository)
|
||
|
{
|
||
|
_commandBus = commandBus;
|
||
|
_stockRepository = stockRepository;
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 处理程序
|
||
|
/// </summary>
|
||
|
public override async Task Handle(PreSetQcStatusCommand command, CancellationToken cancellationToken)
|
||
|
{
|
||
|
if (command.ValidationResult.IsValid)
|
||
|
{
|
||
|
if (command.BarcodeList != null)
|
||
|
{
|
||
|
foreach (var r in command.BarcodeList)
|
||
|
{
|
||
|
SetQcStatusCommand setQcStatuscommand = new SetQcStatusCommand();
|
||
|
setQcStatuscommand.Barcode = r;
|
||
|
setQcStatuscommand.Enable = command.Enable;
|
||
|
setQcStatuscommand.Message = command.Supplier;
|
||
|
setQcStatuscommand.Operator = command.Operator;
|
||
|
|
||
|
await _commandBus.Execute(setQcStatuscommand, cancellationToken);
|
||
|
}
|
||
|
|
||
|
Output(nameof(command.BarcodeCount), command.BarcodeList.Count());
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
var barcodes = await this._stockRepository.GetQcBarcode(command.GoodsCode,
|
||
|
command.Batch,
|
||
|
command.ManufacturingDateFrom,
|
||
|
command.ManufacturingDateTo,
|
||
|
command.InboundTimeFrom,
|
||
|
command.InboundTimeTo,
|
||
|
command.Barcode,
|
||
|
command.Supplier,
|
||
|
command.Enable);
|
||
|
|
||
|
foreach (var r in barcodes)
|
||
|
{
|
||
|
SetQcStatusCommand setQcStatuscommand = new SetQcStatusCommand();
|
||
|
setQcStatuscommand.Barcode = r.Barcode;
|
||
|
setQcStatuscommand.Enable = command.Enable;
|
||
|
setQcStatuscommand.Message = command.Supplier;
|
||
|
setQcStatuscommand.Operator = command.Operator;
|
||
|
|
||
|
await _commandBus.Execute(setQcStatuscommand, cancellationToken);
|
||
|
}
|
||
|
|
||
|
Output(nameof(command.BarcodeCount), barcodes.Count());
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
await _commandBus.Notify(command.ValidationResult,
|
||
|
cancellationToken: cancellationToken);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|