From a95c4e748b01da8bea6ba0f8e6af9c281bc582d7 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期二, 29 七月 2025 09:22:13 +0800
Subject: [PATCH] 优化日志格式并增强库存查询逻辑在 CommonConveyorLineJob.cs和CommonConveyorLine_GWJob.cs文件中,修改了日志输出格式,添加了时间戳以提高可读性和可追溯性。部分代码中的ToJsonString()方法被替换为 Serialize()方法,以统一序列化方式。与此同时,在 Dt_TaskService.cs文件中增加了库存信息查询逻辑,以确保出库时能够正确处理库存条件,增强系统的健壮性。

---
 Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs       |   10 +++++-----
 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs      |    1 +
 Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs |   21 +++++++++++----------
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
index 9c2148b..bb94546 100644
--- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
+++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -307,7 +307,7 @@
             try
             {
                 // 杈撳嚭璀﹀憡淇℃伅锛岃〃绀轰换鍔″凡鍒拌揪瀛愯澶囧苟璇锋眰鎵爜鍏ュ簱
-                var log = $"銆恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣姹傛壂鐮佸叆搴�";
+                var log = $"鏃堕棿锛氥�恵DateTime.Now}銆戙�恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣姹傛壂鐮佸叆搴�";
                 ConsoleHelper.WriteWarningLine(log);
                 // 鍙戦�侀�氱煡
                 await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
@@ -334,7 +334,7 @@
                         conveyorLine.SendCommand(taskCommand, childDeviceCode);
 
                         // 杈撳嚭璀﹀憡淇℃伅锛岃〃绀轰换鍔″凡鍒拌揪瀛愯澶囧苟璇锋眰鎵爜鍏ュ簱锛屼笅涓�鐩爣鍦板潃
-                        var logs = $"銆恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣姹傛壂鐮佸叆搴�,涓嬩竴鐩爣鍦板潃銆恵taskCommand.TargetAddress}銆�";
+                        var logs = $"鏃堕棿锛氥�恵DateTime.Now}銆戙�恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣姹傛壂鐮佸叆搴�,涓嬩竴鐩爣鍦板潃銆恵taskCommand.TargetAddress}銆�";
                         ConsoleHelper.WriteWarningLine(logs);
 
                         await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = logs, time = DateTime.Now.ToString("G"), color = "red" });
@@ -376,7 +376,7 @@
         /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
         public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
         {
-            var log = $"銆恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣姹傚叆搴撲笅涓�鍦板潃";
+            var log = $"鏃堕棿锛氥�恵DateTime.Now}銆戙�恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣姹傚叆搴撲笅涓�鍦板潃";
             ConsoleHelper.WriteWarningLine(log);
 
             _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
@@ -422,7 +422,7 @@
         {
             try
             {
-                var log = $"銆恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣緭閫佺嚎鍏ュ簱瀹屾垚";
+                var log = $"鏃堕棿锛氥�恵DateTime.Now}銆戙�恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣緭閫佺嚎鍏ュ簱瀹屾垚";
                 ConsoleHelper.WriteWarningLine(log);
 
                 _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
@@ -504,7 +504,7 @@
                 var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
 
                 // 杈撳嚭鎴愬姛淇℃伅锛屽寘鎷緭閫佺嚎鍚嶇О銆佷换鍔″彿銆佹墭鐩樻潯鐮佸拰瀛愯澶囦唬鐮侊紝浠ュ強浠诲姟淇℃伅
-                var logs = $"銆恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣緭閫佺嚎璇锋眰鍑哄簱,task{task.ToJsonString()}";
+                var logs = $"鏃堕棿锛氥�恵DateTime.Now}銆戙�恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵command.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵command.Barcode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣緭閫佺嚎璇锋眰鍑哄簱,task{task.ToJsonString()}";
                 ConsoleHelper.WriteSuccessLine(logs);
 
                 _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = logs, time = DateTime.Now.ToString("G"), color = "red" });
diff --git a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs
index b710291..cc448ff 100644
--- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs
+++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs
@@ -21,6 +21,7 @@
 
 using AutoMapper;
 using HslCommunication;
+using Masuit.Tools;
 using Microsoft.CodeAnalysis;
 using Newtonsoft.Json;
 using Quartz;
@@ -150,7 +151,6 @@
                                 }
                             }
                         }
