wanshenmean
6 小时以前 853f7a71577bd8694c848985e1eb21c74d30eba9
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineDispatchHandler.cs
@@ -1,12 +1,11 @@
using MapsterMapper;
using Microsoft.Extensions.Logging;
using Serilog;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
namespace WIDESEAWCS_Tasks
@@ -105,7 +104,7 @@
        {
            // 清除任务号,表示当前空闲
            conveyorLine.SetValue(ConveyorLineDBNameNew.TaskNo, 0, childDeviceCode);
            QuartzLogHelper.LogDebug(_logger, "HeartBeat:子设备 {ChildDeviceCode} 心跳", $"HeartBeat:子设备 {childDeviceCode} 心跳", conveyorLine.DeviceCode, childDeviceCode);
            QuartzLogHelper.LogDebug(_logger, $"HeartBeat:子设备 {childDeviceCode} 心跳", conveyorLine.DeviceCode);
        }
        /// <summary>
@@ -124,7 +123,7 @@
        /// <param name="childDeviceCode">子设备编码</param>
        public void RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode)
        {
            QuartzLogHelper.LogInfo(_logger, "RequestInbound:子设备 {ChildDeviceCode} 请求入库", $"请求入库,子设备: {childDeviceCode}", conveyorLine.DeviceCode, childDeviceCode);
            QuartzLogHelper.LogInfo(_logger, $"请求入库,子设备: {childDeviceCode}", conveyorLine.DeviceCode);
            // 向 WMS 请求新任务(基于条码)
            if (_taskFilter.RequestWmsTask(command.Barcode, childDeviceCode))
@@ -145,7 +144,7 @@
                    // 更新任务状态到下一阶段
                    _taskService.UpdateTaskStatusToNext(task);
                    QuartzLogHelper.LogInfo(_logger, "RequestInbound:入库任务已下发,任务号: {TaskNum},子设备: {ChildDeviceCode}", $"入库任务已下发,任务号: {task.TaskNum},子设备: {childDeviceCode}", conveyorLine.DeviceCode, task.TaskNum, childDeviceCode);
                    QuartzLogHelper.LogInfo(_logger, $"入库任务已下发,任务号: {task.TaskNum},子设备: {childDeviceCode}", conveyorLine.DeviceCode);
                }
            }
        }
@@ -166,17 +165,21 @@
            Dt_Task? task = _taskFilter.QueryExecutingTask(command.TaskNo, childDeviceCode);
            if (task == null)
            {
                QuartzLogHelper.LogDebug(_logger, "RequestInNextAddress:任务 {TaskNo} 不存在", $"RequestInNextAddress:任务 {command.TaskNo} 不存在", conveyorLine.DeviceCode, command.TaskNo);
                QuartzLogHelper.LogDebug(_logger, $"RequestInNextAddress:任务 {command.TaskNo} 不存在", conveyorLine.DeviceCode);
                return;
            }
            QuartzLogHelper.LogInfo(_logger, "RequestInNextAddress:入库下一地址,任务号: {TaskNum},子设备: {ChildDeviceCode}", $"RequestInNextAddress:入库下一地址,任务号: {task.TaskNum},子设备: {childDeviceCode}", conveyorLine.DeviceCode, task.TaskNum, childDeviceCode);
            QuartzLogHelper.LogInfo(_logger, $"RequestInNextAddress:入库下一地址,任务号: {task.TaskNum},子设备: {childDeviceCode}", conveyorLine.DeviceCode);
            // 如果不是空托盘任务,处理目标地址(与拘束机/插拔钉机交互)
            if (task.TaskType != (int)TaskOutboundTypeEnum.OutEmpty)
            {
                _targetAddressSelector.HandleInboundNextAddress(conveyorLine, task.NextAddress, childDeviceCode);
            }
            //// 如果不是空托盘任务,处理目标地址
            //if (task.TaskType != (int)TaskOutboundTypeEnum.OutEmpty)
            //{
            Dt_Router routers = _routerService.QueryNextRoute(task.NextAddress, task.TargetAddress);
            if (routers == null) throw new Exception($"未找到设备路由信息");
            _targetAddressSelector.HandleInboundNextAddress(conveyorLine, routers.ChildPosi, childDeviceCode);
            //}
            // 更新任务当前位置
            _ = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
