From f288ccc545f8cc32bc922c96dfb3cab9a1f92ec6 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期一, 20 四月 2026 00:49:55 +0800
Subject: [PATCH] feat: 初始化WMS前端项目并实现基础功能

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotMessageHandler.cs |   69 +++++++---------------------------
 1 files changed, 14 insertions(+), 55 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotMessageHandler.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotMessageHandler.cs
index 081bfd4..9bcf06b 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotMessageHandler.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotMessageHandler.cs
@@ -1,8 +1,8 @@
 using Microsoft.Extensions.Logging;
 using System.Net.Sockets;
 using WIDESEAWCS_Common;
-using WIDESEAWCS_Core.Caches;
 using WIDESEAWCS_Core.LogHelper;
+using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_Tasks.Workflow.Abstractions;
 
 namespace WIDESEAWCS_Tasks
@@ -12,7 +12,7 @@
     /// </summary>
     /// <remarks>
     /// 鏍稿績鑱岃矗锛�
-    /// 1. 缂撳瓨鐘舵�佽鍙栵細浠� Redis 涓幏鍙栨満鍣ㄤ汉鏈�鏂扮殑鐘舵��
+    /// 1. 鐘舵�佹帴鏀讹細浠庤皟鐢ㄦ柟鑾峰彇鏈哄櫒浜烘渶鏂扮殑鐘舵��
     /// 2. 鍛戒护鍒嗗彂锛氭牴鎹秷鎭被鍨嬪垎鍙戠粰涓嶅悓鐨勫鐞嗗櫒
     ///    - 绠�鍗曞懡浠わ紙濡� homing銆乺unning锛夛細鐢� <see cref="IRobotSimpleCommandHandler"/> 澶勭悊
     ///    - 鍓嶇紑鍛戒护锛堝 pickfinished銆乸utfinished锛夛細鐢� <see cref="IRobotPrefixCommandHandler"/> 澶勭悊
@@ -25,41 +25,21 @@
         /// <summary>
         /// Socket 瀹㈡埛绔綉鍏虫帴鍙�
         /// </summary>
-        /// <remarks>
-        /// 鐢ㄤ簬鍚戝鎴风鍙戦�佸搷搴旀秷鎭��
-        /// </remarks>
         private readonly ISocketClientGateway _socketClientGateway;
 
         /// <summary>
         /// 鏈烘鎵嬬姸鎬佺鐞嗗櫒
         /// </summary>
-        /// <remarks>
-        /// 鐢ㄤ簬璇诲彇鍜屾洿鏂版満鍣ㄤ汉鐨勭姸鎬併��
-        /// </remarks>
         private readonly RobotStateManager _stateManager;
-
-        /// <summary>
-        /// 缂撳瓨鏈嶅姟
-        /// </summary>
-        /// <remarks>
-        /// 鐩存帴浣跨敤缂撳瓨鏈嶅姟妫�鏌ョ姸鎬佹槸鍚﹀瓨鍦ㄣ��
-        /// </remarks>
-        private readonly ICacheService _cache;
 
         /// <summary>
         /// 绠�鍗曞懡浠ゅ鐞嗗櫒
         /// </summary>
-        /// <remarks>
-        /// 澶勭悊绠�鍗曠殑鐘舵�佹洿鏂板懡浠わ紝濡傝繍琛岀姸鎬併�佹ā寮忓垏鎹㈢瓑銆�
-        /// </remarks>
         private readonly IRobotSimpleCommandHandler _simpleCommandHandler;
 
         /// <summary>
         /// 鍓嶇紑鍛戒护澶勭悊鍣�
         /// </summary>
-        /// <remarks>
-        /// 澶勭悊甯﹀弬鏁扮殑鍓嶇紑鍛戒护锛屽 pickfinished锛堝彇璐у畬鎴愶級銆乸utfinished锛堟斁璐у畬鎴愶級銆�
-        /// </remarks>
         private readonly IRobotPrefixCommandHandler _prefixCommandHandler;
 
         /// <summary>
@@ -72,21 +52,18 @@
         /// </summary>
         /// <param name="socketClientGateway">Socket 缃戝叧</param>
         /// <param name="stateManager">鐘舵�佺鐞嗗櫒</param>
