From b690250002ee04f4309e6a90fd16fbfd9bd959e2 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 01 五月 2026 23:11:23 +0800
Subject: [PATCH] feat(router): 添加托盘操作页面路由

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotMessageHandler.cs |   85 ++++++++++++++++++++++++------------------
 1 files changed, 49 insertions(+), 36 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotMessageHandler.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotMessageHandler.cs
index 3dc5a22..7a78510 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotMessageHandler.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotMessageHandler.cs
@@ -89,47 +89,60 @@
         public async Task<string?> HandleMessageReceivedAsync(string message, bool isJson, TcpClient client)
         {
             var state = _stateManager.GetState(client.Client.RemoteEndPoint.ToString());
-            if (state.OperStatus == message)
-            {
-                // 澶勭悊鎴愬姛鍚庯紝灏嗗師娑堟伅鍥炲啓鍒板鎴风锛堜繚鎸佸師鏈夎涓猴級
-                //await _socketClientGateway.SendMessageAsync(client, message);
-            }
-            // 璁板綍鎺ユ敹鍒扮殑娑堟伅鏃ュ織
-            QuartzLogHelper.LogInfo(_logger, $"鎺ユ敹鍒板鎴风銆恵state.RobotCrane?.DeviceName}銆戝彂閫佹秷鎭�恵message}銆�", state.RobotCrane?.DeviceName);
 
-            // 妫�鏌ヤ换鍔℃�绘暟鏄惁鏈揪鍒颁笂闄�
-            if (state.RobotTaskTotalNum > RobotConst.MaxTaskTotalNum)
+            // 璁惧鐘舵�佷笉瀛樺湪鏃剁洿鎺ヨ繑鍥烇紝閬垮厤鍚庣画绌哄紩鐢�
+            if (state == null)
             {
+                return null;
+            }
+
+            // 鑾峰彇璇ヨ澶囩殑浜掓枼閿侊紝纭繚娑堟伅澶勭悊涓� Job 鎵ц浜掓枼
+            // Job 鍦ㄥ鐞嗕换鍔℃椂浼氱瓑寰呮閿侀噴鏀惧悗鎵嶇户缁墽琛�
+            var robotLock = _stateManager.GetOrCreateLock(state.IPAddress);
+            await robotLock.WaitAsync();
+            try
+            {
+                // 璁板綍鎺ユ敹鍒扮殑娑堟伅鏃ュ織
                 QuartzLogHelper.LogInfo(_logger, $"鎺ユ敹鍒板鎴风銆恵state.RobotCrane?.DeviceName}銆戝彂閫佹秷鎭�恵message}銆�", state.RobotCrane?.DeviceName);
-                await _socketClientGateway.SendMessageAsync(client, message);
-                return null;
+
+                // 妫�鏌ヤ换鍔℃�绘暟鏄惁鏈揪鍒颁笂闄�
+                if (state.RobotTaskTotalNum > RobotConst.MaxTaskTotalNum)
+                {
+                    QuartzLogHelper.LogInfo(_logger, $"鎺ユ敹鍒板鎴风銆恵state.RobotCrane?.DeviceName}銆戝彂閫佹秷鎭�恵message}銆�", state.RobotCrane?.DeviceName);
+                    await _socketClientGateway.SendMessageAsync(client, message);
+                    return null;
+                }
+
+                // 灏嗘秷鎭浆鎹负灏忓啓锛堢敤浜庣畝鍗曞懡浠ゅ尮閰嶏級
+                string messageLower = message.ToLowerInvariant();
+
+                // 灏濊瘯鐢ㄧ畝鍗曞懡浠ゅ鐞嗗櫒澶勭悊
+                // 绠�鍗曞懡浠ゅ寘鎷細homing銆乭omed銆乺unning銆乸ausing銆乺unmode銆乧ontrolmode 绛�
+                if (await _simpleCommandHandler.HandleAsync(messageLower, state))
+                {
+                    //if (messageLower != "batteryarrived")
+                    //{
+                    // 澶勭悊鎴愬姛鍚庯紝灏嗗師娑堟伅鍥炲啓鍒板鎴风锛堜繚鎸佸師鏈夎涓猴級
+                    //await _socketClientGateway.SendMessageAsync(client, message);
+                    QuartzLogHelper.LogInfo(_logger, $"鎺ユ敹鍒版秷鎭秷鎭�恵message}銆戯紝绾﹀畾涓嶈繑鍥炲彂閫佹秷鎭細銆恵message}銆�", state.RobotCrane?.DeviceName);
+                    //}
+
+                    //// 瀹夊叏鏇存柊鐘舵�佸埌鏁版嵁搴�
+                    //_stateManager.TryUpdateStateSafely(state.IPAddress, state);
+                    return null;
+                }
+
+                // 濡傛灉涓嶆槸绠�鍗曞懡浠わ紝妫�鏌ユ槸鍚︽槸鍓嶇紑鍛戒护
+                // 鍓嶇紑鍛戒护鍖呮嫭锛歱ickfinished銆乸utfinished锛堝悗闈㈣窡閫楀彿鍒嗛殧鐨勪綅缃弬鏁帮級
+                if (_prefixCommandHandler.IsPrefixCommand(messageLower))
+                {
+                    // 璋冪敤鍓嶇紑鍛戒护澶勭悊鍣�
+                    await _prefixCommandHandler.HandleAsync(message, state, client);
+                }
             }
-
-            // 灏嗘秷鎭浆鎹负灏忓啓锛堢敤浜庣畝鍗曞懡浠ゅ尮閰嶏級
-            string messageLower = message.ToLowerInvariant();
-
-            // 灏濊瘯鐢ㄧ畝鍗曞懡浠ゅ鐞嗗櫒澶勭悊
-            // 绠�鍗曞懡浠ゅ寘鎷細homing銆乭omed銆乺unning銆乸ausing銆乺unmode銆乧ontrolmode 绛�
-            if (await _simpleCommandHandler.HandleAsync(messageLower, state))
+            finally
             {
-                //if (messageLower != "batteryarrived")
-                //{
-                // 澶勭悊鎴愬姛鍚庯紝灏嗗師娑堟伅鍥炲啓鍒板鎴风锛堜繚鎸佸師鏈夎涓猴級
-                //await _socketClientGateway.SendMessageAsync(client, message);
-                QuartzLogHelper.LogInfo(_logger, $"鎺ユ敹鍒版秷鎭秷鎭�恵message}銆戯紝绾﹀畾涓嶈繑鍥炲彂閫佹秷鎭細銆恵message}銆�", state.RobotCrane?.DeviceName);
-                //}
-
-                // 瀹夊叏鏇存柊鐘舵�佸埌鏁版嵁搴�
-                _stateManager.TryUpdateStateSafely(state.IPAddress, state);
-                return null;
-            }
-
-            // 濡傛灉涓嶆槸绠�鍗曞懡浠わ紝妫�鏌ユ槸鍚︽槸鍓嶇紑鍛戒护
-            // 鍓嶇紑鍛戒护鍖呮嫭锛歱ickfinished銆乸utfinished锛堝悗闈㈣窡閫楀彿鍒嗛殧鐨勪綅缃弬鏁帮級
-            if (_prefixCommandHandler.IsPrefixCommand(messageLower))
-            {
-                // 璋冪敤鍓嶇紑鍛戒护澶勭悊鍣�
-                await _prefixCommandHandler.HandleAsync(message, state, client);
+                robotLock.Release();
             }
 
             return null;

--
Gitblit v1.9.3