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 { /// /// 扫描输入命令处理程序 /// public sealed class ScanOutputsCommandHandler : CommandHandler { private readonly IWcsRepository _wcsRepository; // 控制仓库 private readonly TaskProxy _taskProxy; // 任务代理 /// /// 依赖注入 /// public ScanOutputsCommandHandler( IWcsRepository wcsRepository, TaskProxy taskProxy) { _wcsRepository = wcsRepository; _taskProxy = taskProxy; } /// /// 处理程序 /// public override async Task Handle(ScanOutputsCommand command, CancellationToken cancellationToken) { var queue = new Queue(); 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); } } }