From bf2aa9dd56432a74940ca1bb08fb4d7eaee37045 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 27 三月 2026 11:03:37 +0800
Subject: [PATCH] feat(WCS): 完善 WIDESEAWCS_Tasks 模块日志系统

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs |   41 +++++++++++++++++++++++++++++++++++------
 1 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
index 2177cbb..cad24d5 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
@@ -1,5 +1,6 @@
 using MapsterMapper;
 using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Logging;
 using Quartz;
 using SqlSugar;
 using System.Text.Json;
@@ -7,6 +8,7 @@
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_Core.LogHelper;
 using WIDESEAWCS_DTO.TaskInfo;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
@@ -70,6 +72,11 @@
         private readonly HttpClientHelper _httpClientHelper;
 
         /// <summary>
+        /// 鏃ュ織璁板綍鍣�
+        /// </summary>
+        private readonly ILogger<CommonConveyorLineNewJob> _logger;
+
+        /// <summary>
         /// 鏋勯�犲嚱鏁�
         /// </summary>
         /// <param name="taskService">浠诲姟鏈嶅姟</param>
@@ -77,16 +84,18 @@
         /// <param name="routerService">璺敱鏈嶅姟</param>
         /// <param name="mapper">瀵硅薄鏄犲皠鍣�</param>
         /// <param name="httpClientHelper">HTTP 瀹㈡埛绔府鍔╃被</param>
-        public CommonConveyorLineNewJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, HttpClientHelper httpClientHelper)
+        /// <param name="logger">鏃ュ織璁板綍鍣�</param>
+        public CommonConveyorLineNewJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, HttpClientHelper httpClientHelper, ILogger<CommonConveyorLineNewJob> logger)
         {
             _taskService = taskService;
             _taskExecuteDetailService = taskExecuteDetailService;
             _routerService = routerService;
             _mapper = mapper;
             _httpClientHelper = httpClientHelper;
+            _logger = logger;
 
             // 鍒濆鍖栬皟搴﹀鐞嗗櫒
-            _conveyorLineDispatch = new ConveyorLineDispatchHandler(_taskService, _taskExecuteDetailService, _routerService, _mapper);
+            _conveyorLineDispatch = new ConveyorLineDispatchHandler(_taskService, _taskExecuteDetailService, _routerService, _mapper, _logger);
         }
 
         /// <summary>
@@ -116,7 +125,8 @@
                     if (childDeviceCodes == null || childDeviceCodes.Count == 0)
                     {
                         // 娌℃湁瀛愯澶囷紝鐩存帴杩斿洖
-                        Console.WriteLine($"杈撻�佺嚎 {conveyorLine.DeviceCode} 娌℃湁瀛愯澶�");
+                        _logger.LogInformation("杈撻�佺嚎 {DeviceCode} 娌℃湁瀛愯澶�", conveyorLine.DeviceCode);
+                        QuartzLogger.Info($"杈撻�佺嚎 {conveyorLine.DeviceCode} 娌℃湁瀛愯澶�", conveyorLine.DeviceCode);
                         return Task.CompletedTask;
                     }
 
@@ -126,6 +136,9 @@
                         // 闄愬埗骞跺彂鏁帮細瀛愯澶囨暟閲忓拰 CPU 鏍稿績鏁�*2 鐨勮緝灏忓��
                         MaxDegreeOfParallelism = Math.Min(childDeviceCodes.Count, Environment.ProcessorCount * 2),
                     };
