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.
59 lines
2.0 KiB
59 lines
2.0 KiB
using Kean.Domain.Wcs.Commands;
|
|
using Kean.Domain.Wcs.Models;
|
|
using Kean.Domain.Wcs.Repositories;
|
|
using Kean.Domain.Wcs.SharedServices.Proxies;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Kean.Domain.Wcs.CommandHandlers
|
|
{
|
|
/// <summary>
|
|
/// 扫描输入命令处理程序
|
|
/// </summary>
|
|
public sealed class ScanOutputsCommandHandler : CommandHandler<ScanOutputsCommand>
|
|
{
|
|
private readonly IWcsRepository _wcsRepository; // 控制仓库
|
|
private readonly TaskProxy _taskProxy; // 任务代理
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
public ScanOutputsCommandHandler(
|
|
IWcsRepository wcsRepository,
|
|
TaskProxy taskProxy)
|
|
{
|
|
_wcsRepository = wcsRepository;
|
|
_taskProxy = taskProxy;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理程序
|
|
/// </summary>
|
|
public override async Task Handle(ScanOutputsCommand command, CancellationToken cancellationToken)
|
|
{
|
|
var queue = new Queue<Output>();
|
|
foreach (var item in await _wcsRepository.GetOutputs())
|
|
{
|
|
if (item.State != item.PreState)
|
|
{
|
|
if (item.State == 995 && item.PreState == 996)
|
|
{
|
|
await _wcsRepository.SyncOutput(item.Id, item.State);
|
|
await _taskProxy.SetTaskState(item.Task, string.Empty, "Running", string.Empty, "Task");
|
|
}
|
|
else
|
|
{
|
|
queue.Enqueue(item);
|
|
}
|
|
}
|
|
else if (item.State == 900 || item.State == 999)
|
|
{
|
|
await _wcsRepository.RemoveOutput(item.Id);
|
|
await _wcsRepository.LogOutput(item);
|
|
}
|
|
}
|
|
Output(nameof(command.UnsyncedOutputs), queue);
|
|
}
|
|
}
|
|
}
|