| | |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using ManualInboundTaskHandler = WIDESEAWCS_Tasks.ConveyorLineNewJob.ManualInbound.ManualInboundTaskHandler; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | | { |
| | |
| | | if (childDeviceCodes == null || childDeviceCodes.Count == 0) |
| | | { |
| | | // 没有子设备,直接返回 |
| | | _logger.LogInformation("输送线 {DeviceCode} 没有子设备", conveyorLine.DeviceCode); |
| | | QuartzLogger.Info($"输送线 {conveyorLine.DeviceCode} 没有子设备", conveyorLine.DeviceCode); |
| | | QuartzLogHelper.LogInfo(_logger, "输送线 {DeviceCode} 没有子设备", $"输送线 {conveyorLine.DeviceCode} 没有子设备", conveyorLine.DeviceCode, conveyorLine.DeviceCode); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | |
| | | // 如果命令为空,跳过 |
| | | if (command == null) |
| | | { |
| | | _logger.LogDebug("Execute:子设备 {ChildDeviceCode} 命令为空,跳过", childDeviceCode); |
| | | QuartzLogger.Debug($"子设备 {childDeviceCode} 命令为空,跳过", conveyorLine.DeviceCode); |
| | | continue; |
| | | } |
| | | |
| | | #region 检测是否需要空托盘 |
| | | |
| | | // ========== 检查特定位置是否有托盘 ========== |
| | | // 从配置中读取需要检查托盘的位置列表 |
| | |
| | | { |
| | | // 没有任务,向 WMS 请求出库托盘任务 |
| | | var position = checkPalletPositions.FirstOrDefault(x => x.Code == childDeviceCode); |
| | | _logger.LogInformation("Execute:检查托盘位置 {ChildDeviceCode},请求WMS出库托盘任务", childDeviceCode); |
| | | QuartzLogger.Info($"检查托盘位置 {childDeviceCode},请求WMS出库托盘任务", conveyorLine.DeviceCode); |
| | | QuartzLogHelper.LogInfo(_logger, "Execute:检查托盘位置 {ChildDeviceCode},请求WMS出库托盘任务", $"检查托盘位置 {childDeviceCode},请求WMS出库托盘任务", conveyorLine.DeviceCode, childDeviceCode); |
| | | |
| | | var responseResult = _httpClientHelper.Post<WebResponseContent>("GetOutBoundTrayTaskAsync", new CreateTaskDto() |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | // ========== 检查 PLC_STB 标志 ========== |
| | | // 只有当 PLC_STB 为 1 时才处理任务 |
| | | if (command.PLC_STB != 1) |
| | |
| | | // 如果 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) |
| | | { |
| | | QuartzLogHelper.LogError(_logger, ex, "处理手动入库任务异常", $"处理手动入库任务异常: {ex.Message}", "CommonConveyorLineNewJob"); |
| | | } |
| | | continue; |
| | | } |
| | | |
| | |
| | | // 无托盘条码时,请求出库任务 |
| | | if (command.Barcode.IsNullOrEmpty() || command.Barcode.Replace("\0", "") == "") |
| | | { |
| | | _logger.LogDebug("Execute:子设备 {ChildDeviceCode} 无托盘条码,请求出库任务", childDeviceCode); |
| | | QuartzLogger.Debug($"子设备 {childDeviceCode} 无托盘条码,请求出库任务", conveyorLine.DeviceCode); |
| | | _conveyorLineDispatch.RequestOutbound(conveyorLine, command, childDeviceCode); |
| | | continue; |
| | | } |
| | |
| | | Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNo, childDeviceCode); |
| | | if (!task.IsNullOrEmpty()) |
| | | { |
| | | _logger.LogInformation("Execute:子设备 {ChildDeviceCode} 处理任务 {TaskNum},状态: {Status}", childDeviceCode, task.TaskNum, task.TaskStatus); |
| | | QuartzLogger.Info($"处理任务 {task.TaskNum},状态: {task.TaskStatus}", conveyorLine.DeviceCode); |
| | | QuartzLogHelper.LogInfo(_logger, "Execute:子设备 {ChildDeviceCode} 处理任务 {TaskNum},状态: {Status}", $"处理任务 {task.TaskNum},状态: {task.TaskStatus}", conveyorLine.DeviceCode, childDeviceCode, task.TaskNum, task.TaskStatus); |
| | | // 处理任务状态(根据状态分发到不同方法) |
| | | ProcessTaskState(conveyorLine, command, task, childDeviceCode); |
| | | return Task.CompletedTask; |
| | |
| | | catch (Exception innerEx) |
| | | { |
| | | // 记录异常,但不影响其他子设备的处理 |
| | | _logger.LogError(innerEx, "Execute:子设备 {ChildDeviceCode} 处理异常,CorrelationId: {CorrelationId}", childDeviceCode, correlationId); |
| | | QuartzLogger.Error($"子设备处理异常: {innerEx.Message}", conveyorLine.DeviceCode, innerEx); |
| | | QuartzLogHelper.LogError(_logger, innerEx, "Execute:子设备 {ChildDeviceCode} 处理异常,CorrelationId: {CorrelationId}", $"子设备处理异常: {innerEx.Message}", conveyorLine.DeviceCode, childDeviceCode, correlationId); |
| | | } |
| | | } |
| | | } |
| | |
| | | catch (Exception ex) |
| | | { |
| | | // 记录整体异常 |
| | | _logger.LogError(ex, "Execute:输送线 {DeviceCode} 执行异常", ex.Message); |
| | | QuartzLogger.Error($"输送线执行异常: {ex.Message}", "CommonConveyorLineNewJob", ex); |
| | | QuartzLogHelper.LogError(_logger, ex, "Execute:输送线 {DeviceCode} 执行异常", $"输送线执行异常: {ex.Message}", "CommonConveyorLineNewJob", ex.Message); |
| | | } |
| | | return Task.CompletedTask; |
| | | } |