-
                         #region 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇
 
                         var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken");
@@ -170,6 +170,8 @@
                         _noticeService.LineData(userIds?.FirstOrDefault(), userTokenIds, new { conveyorLine.DeviceName, data = obj });
 
                         #endregion 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇
+
+
                     }
 
                     #endregion 璺敱鏂瑰紡
@@ -199,7 +201,7 @@
             try
             {
                 var task = _taskService.QueryBarCodeConveyorLineTask(command.ConveyorLineBarcode, childDeviceCode);
-                var log = $"銆恵conveyorLine.DeviceName}銆戞墭鐩樺彿锛氥�恵command.ConveyorLineBarcode}銆戜换鍔″彿锛氥�恵command.ConveyorLineTaskNum}銆戣澶囩紪鐮侊細銆恵childDeviceCode}銆�";
+                var log = $"鏃堕棿锛氥�恵DateTime.Now}銆戙�恵conveyorLine.DeviceName}銆戞墭鐩樺彿锛氥�恵command.ConveyorLineBarcode}銆戜换鍔″彿锛氥�恵command.ConveyorLineTaskNum}銆戣澶囩紪鐮侊細銆恵childDeviceCode}銆�";
                 ConsoleHelper.WriteSuccessLine(log);
 
                 _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
@@ -214,11 +216,10 @@
                     var GWTask = _taskRepository.QueryData(x => x.Roadway.Contains("GWSC2") && x.SourceAddress == "1039" && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskInStatusEnum.Line_InFinish)).ToList();
                     if (GWTask.Count >= 2 && childDeviceCode == "1039" && task.Roadway.Contains("GWSC2"))
                     {
-                        ConsoleHelper.WriteErrorLine($"鎵樼洏鍙凤細銆恵command.ConveyorLineBarcode}銆戦珮娓╀簩宸插瓨鍦ㄣ�恵GWTask.Count}銆戜釜浠诲姟澶т簬2涓换鍔′笉鍙笅鍙�");
+                        ConsoleHelper.WriteErrorLine($"鏃堕棿锛氥�恵DateTime.Now}銆戞墭鐩樺彿锛氥�恵command.ConveyorLineBarcode}銆戦珮娓╀簩宸插瓨鍦ㄣ�恵GWTask.Count}銆戜釜浠诲姟澶т簬2涓换鍔′笉鍙笅鍙�");
                         return;
                     }
                     ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
-                    //conveyorLine.SendCommand(taskCommand, childDeviceCode);
 
                     bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode);
                     if (sendFlag)
@@ -360,8 +361,8 @@
 
                 var MOMIpAddress = wmsBase + ipAddress;
 
-                var result = HttpHelper.PostAsync(MOMIpAddress, trayCells.ToJsonString()).Result;
-                WriteInfo("鍏ョ珯鏍¢獙", $"銆恵childDeviceCode}銆戝叆绔欐牎楠岃姹傚弬鏁般�恵trayCells.ToJsonString()}銆�");
+                var result = HttpHelper.PostAsync(MOMIpAddress, trayCells.Serialize()).Result;
+                WriteInfo("鍏ョ珯鏍¢獙", $"銆恵childDeviceCode}銆戝叆绔欐牎楠岃姹傚弬鏁般�恵trayCells.Serialize()}銆�");
                 WriteInfo("鍏ョ珯鏍¢獙", "");
                 WriteInfo("鍏ョ珯鏍¢獙", $"銆恵childDeviceCode}銆戝叆绔欐牎楠岃繑鍥炲弬鏁般�恵result}銆�");
                 ResultTrayCellsStatus result1 = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(result);
