From 5bf10c1dafe485d506ec534f98e5220a3b83dd17 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期四, 16 四月 2026 23:16:46 +0800
Subject: [PATCH] feat(WCS&WMS): 机械手扫码NG处理与线体条码读取与添加批量MES绑定解绑接口
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/Workflow/RobotWorkflowOrchestrator.cs | 327 +++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 262 insertions(+), 65 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/Workflow/RobotWorkflowOrchestrator.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/Workflow/RobotWorkflowOrchestrator.cs
index e0211a5..2ddad09 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/Workflow/RobotWorkflowOrchestrator.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/Workflow/RobotWorkflowOrchestrator.cs
@@ -5,6 +5,7 @@
using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
+using WIDESEAWCS_Tasks.SocketServer;
using WIDESEAWCS_Tasks.Workflow.Abstractions;
namespace WIDESEAWCS_Tasks.Workflow
@@ -152,7 +153,7 @@
/// </summary>
/// <remarks>
/// 褰撳彇璐у畬鎴愬悗锛屽悜鏈哄櫒浜哄彂閫佹斁璐ф寚浠わ紙Putbattery锛夈��
- /// 鏈哄櫒浜烘敹鍒版寚浠ゅ悗浼氬皢璐х墿鏀剧疆鍒扮洰鏍囧湴鍧�銆�
+ /// 鎹㈢洏浠诲姟浣跨敤鎵规鏍煎紡 SendPutWithBatchAsync銆�
///
/// 鎸囦护鏍煎紡锛歅utbattery,{鐩爣鍦板潃}
/// 渚嬪锛歅utbattery,B01 琛ㄧず灏嗚揣鐗╂斁缃埌 B01 浣嶇疆
@@ -161,38 +162,113 @@
/// <param name="ipAddress">鏈哄櫒浜� IP 鍦板潃</param>
private async Task HandlePickFinishedStateAsync(Dt_RobotTask task, string ipAddress)
{
- // 鏋勫缓鏀捐揣鎸囦护锛屾牸寮忥細Putbattery,{鐩爣鍦板潃}
- string taskString = $"Putbattery,{task.RobotTargetAddress}";
+ string taskString;
- // 閫氳繃瀹㈡埛绔鐞嗗櫒鍙戦�佹寚浠ゅ埌鏈哄櫒浜�
+ var state = _stateManager.GetState(ipAddress);
+
+ // 鎹㈢洏浠诲姟浣跨敤鎵规鏍煎紡
+ if (task.RobotTaskType == RobotTaskTypeEnum.ChangePallet.GetHashCode())
+ {
+ int targetNormalCount = task.RobotTaskTotalNum;
+ int currentCompletedCount = state?.RobotTaskTotalNum ?? 0;
+
+ bool isFlowA = task.RobotSourceAddressLineCode is "11001" or "11010";
+
+ // 娴佸悜A Phase 2锛氭斁鍋囩數鑺埌鐩爣鎵樼洏
+ if (isFlowA && state?.ChangePalletPhase == 2)
+ {
+ int remaining = 48 - currentCompletedCount;
+ if (remaining <= 0) return;
+
+ int batchStart = targetNormalCount + 1 + (state.CurrentBatchIndex - 1);
+ int putCount = Math.Min(4, remaining);
+ var (start, end) = _taskProcessor.BuildBatchRange(batchStart, putCount);
+
+ await _taskProcessor.SendPutWithBatchAsync(task, state, task.RobotTargetAddress, start, end);
+ return;
+ }
+
+ // 娴佸悜B Phase 4锛氭斁鍋囩數鑺埌5鍙蜂綅
+ if (!isFlowA && state?.ChangePalletPhase == 4)
+ {
+ int fakeCount = 48 - targetNormalCount;
+ int completedFake = Math.Max(0, currentCompletedCount - targetNormalCount);
+ int remainingFake = fakeCount - completedFake;
+
+ if (remainingFake <= 0) return;
+
+ var positions = _taskProcessor.GetNextAvailableFakeBatteryPositions(Math.Min(4, remainingFake));
+ if (positions.Count == 0)
+ {
+ _logger.LogError("HandlePickFinishedStateAsync锛氭棤鍙敤鍋囩數鑺偣浣嶏紝浠诲姟鍙�: {TaskNum}", task.RobotTaskNum);
+ return;
+ }
+
+ int start = positions.Min();
+ int end = positions.Max();
+
+ await _taskProcessor.SendPutWithBatchAsync(task, state, "5", start, end);
+ return;
+ }
+
+ // 娴佸悜B Phase 2锛氭斁姝e父鐢佃姱鍒扮洰鏍囨墭鐩�
+ if (!isFlowA && state?.ChangePalletPhase == 2)
+ {
+ int remainingNormal = targetNormalCount - currentCompletedCount;
+ if (remainingNormal <= 0) return;
+
+ int batchStart = ((currentCompletedCount - 1) / 4) * 4 + 1;
+ int putCount = Math.Min(4, remainingNormal);
+ var (start, end) = _taskProcessor.BuildBatchRange(batchStart, putCount);
+
+ await _taskProcessor.SendPutWithBatchAsync(task, state, task.RobotTargetAddress, start, end);
+ return;
+ }
+
+ // 榛樿锛氫娇鐢ㄥ師鏈夋牸寮�
+ taskString = $"Putbattery,{task.RobotTargetAddress}";
+ }
+ else
+ {
+ // 闈炴崲鐩樹换鍔★細浣跨敤鍘熸湁鏍煎紡
+ if (state != null && state.IsGroupPallet && task.RobotTaskType == RobotTaskTypeEnum.GroupPallet.GetHashCode())
+ {
+ // 缁勭洏浠诲姟锛氭斁璐ч渶鍒ゆ柇鏄惁NG锛屽鏋淣G鍒欐斁鍒癗G鍙�
+ if (state.IsScanNG)
+ {
+ taskString = $"Putbattery,NG";
+ }
+ else
+ {
+ taskString = $"Putbattery,{task.RobotTargetAddress}";
+ }
+ }
+ else
+ taskString = $"Putbattery,{task.RobotTargetAddress}";
+ }
+
bool result = await _clientManager.SendToClientAsync(ipAddress, taskString);
if (result)
{
- // 鍙戦�佹垚鍔燂紝璁板綍 Info 鏃ュ織
_logger.LogInformation("HandlePickFinishedStateAsync锛氫笅鍙戞斁璐ф寚浠ゆ垚鍔燂紝鎸囦护: {TaskString}锛屼换鍔″彿: {TaskNum}", taskString, task.RobotTaskNum);
QuartzLogger.Info($"涓嬪彂鏀捐揣鎸囦护鎴愬姛锛屾寚浠�: {taskString}", task.RobotRoadway);
- // 鏇存柊浠诲姟鐘舵�佷负"鏈哄櫒浜烘墽琛屼腑"
task.RobotTaskState = TaskRobotStatusEnum.RobotExecuting.GetHashCode();
- // 鑾峰彇鏈�鏂扮姸鎬佸苟鏇存柊浠诲姟鍏宠仈
var stateToUpdate = _stateManager.GetState(ipAddress);
if (stateToUpdate != null)
{
stateToUpdate.CurrentTask = task;
- // 瀹夊叏鏇存柊鐘舵�佸埌 Redis
if (_stateManager.TryUpdateStateSafely(ipAddress, stateToUpdate))
{
- // 鐘舵�佹洿鏂版垚鍔熷悗锛屾洿鏂颁换鍔¤褰�
await _robotTaskService.UpdateRobotTaskAsync(task);
}
}
}
else
{
- // 鍙戦�佸け璐ワ紝璁板綍 Error 鏃ュ織
_logger.LogError("HandlePickFinishedStateAsync锛氫笅鍙戞斁璐ф寚浠ゅけ璐ワ紝鎸囦护: {TaskString}锛屼换鍔″彿: {TaskNum}", taskString, task.RobotTaskNum);
QuartzLogger.Error($"涓嬪彂鏀捐揣鎸囦护澶辫触锛屾寚浠�: {taskString}", task.RobotRoadway);
}
@@ -240,112 +316,233 @@
// 濡傛灉鏄粍鐩樹换鍔�
if (task.RobotTaskType == RobotTaskTypeEnum.GroupPallet.GetHashCode())
{
- // 鐢熸垚鎵樼洏鏉$爜鍓嶇紑
- const string prefix = "TRAY";
-
- // 鐢熸垚涓や釜鎵樼洏鏉$爜锛堢敤浜庣粍鐩樻搷浣滐級锛堟祴璇曠敤锛屽悗缁鍙栫嚎浣撴潯鐮侊級
- string trayBarcode1 = RobotBarcodeGenerator.GenerateTrayBarcode(prefix);
- string trayBarcode2 = RobotBarcodeGenerator.GenerateTrayBarcode(prefix);
+ // 璇诲彇绾夸綋鐢佃姱鏉$爜
+ string trayBarcode1 = RobotBarcodeGenerator.GenerateTrayBarcode("DB40.990");
+ string trayBarcode2 = RobotBarcodeGenerator.GenerateTrayBarcode("DB40.1020");
// 濡傛灉鏉$爜鐢熸垚鎴愬姛
if (!string.IsNullOrEmpty(trayBarcode1) && !string.IsNullOrEmpty(trayBarcode2))
{
- if(stateForUpdate.CellBarcode.Contains(trayBarcode1)|| stateForUpdate.CellBarcode.Contains(trayBarcode2))
+ if (stateForUpdate.CellBarcode.Contains(trayBarcode1) || stateForUpdate.CellBarcode.Contains(trayBarcode2))
{
- _logger.LogError("HandlePutFinishedStateAsync锛氱敓鎴愮殑鎵樼洏鏉$爜宸插瓨鍦紝鍙兘瀛樺湪閲嶅锛屼换鍔″彿: {TaskNum}", task.RobotTaskNum);
- QuartzLogger.Error($"鐢熸垚鐨勬墭鐩樻潯鐮佸凡瀛樺湪锛屽彲鑳藉瓨鍦ㄩ噸澶�", stateForUpdate.RobotCrane.DeviceName);
+ _logger.LogError("HandlePutFinishedStateAsync锛氳鍙栫殑鎵樼洏鏉$爜宸插瓨鍦紝鍙兘瀛樺湪閲嶅锛屼换鍔″彿: {TaskNum}", task.RobotTaskNum);
+ QuartzLogger.Error($"璇诲彇鐨勬墭鐩樻潯鐮佸凡瀛樺湪锛屽彲鑳藉瓨鍦ㄩ噸澶�", stateForUpdate.RobotCrane.DeviceName);
// 鏉$爜閲嶅锛岃褰曢敊璇棩蹇楀苟鍋滄鍚庣画鎿嶄綔(鍚庣画鏀捐揣鏃朵細鐢ㄥ埌杩欎簺鏉$爜淇℃伅锛屼緵鍚庣画鏀捐揣鏃朵娇鐢紝璋冭瘯鍚庡彲鑳戒細鍙栨秷姝ら�昏緫)
- return;
+
+ // 鍙戦�佸彇璐ф寚浠� 鏍囪鎵爜NG锛屾斁璐ф椂涓嶄娇鐢ㄨ繖浜涙潯鐮侊紝骞舵斁鍏G鍙�
+ await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate, true);
}
else
{
- _logger.LogInformation("HandlePutFinishedStateAsync锛氱敓鎴愮殑鎵樼洏鏉$爜鍞竴锛岀户缁墽琛岋紝浠诲姟鍙�: {TaskNum}", task.RobotTaskNum);
- QuartzLogger.Info($"鐢熸垚鐨勬墭鐩樻潯鐮佸敮涓�锛岀户缁墽琛�", stateForUpdate.RobotCrane.DeviceName);
+ _logger.LogInformation("HandlePutFinishedStateAsync锛氳鍙栫殑鎵樼洏鏉$爜鍞竴锛岀户缁墽琛岋紝浠诲姟鍙�: {TaskNum}", task.RobotTaskNum);
+ QuartzLogger.Info($"璇诲彇鐨勬墭鐩樻潯鐮佸敮涓�锛岀户缁墽琛�", stateForUpdate.RobotCrane.DeviceName);
// 灏嗘潯鐮佹坊鍔犲埌鐘舵�佷腑锛屼緵鍚庣画鏀捐揣鏃朵娇鐢�
stateForUpdate.CellBarcode.Add(trayBarcode1);
stateForUpdate.CellBarcode.Add(trayBarcode2);
}
- // 璁板綍鏃ュ織锛氱敓鎴愭墭鐩樻潯鐮佹垚鍔�
- _logger.LogInformation("HandlePutFinishedStateAsync锛氱敓鎴愭墭鐩樻潯鐮佹垚鍔�: {Barcode1}+{Barcode2}锛屼换鍔″彿: {TaskNum}", trayBarcode1, trayBarcode2, task.RobotTaskNum);
- QuartzLogger.Info($"鐢熸垚鎵樼洏鏉$爜鎴愬姛: {trayBarcode1}+{trayBarcode2}", stateForUpdate.RobotCrane.DeviceName);
+ // 璁板綍鏃ュ織锛氳鍙栨墭鐩樻潯鐮佹垚鍔�
+ _logger.LogInformation("HandlePutFinishedStateAsync锛氳鍙栨墭鐩樻潯鐮佹垚鍔�: {Barcode1}+{Barcode2}锛屼换鍔″彿: {TaskNum}", trayBarcode1, trayBarcode2, task.RobotTaskNum);
+ QuartzLogger.Info($"璇诲彇鎵樼洏鏉$爜鎴愬姛: {trayBarcode1}+{trayBarcode2}", stateForUpdate.RobotCrane.DeviceName);
// 鍙戦�佸彇璐ф寚浠�
- await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate);
+ await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate, false);
}
else
{
- // 鏉$爜鐢熸垚澶辫触锛岃褰曢敊璇棩蹇�
- _logger.LogError("HandlePutFinishedStateAsync锛氱敓鎴愭墭鐩樻潯鐮佸け璐ワ紝浠诲姟鍙�: {TaskNum}", task.RobotTaskNum);
- QuartzLogger.Error($"鐢熸垚鎵樼洏鏉$爜澶辫触", stateForUpdate.RobotCrane.DeviceName);
+ // 鏉$爜璇诲彇澶辫触锛岃褰曢敊璇棩蹇�
+ _logger.LogError("HandlePutFinishedStateAsync锛氳鍙栨墭鐩樻潯鐮佸け璐ワ紝浠诲姟鍙�: {TaskNum}", task.RobotTaskNum);
+ QuartzLogger.Error($"璇诲彇鎵樼洏鏉$爜澶辫触", stateForUpdate.RobotCrane.DeviceName);
+
+
+ // 鍙戦�佸彇璐ф寚浠� 鏍囪鎵爜NG锛屾斁璐ф椂涓嶄娇鐢ㄨ繖浜涙潯鐮侊紝骞舵斁鍏G鍙�
+ await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate, true);
}
}
else if (task.RobotTaskType == RobotTaskTypeEnum.ChangePallet.GetHashCode())
{
- // 鎹㈢洏浠诲姟
- // 鐩爣锛氭甯哥數鑺姄鍙栧畬鎴愬悗锛岃ˉ鍏呭亣鐢佃姱鑷�48涓�
const int targetTotal = 48;
- const int fakeBatteryPickPosition = 5; // 鍋囩數鑺姄鍙栦綅缃�
- const int pickCountPerExecution = 4; // 姣忔鎶撳彇鏁伴噺
+ int targetNormalCount = task.RobotTaskTotalNum;
+ int currentCompletedCount = stateForUpdate.RobotTaskTotalNum;
- int targetNormalCount = task.RobotTaskTotalNum; // 姝e父鐢佃姱鐩爣鏁伴噺
- int currentCompletedCount = stateForUpdate.RobotTaskTotalNum; // 宸插畬鎴愭暟閲�
+ // 鍒ゆ柇娴佸悜锛坣ull-safe锛�
+ bool isFlowA = task.RobotSourceAddressLineCode is "11001" or "11010";
- // 濡傛灉鐩爣鏁伴噺涓�48锛岀洿鎺ヤ笅鍙戞甯镐换鍔�
+ // 鐩爣鏁伴噺涓�48锛氱洿鎺ヨ蛋鍘熸湁閫昏緫锛屼笉杩涘叆鎵规妯″紡
if (targetNormalCount == targetTotal)
{
- await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate);
- }
- // 濡傛灉宸插畬鎴愭暟閲忓皬浜庣洰鏍囨暟閲忥紝缁х画鎶撳彇姝e父鐢佃姱
- else if (currentCompletedCount < targetNormalCount)
- {
- await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate);
- }
- // 姝e父鐢佃姱宸插畬鎴愶紝杩涘叆鍋囩數鑺ˉ鍏呮ā寮�
- else if (currentCompletedCount == targetNormalCount && !stateForUpdate.IsInFakeBatteryMode)
- {
- // 棣栨杩涘叆鍋囩數鑺ā寮忥紝璁剧疆鏍囧織
- stateForUpdate.IsInFakeBatteryMode = true;
- _logger.LogInformation("HandlePutFinishedStateAsync锛氭甯哥數鑺姄鍙栧畬鎴愶紝杩涘叆鍋囩數鑺ˉ鍏呮ā寮忥紝浠诲姟鍙�: {TaskNum}", task.RobotTaskNum);
- QuartzLogger.Info($"姝e父鐢佃姱鎶撳彇瀹屾垚锛岃繘鍏ュ亣鐢佃姱琛ュ厖妯″紡", stateForUpdate.RobotCrane?.DeviceName);
+ await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate, false);
+ return;
}
- // 濡傛灉澶勪簬鍋囩數鑺ˉ鍏呮ā寮忥紝璁$畻骞朵笅鍙戣ˉ鏁颁换鍔�
- if (stateForUpdate.IsInFakeBatteryMode)
+ // 鍒濆鍖栨壒娆℃ā寮�
+ if (stateForUpdate.ChangePalletPhase == 0)
{
- int remaining = targetTotal - currentCompletedCount;
- if (remaining > 0)
+ stateForUpdate.ChangePalletPhase = 1;
+ stateForUpdate.CurrentBatchIndex = 1;
+ _logger.LogInformation("HandlePutFinishedStateAsync锛氭崲鐩樹换鍔¤繘鍏ユ壒娆℃ā寮忥紝浠诲姟鍙�: {TaskNum}锛屾祦鍚�: {Flow}",
+ task.RobotTaskNum, isFlowA ? "A" : "B");
+ }
+
+ // ==================== 娴佸悜A锛氳ˉ鍋囩數鑺埌鐩爣鎵樼洏 ====================
+ if (isFlowA)
+ {
+ // Phase 1: 鍙栧亣鐢佃姱锛堜粠5鍙蜂綅锛屼娇鐢� PositionIndex锛�
+ if (stateForUpdate.ChangePalletPhase == 1)
{
- // 璁$畻姣忔鎶撳彇鐨勬暟閲忥紙鏈�澶�4涓級
- int pickCount = Math.Min(pickCountPerExecution, remaining);
+ int remaining = targetTotal - currentCompletedCount;
+ if (remaining <= 0)
+ {
+ stateForUpdate.ChangePalletPhase = 0;
+ stateForUpdate.CurrentBatchIndex = 1;
+ stateForUpdate.IsInFakeBatteryMode = false;
+ _logger.LogInformation("HandlePutFinishedStateAsync锛氭祦鍚慉瀹屾垚锛屼换鍔″彿: {TaskNum}", task.RobotTaskNum);
+ return;
+ }
- // 鑾峰彇鍙敤鐨勫亣鐢佃姱骞抽潰鐐逛綅
+ int pickCount = Math.Min(4, remaining);
var positions = _taskProcessor.GetNextAvailableFakeBatteryPositions(pickCount);
if (positions.Count == 0)
{
_logger.LogError("HandlePutFinishedStateAsync锛氭棤鍙敤鍋囩數鑺偣浣嶏紝浠诲姟鍙�: {TaskNum}", task.RobotTaskNum);
- QuartzLogger.Error($"鏃犲彲鐢ㄥ亣鐢佃姱鐐逛綅", stateForUpdate.RobotCrane?.DeviceName);
return;
}
- // 涓嬪彂鍋囩數鑺彇璐ф寚浠�
await _taskProcessor.SendSocketRobotFakeBatteryPickAsync(task, stateForUpdate, positions);
+ stateForUpdate.ChangePalletPhase = 2;
}
- else
+ // Phase 2: 鏀惧亣鐢佃姱鍒扮洰鏍囨墭鐩橈紙浠� targetNormalCount+1 寮�濮嬮�掑锛�
+ else if (stateForUpdate.ChangePalletPhase == 2)
{
- // 鍋囩數鑺ˉ鍏呭畬鎴愶紝閲嶇疆鏍囧織
- stateForUpdate.IsInFakeBatteryMode = false;
- _logger.LogInformation("HandlePutFinishedStateAsync锛氭崲鐩樹换鍔″畬鎴愶紝浠诲姟鍙�: {TaskNum}", task.RobotTaskNum);
- QuartzLogger.Info($"鎹㈢洏浠诲姟瀹屾垚", stateForUpdate.RobotCrane?.DeviceName);
+ int remaining = targetTotal - currentCompletedCount;
+ if (remaining <= 0)
+ {
+ stateForUpdate.ChangePalletPhase = 0;
+ stateForUpdate.CurrentBatchIndex = 1;
+ stateForUpdate.IsInFakeBatteryMode = false;
+ _logger.LogInformation("HandlePutFinishedStateAsync锛氭祦鍚慉瀹屾垚锛屼换鍔″彿: {TaskNum}", task.RobotTaskNum);
+ return;
+ }
+
+ // 璁$畻鏀捐揣鎵规缂栧彿锛氫粠 targetNormalCount + 1 寮�濮�
+ int batchStart = targetNormalCount + 1 + (stateForUpdate.CurrentBatchIndex - 1);
+ int putCount = Math.Min(4, remaining);
+ var (start, end) = _taskProcessor.BuildBatchRange(batchStart, putCount);
+
+ await _taskProcessor.SendPutWithBatchAsync(task, stateForUpdate, task.RobotTargetAddress, start, end);
+
+ stateForUpdate.CurrentBatchIndex += putCount;
+ stateForUpdate.ChangePalletPhase = 1;
+ }
+ }
+ // ==================== 娴佸悜B锛氬彇姝e父鐢佃姱 + 鍥炴敹鍋囩數鑺� ====================
+ else
+ {
+ // Phase 1: 鍙栨甯哥數鑺紙浠庢簮鍦板潃锛屼粠1寮�濮嬮�掑锛�
+ if (stateForUpdate.ChangePalletPhase == 1)
+ {
+ int remainingNormal = targetNormalCount - currentCompletedCount;
+ if (remainingNormal <= 0)
+ {
+ // 姝e父鐢佃姱鍙栧畬锛屽垏鎹㈠埌 Phase 3
+ stateForUpdate.ChangePalletPhase = 3;
+ stateForUpdate.CurrentBatchIndex = targetNormalCount + 1;
+ _logger.LogInformation("HandlePutFinishedStateAsync锛氭甯哥數鑺叏閮ㄥ彇瀹岋紝杩涘叆Phase 3鍥炴敹鍋囩數鑺紝浠诲姟鍙�: {TaskNum}", task.RobotTaskNum);
+ return;
+ }
+
+ int pickCount = Math.Min(4, remainingNormal);
+ var (start, end) = _taskProcessor.BuildBatchRange(stateForUpdate.CurrentBatchIndex, pickCount);
+
+ await _taskProcessor.SendPickWithBatchAsync(task, stateForUpdate, task.RobotSourceAddress, start, end);
+
+ stateForUpdate.CurrentBatchIndex += pickCount;
+ stateForUpdate.ChangePalletPhase = 2;
+ }
+ // Phase 2: 鏀炬甯哥數鑺埌鐩爣鎵樼洏锛堟斁璐х紪鍙蜂笌鍙栬揣缂栧彿涓�鑷达級
+ else if (stateForUpdate.ChangePalletPhase == 2)
+ {
+ int remainingNormal = targetNormalCount - currentCompletedCount;
+ if (remainingNormal <= 0)
+ {
+ // 姝e父鐢佃姱鏀惧畬锛屽垏鎹㈠埌 Phase 3
+ stateForUpdate.ChangePalletPhase = 3;
+ stateForUpdate.CurrentBatchIndex = targetNormalCount + 1;
+ _logger.LogInformation("HandlePutFinishedStateAsync锛氭甯哥數鑺叏閮ㄦ斁瀹岋紝杩涘叆Phase 3鍥炴敹鍋囩數鑺紝浠诲姟鍙�: {TaskNum}", task.RobotTaskNum);
+ return;
+ }
+
+ // 璁$畻鏈壒鏀捐揣缂栧彿锛氬熀浜� currentCompletedCount 鎺ㄥ鎵规璧峰
+ int batchStart = ((currentCompletedCount - 1) / 4) * 4 + 1;
+ int putCount = Math.Min(4, remainingNormal);
+ var (start, end) = _taskProcessor.BuildBatchRange(batchStart, putCount);
+
+ await _taskProcessor.SendPutWithBatchAsync(task, stateForUpdate, task.RobotTargetAddress, start, end);
+
+ stateForUpdate.ChangePalletPhase = 1;
+ }
+ // Phase 3: 鍙栧亣鐢佃姱锛堜粠婧愬湴鍧�锛屼粠 targetNormalCount+1 寮�濮嬮�掑锛�
+ else if (stateForUpdate.ChangePalletPhase == 3)
+ {
+ int fakeCount = targetTotal - targetNormalCount;
+ int completedFake = Math.Max(0, currentCompletedCount - targetNormalCount);
+ int remainingFake = fakeCount - completedFake;
+
+ if (remainingFake <= 0)
+ {
+ stateForUpdate.ChangePalletPhase = 0;
+ stateForUpdate.CurrentBatchIndex = 1;
+ stateForUpdate.IsInFakeBatteryMode = false;
+ _logger.LogInformation("HandlePutFinishedStateAsync锛氭祦鍚態瀹屾垚锛屼换鍔″彿: {TaskNum}", task.RobotTaskNum);
+ return;
+ }
+
+ int pickCount = Math.Min(4, remainingFake);
+ var (start, end) = _taskProcessor.BuildBatchRange(stateForUpdate.CurrentBatchIndex, pickCount);
+
+ await _taskProcessor.SendPickWithBatchAsync(task, stateForUpdate, task.RobotSourceAddress, start, end);
+
+ stateForUpdate.CurrentBatchIndex += pickCount;
+ stateForUpdate.ChangePalletPhase = 4;
+ }
+ // Phase 4: 鏀惧亣鐢佃姱鍒�5鍙蜂綅锛堜娇鐢� PositionIndex锛�
+ else if (stateForUpdate.ChangePalletPhase == 4)
+ {
+ int fakeCount = targetTotal - targetNormalCount;
+ int completedFake = Math.Max(0, currentCompletedCount - targetNormalCount);
+ int remainingFake = fakeCount - completedFake;
+
+ if (remainingFake <= 0)
+ {
+ stateForUpdate.ChangePalletPhase = 0;
+ stateForUpdate.CurrentBatchIndex = 1;
+ stateForUpdate.IsInFakeBatteryMode = false;
+ _logger.LogInformation("HandlePutFinishedStateAsync锛氭祦鍚態瀹屾垚锛屼换鍔″彿: {TaskNum}", task.RobotTaskNum);
+ return;
+ }
+
+ var positions = _taskProcessor.GetNextAvailableFakeBatteryPositions(Math.Min(4, remainingFake));
+ if (positions.Count == 0)
+ {
+ _logger.LogError("HandlePutFinishedStateAsync锛氭棤鍙敤鍋囩數鑺偣浣嶏紝浠诲姟鍙�: {TaskNum}", task.RobotTaskNum);
+ return;
+ }
+
+ int start = positions.Min();
+ int end = positions.Max();
+
+ await _taskProcessor.SendPutWithBatchAsync(task, stateForUpdate, "5", start, end);
+
+ stateForUpdate.ChangePalletPhase = 3;
}
}
}
else
{
// 闈炵粍鐩樹换鍔★紝鐩存帴鍙戦�佸彇璐ф寚浠�
- await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate);
+ await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate, false);
}
}
}
--
Gitblit v1.9.3