From e2bf7bc6b494439e182d333041e22b2774056fc3 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期日, 19 四月 2026 19:26:47 +0800
Subject: [PATCH] refactor(RobotJob): 构造函数从 ICacheService 改为 IRobotStateRepository
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs | 48 ++++++++++++++++++++++++++----------------------
1 files changed, 26 insertions(+), 22 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
index ea25892..f472356 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
@@ -1,12 +1,13 @@
using Microsoft.Extensions.Logging;
using Quartz;
-using System.Net;
using WIDESEA_Core;
+using WIDESEAWCS_Common;
using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_RedisService;
using WIDESEAWCS_Tasks.SocketServer;
using WIDESEAWCS_Tasks.Workflow;
using WIDESEAWCS_Tasks.Workflow.Abstractions;
@@ -29,15 +30,6 @@
[DisallowConcurrentExecution]
public class RobotJob : IJob
{
- /// <summary>
- /// 浠诲姟鎬绘暟涓婇檺
- /// </summary>
- /// <remarks>
- /// 褰撴満鍣ㄤ汉澶勭悊鐨勮揣鐗╂暟閲忚揪鍒版涓婇檺鏃讹紝涓嶅啀涓嬪彂鏂颁换鍔°��
- /// 闃叉鏈哄櫒浜鸿繃搴﹀姵绱垨绯荤粺杩囪浇銆�
- /// </remarks>
- private const int MaxTaskTotalNum = 48;
-
/// <summary>
/// 娑堟伅浜嬩欢璁㈤槄鏍囧織
/// </summary>
@@ -104,19 +96,20 @@
/// <param name="tcpSocket">TCP Socket 鏈嶅姟鍣ㄥ疄渚�</param>
/// <param name="robotTaskService">鏈哄櫒浜轰换鍔℃湇鍔�</param>
/// <param name="taskService">閫氱敤浠诲姟鏈嶅姟</param>
- /// <param name="cache">缂撳瓨鏈嶅姟</param>
+ /// <param name="robotStateRepository">鏈哄櫒浜虹姸鎬佷粨鍌�</param>
/// <param name="httpClientHelper">HTTP 瀹㈡埛绔府鍔╃被锛岀敤浜庤皟鐢� WMS 鎺ュ彛</param>
/// <param name="logger">鏃ュ織璁板綍鍣�</param>
public RobotJob(
TcpSocketServer tcpSocket,
IRobotTaskService robotTaskService,
ITaskService taskService,
- ICacheService cache,
+ IRobotStateRepository robotStateRepository,
HttpClientHelper httpClientHelper,
- ILogger<RobotJob> logger)
+ ILogger<RobotJob> logger,
+ IFakeBatteryPositionService fakeBatteryPositionService)
{
- // 鍒濆鍖栫姸鎬佺鐞嗗櫒锛屼紶鍏ョ紦瀛樻湇鍔�
- _stateManager = new RobotStateManager(cache, _logger);
+ // 鍒濆鍖栫姸鎬佺鐞嗗櫒锛屼紶鍏ヤ粨鍌ㄦ湇鍔�
+ _stateManager = new RobotStateManager(robotStateRepository, _logger);
_logger = logger;
// 鍒涘缓 Socket 缃戝叧锛屽皝瑁� TcpSocketServer 鐨勮闂�
@@ -124,16 +117,16 @@
ISocketClientGateway socketGateway = new SocketClientGateway(tcpSocket);
// 鍒濆鍖栦换鍔″鐞嗗櫒
- _taskProcessor = new RobotTaskProcessor(socketGateway, _stateManager, robotTaskService, taskService, httpClientHelper, _logger);
+ _taskProcessor = new RobotTaskProcessor(socketGateway, _stateManager, robotTaskService, taskService, httpClientHelper, _logger, fakeBatteryPositionService);
// 鍒濆鍖栧鎴风绠$悊鍣�
_clientManager = new RobotClientManager(tcpSocket, _stateManager, _logger);
// 鍒濆鍖栧懡浠ゅ鐞嗗櫒
// 绠�鍗曞懡浠ゅ鐞嗗櫒锛氬鐞嗙姸鎬佹洿鏂扮瓑绠�鍗曞懡浠�
- var simpleCommandHandler = new RobotSimpleCommandHandler(_taskProcessor);
+ var simpleCommandHandler = new RobotSimpleCommandHandler(_taskProcessor, socketGateway);
// 鍓嶇紑鍛戒护澶勭悊鍣細澶勭悊 pickfinished銆乸utfinished 绛夊甫鍙傛暟鐨勫懡浠�
- var prefixCommandHandler = new RobotPrefixCommandHandler(robotTaskService, _taskProcessor, _stateManager, socketGateway);
+ var prefixCommandHandler = new RobotPrefixCommandHandler(robotTaskService, _taskProcessor, _stateManager, socketGateway, fakeBatteryPositionService);
// 鍒濆鍖栨秷鎭矾鐢卞櫒
_messageRouter = new RobotMessageHandler(socketGateway, _stateManager, cache, simpleCommandHandler, prefixCommandHandler, logger);
@@ -214,8 +207,19 @@
return;
}
+ if (state.CurrentAction == "Picking" || state.CurrentAction == "Puting")
+ {
+ return;
+ }
+
// 杞鑾峰彇璇ヨ澶囩殑寰呭鐞嗕换鍔�
var task = _taskProcessor.GetTask(robotCrane);
+
+ // 濡傛灉娌℃湁鑾峰彇鍒板緟澶勭悊浠诲姟锛屼笖RobotArmObject涓�1锛堟湁鐗╂枡锛夛紝鍒欒幏鍙栬璁惧鎵ц涓殑浠诲姟
+ if (task == null && state.RobotArmObject == 1)
+ {
+ task = _taskProcessor.GetExecutingTask(robotCrane);
+ }
// 濡傛灉鏈夊緟澶勭悊浠诲姟
if (task != null)
@@ -229,12 +233,12 @@
}
// 妫�鏌ヤ换鍔℃�绘暟鏄惁鏈揪鍒颁笂闄�
- //if (latestState.RobotTaskTotalNum < MaxTaskTotalNum)
- //{
+ if (latestState.RobotTaskTotalNum < RobotConst.MaxTaskTotalNum)
+ {
// 璋冪敤宸ヤ綔娴佺紪鎺掑櫒鎵ц浠诲姟
// 缂栨帓鍣ㄤ細鏍规嵁褰撳墠鐘舵�佸喅瀹氫笅涓�姝ュ姩浣�
await _workflowOrchestrator.ExecuteAsync(latestState, task, ipAddress);
- //}
+ }
}
}
catch (Exception ex)
@@ -246,4 +250,4 @@
}
}
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3