@@ -405,7 +406,7 @@
         /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
         public void ConveyorLineOutFinish(CommonConveyorLine_GW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
         {
-            var log = $"銆恵conveyorLine.DeviceName}銆戞墭鐩樺彿锛氥�恵command.ConveyorLineBarcode}銆戜换鍔″彿锛氥�恵command.ConveyorLineTaskNum}銆戣澶囩紪鐮侊細銆恵childDeviceCode}銆�";
+            var log = $"鏃堕棿锛氥�恵DateTime.Now}銆戙�恵conveyorLine.DeviceName}銆戞墭鐩樺彿锛氥�恵command.ConveyorLineBarcode}銆戜换鍔″彿锛氥�恵command.ConveyorLineTaskNum}銆戣澶囩紪鐮侊細銆恵childDeviceCode}銆�";
             ConsoleHelper.WriteSuccessLine(log);
 
             _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
@@ -539,7 +540,7 @@
                 //var deviceCode = device.Select(x => x.DeviceCode).ToList();
                 List<string> strings = platform.Location.Split(',').ToList();
 
-                var result = await HttpHelper.PostAsync(wmsIpAddress, new { Position = childDeviceCode, Tag = (int)taskType, AreaCdoe = platform.Stacker, AreaCdoes = strings, platform.ProductionLine }.ToJsonString());
+                var result = await HttpHelper.PostAsync(wmsIpAddress, new { Position = childDeviceCode, Tag = (int)taskType, AreaCdoe = platform.Stacker, AreaCdoes = strings, platform.ProductionLine }.Serialize());
                 //var result = await HttpHelper.PostAsync("http://localhost:5000/api/Task/RequestTrayOutTaskAsync", dynamic.ToJsonString());
 
                 WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result);
@@ -583,7 +584,7 @@
                 {
                     if (command.ConveyorLineBarcode == taskCommand.ConveyorLineBarcode && command.ConveyorLineTaskNum == taskCommand.ConveyorLineTaskNum && command.ConveyorLineTargetAddress == taskCommand.ConveyorLineTargetAddress)
                     {
-                        WriteInfo(conveyorLine.DeviceName, $"鍐欏叆浠诲姟鎴愬姛鍐欏叆娆℃暟{i}鍐欏叆浠诲姟銆恵JsonConvert.SerializeObject(taskCommand)}銆�");
+                        WriteInfo(conveyorLine.DeviceName, $"鏃堕棿锛氥�恵DateTime.Now}銆戝啓鍏ヤ换鍔℃垚鍔熷啓鍏ユ鏁皗i}鍐欏叆浠诲姟銆恵JsonConvert.SerializeObject(taskCommand)}銆�");
                         return true;
                     }
                     if (command.ConveyorLineTargetAddress != taskCommand.ConveyorLineTargetAddress)
@@ -603,7 +604,7 @@
 
                 }
             }
-            WriteInfo(conveyorLine.DeviceName, $"鍐欏叆浠诲姟澶辫触浠诲姟鍙枫�恵taskCommand.ConveyorLineTaskNum}銆戞墭鐩樺彿銆恵taskCommand.ConveyorLineBarcode}銆戠洰鏍囧湴鍧�銆恵taskCommand.ConveyorLineTargetAddress}銆戝綋鍓嶈妭鐐广�恵childDeviceCode}銆�");
+            WriteInfo(conveyorLine.DeviceName, $"鏃堕棿锛氥�恵DateTime.Now}銆戝啓鍏ヤ换鍔″け璐ヤ换鍔″彿銆恵taskCommand.ConveyorLineTaskNum}銆戞墭鐩樺彿銆恵taskCommand.ConveyorLineBarcode}銆戠洰鏍囧湴鍧�銆恵taskCommand.ConveyorLineTargetAddress}銆戝綋鍓嶈妭鐐广�恵childDeviceCode}銆�");
             return false;
         }
     }
diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
index ed32328..6bd38fe 100644
--- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
+++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
@@ -1149,6 +1149,7 @@
                 if (hasMatchingDetail)
                 {
                     stockInfo = stock;
+                    break;
                 }
             }
             if (stockInfo == null) throw new Exception($"搴撳唴{station.productLine}鏃犳弧瓒虫潯浠剁殑搴撳瓨鍙嚭搴�");

--
Gitblit v1.9.3