@@ -201,16 +204,13 @@
            Dt_Task? task = _taskFilter.QueryExecutingTask(command.TaskNo, childDeviceCode);
            if (task != null)
            {
                // 更新任务状态到下一阶段(通常是完成)
                if (_taskService.UpdateTaskStatusToNext(task).Status)
                {
                    // 回复 ACK 确认
                    conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
                    QuartzLogHelper.LogInfo(_logger, "ConveyorLineInFinish:入库完成,任务号: {TaskNum},子设备: {ChildDeviceCode}", $"入库完成,任务号: {task.TaskNum}", conveyorLine.DeviceCode, task.TaskNum, childDeviceCode);
                    QuartzLogHelper.LogInfo(_logger, $"入库完成,任务号: {task.TaskNum},子设备:{childDeviceCode}", conveyorLine.DeviceCode);
                }
            }
        }
@@ -268,17 +268,20 @@
            Dt_Task? task = _taskFilter.QueryExecutingTask(command.TaskNo, childDeviceCode);
            if (task == null)
            {
                QuartzLogHelper.LogDebug(_logger, "RequestOutNextAddress:任务 {TaskNo} 不存在", $"RequestOutNextAddress:任务 {command.TaskNo} 不存在", conveyorLine.DeviceCode, command.TaskNo);
                QuartzLogHelper.LogDebug(_logger, $"RequestOutNextAddress:任务 {command.TaskNo} 不存在", conveyorLine.DeviceCode);
                return;
            }
            QuartzLogHelper.LogInfo(_logger, "RequestOutNextAddress:出库下一地址,任务号: {TaskNum},子设备: {ChildDeviceCode}", $"RequestOutNextAddress:出库下一地址,任务号: {task.TaskNum},子设备: {childDeviceCode}", conveyorLine.DeviceCode, task.TaskNum, childDeviceCode);
            QuartzLogHelper.LogInfo(_logger, $"RequestOutNextAddress:出库下一地址,任务号: {task.TaskNum},子设备: {childDeviceCode}", conveyorLine.DeviceCode);
            // 如果不是空托盘任务,处理目标地址
            if (task.TaskType != (int)TaskOutboundTypeEnum.OutEmpty)
            {
                _targetAddressSelector.HandleOutboundNextAddress(conveyorLine, task.NextAddress, childDeviceCode);
            }
            //if (task.TaskType != (int)TaskOutboundTypeEnum.OutEmpty)
            //{
            Dt_Router routers = _routerService.QueryNextRoute(task.NextAddress, task.TargetAddress);
            if (routers == null) throw new Exception($"未找到设备路由信息");
            _targetAddressSelector.HandleOutboundNextAddress(conveyorLine, routers.ChildPosi, childDeviceCode);
            //}
            // 更新任务当前位置
            _ = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
@@ -312,8 +315,8 @@
                    conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
                }
                QuartzLogHelper.LogInfo(_logger, "ConveyorLineOutFinish:出库完成,完成结果:{Status},任务号: {TaskNum},子设备: {ChildDeviceCode},错误消息: {Message}", $"出库完成,完成结果:{content.Status},任务号: {task.TaskNum},错误消息:{content.Message}", conveyorLine.DeviceCode, content.Status, task.TaskNum, childDeviceCode, content.Message);
                QuartzLogHelper.LogInfo(_logger, $"出库完成,完成结果:{content.Status},任务号: {task.TaskNum},错误消息:{content.Message}", conveyorLine.DeviceCode);
            }
        }
    }
}
}