-        /// <param name="cache">缂撳瓨鏈嶅姟</param>
         /// <param name="simpleCommandHandler">绠�鍗曞懡浠ゅ鐞嗗櫒</param>
         /// <param name="prefixCommandHandler">鍓嶇紑鍛戒护澶勭悊鍣�</param>
         /// <param name="logger">鏃ュ織璁板綍鍣�</param>
         public RobotMessageHandler(
             ISocketClientGateway socketClientGateway,
             RobotStateManager stateManager,
-            ICacheService cache,
             IRobotSimpleCommandHandler simpleCommandHandler,
             IRobotPrefixCommandHandler prefixCommandHandler,
             ILogger<RobotJob> logger)
         {
             _socketClientGateway = socketClientGateway;
             _stateManager = stateManager;
-            _cache = cache;
             _simpleCommandHandler = simpleCommandHandler;
             _prefixCommandHandler = prefixCommandHandler;
             _logger = logger;
@@ -98,12 +75,11 @@
         /// <remarks>
         /// 澶勭悊娴佺▼锛�
         /// 1. 璁板綍鏃ュ織锛堣褰曞師濮嬫秷鎭唴瀹癸級
-        /// 2. 楠岃瘉缂撳瓨涓槸鍚﹀瓨鍦ㄨ璁惧鐨勭姸鎬�
-        /// 3. 灏濊瘯鐢ㄧ畝鍗曞懡浠ゅ鐞嗗櫒澶勭悊锛堢姸鎬佹洿鏂扮被鍛戒护锛�
+        /// 2. 灏濊瘯鐢ㄧ畝鍗曞懡浠ゅ鐞嗗櫒澶勭悊锛堢姸鎬佹洿鏂扮被鍛戒护锛�
         ///    - 濡傛灉澶勭悊鎴愬姛锛屽洖鍐欏師娑堟伅骞舵洿鏂扮姸鎬�
-        /// 4. 濡傛灉涓嶆槸绠�鍗曞懡浠わ紝妫�鏌ユ槸鍚︽槸鍓嶇紑鍛戒护锛坧ickfinished/putfinished锛�
+        /// 3. 濡傛灉涓嶆槸绠�鍗曞懡浠わ紝妫�鏌ユ槸鍚︽槸鍓嶇紑鍛戒护锛坧ickfinished/putfinished锛�
         ///    - 濡傛灉鏄紝璋冪敤鍓嶇紑鍛戒护澶勭悊鍣ㄥ鐞�
-        /// 5. 淇濇寔鍘熸湁琛屼负锛氱畝鍗曞懡浠ゅ拰鍓嶇紑鍛戒护閮藉洖鍐欏師娑堟伅
+        /// 4. 淇濇寔鍘熸湁琛屼负锛氱畝鍗曞懡浠ゅ拰鍓嶇紑鍛戒护閮藉洖鍐欏師娑堟伅
         ///
         /// 娉ㄦ剰锛氭鏂规硶鍙兘鍦� TCP 娑堟伅鎺ユ敹鐨勪笂涓嬫枃涓棰戠箒璋冪敤锛岄渶娉ㄦ剰鎬ц兘銆�
         /// </remarks>
@@ -115,46 +91,31 @@
         public async Task<string?> HandleMessageReceivedAsync(string message, bool isJson, TcpClient client, RobotSocketState state)
         {
             // 璁板綍鎺ユ敹鍒扮殑娑堟伅鏃ュ織
-            _logger.LogInformation($"鎺ユ敹鍒板鎴风銆恵state.RobotCrane.DeviceName}銆戝彂閫佹秷鎭�恵message}銆�");
-            QuartzLogger.Info($"鎺ユ敹鍒板鎴风娑堟伅銆恵message}銆�", state.RobotCrane.DeviceName);
+            _logger.LogInformation($"鎺ユ敹鍒板鎴风銆恵state.RobotCrane?.DeviceName}銆戝彂閫佹秷鎭�恵message}銆�");
+            QuartzLogger.Info($"鎺ユ敹鍒板鎴风娑堟伅銆恵message}銆�", state.RobotCrane?.DeviceName);
 
             // 妫�鏌ヤ换鍔℃�绘暟鏄惁鏈揪鍒颁笂闄�
             if (state.RobotTaskTotalNum > RobotConst.MaxTaskTotalNum)
             {
-                // 璁板綍鎺ユ敹鍒扮殑娑堟伅鏃ュ織
-                _logger.LogInformation($"鎺ユ敹鍒板鎴风銆恵state.RobotCrane.DeviceName}銆戝彂閫佹秷鎭�恵message}銆�");
-                QuartzLogger.Info($"鎺ユ敹鍒板鎴风娑堟伅銆恵message}銆�", state.RobotCrane.DeviceName);
-                // 澶勭悊鎴愬姛鍚庯紝灏嗗師娑堟伅鍥炲啓鍒板鎴风锛堜繚鎸佸師鏈夎涓猴級
+                _logger.LogInformation($"鎺ユ敹鍒板鎴风銆恵state.RobotCrane?.DeviceName}銆戝彂閫佹秷鎭�恵message}銆�");
+                QuartzLogger.Info($"鎺ユ敹鍒板鎴风娑堟伅銆恵message}銆�", state.RobotCrane?.DeviceName);
                 await _socketClientGateway.SendMessageAsync(client, message);
                 return null;
             }
-
-            // 鏋勫缓缂撳瓨閿紝妫�鏌� Redis 涓槸鍚﹀瓨鍦ㄨ璁惧鐨勭姸鎬�
-            var cacheKey = $"{RedisPrefix.Code}:{RedisName.SocketDevices}:{client.Client.RemoteEndPoint}";
-
-            // 濡傛灉缂撳瓨涓笉瀛樺湪鎴栫姸鎬佷负 null锛屽拷鐣ユ娑堟伅
-            if (!_cache.TryGetValue(cacheKey, out RobotSocketState? cachedState) || cachedState == null)
-            {
-                return null;
-            }
-
-            // 浣跨敤缂撳瓨涓幏鍙栫殑鐘舵��
-            var activeState = cachedState;
 
             // 灏嗘秷鎭浆鎹负灏忓啓锛堢敤浜庣畝鍗曞懡浠ゅ尮閰嶏級
             string messageLower = message.ToLowerInvariant();
 
             // 灏濊瘯鐢ㄧ畝鍗曞懡浠ゅ鐞嗗櫒澶勭悊
             // 绠�鍗曞懡浠ゅ寘鎷細homing銆乭omed銆乺unning銆乸ausing銆乺unmode銆乧ontrolmode 绛�
-            if (await _simpleCommandHandler.HandleAsync(messageLower, activeState))
+            if (await _simpleCommandHandler.HandleAsync(messageLower, state))
             {
                 // 澶勭悊鎴愬姛鍚庯紝灏嗗師娑堟伅鍥炲啓鍒板鎴风锛堜繚鎸佸師鏈夎涓猴級
                 await _socketClientGateway.SendMessageAsync(client, message);
-                _logger.LogInformation($"鍙戦�佹秷鎭�恵message}銆�");
-                QuartzLogger.Info($"鍙戦�佹秷鎭細銆恵message}銆�", state.RobotCrane.DeviceName);
+                QuartzLogger.Info($"鍙戦�佹秷鎭細銆恵message}銆�", state.RobotCrane?.DeviceName);
 
-                // 瀹夊叏鏇存柊鐘舵�佸埌 Redis
-                _stateManager.TryUpdateStateSafely(activeState.IPAddress, activeState);
+                // 瀹夊叏鏇存柊鐘舵�佸埌鏁版嵁搴�
+                _stateManager.TryUpdateStateSafely(state.IPAddress, state);
                 return null;
             }
 
@@ -163,11 +124,9 @@
             if (_prefixCommandHandler.IsPrefixCommand(messageLower))
             {
                 // 璋冪敤鍓嶇紑鍛戒护澶勭悊鍣�
-                // 鍓嶇紑鍛戒护澶勭悊鍣ㄤ細瑙f瀽浣嶇疆鍙傛暟骞舵洿鏂扮姸鎬�
-                await _prefixCommandHandler.HandleAsync(message, activeState, client);
+                await _prefixCommandHandler.HandleAsync(message, state, client);
             }
 
-            // 榛樿杩斿洖 null锛屼笉浜х敓鍝嶅簲娑堟伅
             return null;
         }
     }

--
Gitblit v1.9.3