+
+                    _logger.LogDebug("Execute锛氬紑濮嬪苟琛屽鐞嗚緭閫佺嚎 {DeviceCode}锛屽瓙璁惧鏁伴噺: {Count}", conveyorLine.DeviceCode, childDeviceCodes.Count);
+                    QuartzLogger.Debug($"寮�濮嬪苟琛屽鐞嗚緭閫佺嚎锛屽瓙璁惧鏁伴噺: {childDeviceCodes.Count}", conveyorLine.DeviceCode);
 
                     // 骞惰澶勭悊姣忎釜瀛愯澶�
                     Parallel.For(0, childDeviceCodes.Count, parallelOptions, i =>
@@ -140,6 +153,8 @@
                             // 濡傛灉鍛戒护涓虹┖锛岃烦杩�
                             if (command == null)
                             {
+                                _logger.LogDebug("Execute锛氬瓙璁惧 {ChildDeviceCode} 鍛戒护涓虹┖锛岃烦杩�", childDeviceCode);
+                                QuartzLogger.Debug($"瀛愯澶� {childDeviceCode} 鍛戒护涓虹┖锛岃烦杩�", conveyorLine.DeviceCode);
                                 return;
                             }
 
@@ -164,6 +179,9 @@
                                     {
                                         // 娌℃湁浠诲姟锛屽悜 WMS 璇锋眰鍑哄簱鎵樼洏浠诲姟
                                         var position = checkPalletPositions.FirstOrDefault(x => x.Code == childDeviceCode);
+                                        _logger.LogInformation("Execute锛氭鏌ユ墭鐩樹綅缃� {ChildDeviceCode}锛岃姹俉MS鍑哄簱鎵樼洏浠诲姟", childDeviceCode);
+                                        QuartzLogger.Info($"妫�鏌ユ墭鐩樹綅缃� {childDeviceCode}锛岃姹俉MS鍑哄簱鎵樼洏浠诲姟", conveyorLine.DeviceCode);
+
                                         var responseResult = _httpClientHelper.Post<WebResponseContent>("GetOutBoundTrayTaskAsync", new CreateTaskDto()
                                         {
                                             WarehouseId = position.WarehouseId,
@@ -183,12 +201,19 @@
 
                             // ========== 妫�鏌� PLC_STB 鏍囧織 ==========
                             // 鍙湁褰� PLC_STB 涓� 1 鏃舵墠澶勭悊浠诲姟
-                            if (command.PLC_STB != 1) return;
+                            if (command.PLC_STB != 1)
+                            {
+                                _logger.LogDebug("Execute锛氬瓙璁惧 {ChildDeviceCode} PLC_STB 涓嶄负1锛岃烦杩�", childDeviceCode);
+                                QuartzLogger.Debug($"瀛愯澶� {childDeviceCode} PLC_STB 涓嶄负1锛岃烦杩�", conveyorLine.DeviceCode);
+                                return;
+                            }
 
                             // ========== 澶勭悊鏃犳墭鐩樻潯鐮佺殑鎯呭喌 ==========
                             // 鏃犳墭鐩樻潯鐮佹椂锛岃姹傚嚭搴撲换鍔�
                             if (command.Barcode.IsNullOrEmpty() || command.Barcode.Replace("\0", "") == "")
                             {
+                                _logger.LogDebug("Execute锛氬瓙璁惧 {ChildDeviceCode} 鏃犳墭鐩樻潯鐮侊紝璇锋眰鍑哄簱浠诲姟", childDeviceCode);
+                                QuartzLogger.Debug($"瀛愯澶� {childDeviceCode} 鏃犳墭鐩樻潯鐮侊紝璇锋眰鍑哄簱浠诲姟", conveyorLine.DeviceCode);
                                 _conveyorLineDispatch.RequestOutbound(conveyorLine, command, childDeviceCode);
                                 return;
                             }
@@ -200,6 +225,8 @@
                                 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);
                                     // 澶勭悊浠诲姟鐘舵�侊紙鏍规嵁鐘舵�佸垎鍙戝埌涓嶅悓鏂规硶锛�
                                     ProcessTaskState(conveyorLine, command, task, childDeviceCode);
                                     return;
@@ -209,7 +236,8 @@
                         catch (Exception innerEx)
                         {
                             // 璁板綍寮傚父锛屼絾涓嶅奖鍝嶅叾浠栧瓙璁惧鐨勫鐞�
-                            Console.Error.WriteLine($"{DateTime.UtcNow:O} [{childDeviceCode}] CorrelationId={correlationId} {innerEx}");
+                            _logger.LogError(innerEx, "Execute锛氬瓙璁惧 {ChildDeviceCode} 澶勭悊寮傚父锛孋orrelationId: {CorrelationId}", childDeviceCode, correlationId);
+                            QuartzLogger.Error($"瀛愯澶囧鐞嗗紓甯�: {innerEx.Message}", conveyorLine.DeviceCode, innerEx);
                         }
                     });
                 }
@@ -217,7 +245,8 @@
             catch (Exception ex)
             {
                 // 璁板綍鏁翠綋寮傚父
-                Console.Error.WriteLine(ex);
+                _logger.LogError(ex, "Execute锛氳緭閫佺嚎 {DeviceCode} 鎵ц寮傚父", ex.Message);
+                QuartzLogger.Error($"杈撻�佺嚎鎵ц寮傚父: {ex.Message}", "CommonConveyorLineNewJob", ex);
             }
             return Task.CompletedTask;
         }

--
Gitblit v1.9.3