| | |
| | | using Newtonsoft.Json; |
| | | using Quartz; |
| | | using SqlSugar; |
| | | using System.Text; |
| | | using System.Text.Json; |
| | | using WIDESEA_Core; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using ManualInboundTaskHandler = WIDESEAWCS_Tasks.ConveyorLineNewJob.ManualInbound.ManualInboundTaskHandler; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | | { |
| | |
| | | private readonly ILogger<CommonConveyorLineNewJob> _logger; |
| | | |
| | | /// <summary> |
| | | /// 目标地址到设备类型的映射 |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// </remarks> |
| | | private static List<string> AddressToDeviceType = new List<string> { "11020", "11028" }; |
| | | |
| | | /// <summary> |
| | | /// 构造函数 |
| | | /// </summary> |
| | | /// <param name="taskService">任务服务</param> |
| | |
| | | // MaxDegreeOfParallelism = Math.Min(childDeviceCodes.Count, Environment.ProcessorCount * 2), |
| | | //}; |
| | | |
| | | _logger.LogDebug("Execute:开始并行处理输送线 {DeviceCode},子设备数量: {Count}", conveyorLine.DeviceCode, childDeviceCodes.Count); |
| | | QuartzLogger.Debug($"开始并行处理输送线,子设备数量: {childDeviceCodes.Count}", conveyorLine.DeviceCode); |
| | | //_logger.LogDebug("Execute:开始并行处理输送线 {DeviceCode},子设备数量: {Count}", conveyorLine.DeviceCode, childDeviceCodes.Count); |
| | | //QuartzLogger.Debug($"开始并行处理输送线,子设备数量: {childDeviceCodes.Count}", conveyorLine.DeviceCode); |
| | | |
| | | // 并行处理每个子设备 |
| | | //Parallel.For(0, childDeviceCodes.Count, parallelOptions, i => |
| | |
| | | continue; |
| | | } |
| | | |
| | | // 如果 WCS_ACK 为 1,先清除(表示处理过上一次请求) |
| | | if (command.WCS_ACK == 1) |
| | | conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 0, childDeviceCode); |
| | | #region 检测是否需要空托盘 |
| | | |
| | | // ========== 检查特定位置是否有托盘 ========== |
| | | // 从配置中读取需要检查托盘的位置列表 |
| | |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | // ========== 检查 PLC_STB 标志 ========== |
| | | // 只有当 PLC_STB 为 1 时才处理任务 |
| | | if (command.PLC_STB != 1) |
| | | { |
| | | return Task.CompletedTask; |
| | | // 如果 WCS_ACK 为 1,先清除(表示处理过上一次请求) |
| | | if (command.WCS_ACK == 1) |
| | | conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)0, childDeviceCode); |
| | | |
| | | // 处理手动入库任务(起点为线体点位的任务) |
| | | try |
| | | { |
| | | var task = _taskService.QueryManualInboundTask(childDeviceCode); |
| | | if (task != null) |
| | | { |
| | | var handler = new ManualInboundTaskHandler(_taskService); |
| | | handler.WriteTaskToPlc(conveyorLine, childDeviceCode, task); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogError(ex, "处理手动入库任务异常"); |
| | | QuartzLogger.Error($"处理手动入库任务异常: {ex.Message}", "CommonConveyorLineNewJob", ex); |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | // ========== 处理无托盘条码的情况 ========== |
| | |
| | | _logger.LogDebug("Execute:子设备 {ChildDeviceCode} 无托盘条码,请求出库任务", childDeviceCode); |
| | | QuartzLogger.Debug($"子设备 {childDeviceCode} 无托盘条码,请求出库任务", conveyorLine.DeviceCode); |
| | | _conveyorLineDispatch.RequestOutbound(conveyorLine, command, childDeviceCode); |
| | | return Task.CompletedTask; |
| | | continue; |
| | | } |
| | | |
| | | // ========== 处理已有任务号的情况 ========== |
| | |
| | | { |
| | | case InExecuting: |
| | | // 入库执行中,调用下一地址处理 |
| | | _conveyorLineDispatch.RequestInNextAddress(conveyorLine, command, childDeviceCode); |
| | | |
| | | if (AddressToDeviceType.Contains(childDeviceCode)) |
| | | // 到达目标地址,调用入库完成 |
| | | _conveyorLineDispatch.ConveyorLineInFinish(conveyorLine, command, childDeviceCode); |
| | | else |
| | | // 未到达目标地址,调用入库下一地址处理 |
| | | _conveyorLineDispatch.RequestInNextAddress(conveyorLine, command, childDeviceCode); |
| | | break; |
| | | |
| | | case OutExecuting: |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |