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 |   64 ++++++++++++++++++++-----------
 1 files changed, 41 insertions(+), 23 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 4414558..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
@@ -163,11 +164,12 @@
         {
             string taskString;
 
+            var state = _stateManager.GetState(ipAddress);
+
             // 鎹㈢洏浠诲姟浣跨敤鎵规鏍煎紡
             if (task.RobotTaskType == RobotTaskTypeEnum.ChangePallet.GetHashCode())
             {
                 int targetNormalCount = task.RobotTaskTotalNum;
-                var state = _stateManager.GetState(ipAddress);
                 int currentCompletedCount = state?.RobotTaskTotalNum ?? 0;
 
                 bool isFlowA = task.RobotSourceAddressLineCode is "11001" or "11010";
@@ -229,7 +231,20 @@
             else
             {
                 // 闈炴崲鐩樹换鍔★細浣跨敤鍘熸湁鏍煎紡
-                taskString = $"Putbattery,{task.RobotTargetAddress}";
+                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);
@@ -301,46 +316,49 @@
             // 濡傛灉鏄粍鐩樹换鍔�
             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())
@@ -355,7 +373,7 @@
                 // 鐩爣鏁伴噺涓�48锛氱洿鎺ヨ蛋鍘熸湁閫昏緫锛屼笉杩涘叆鎵规妯″紡
                 if (targetNormalCount == targetTotal)
                 {
-                    await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate);
+                    await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate, false);
                     return;
                 }
 
@@ -524,7 +542,7 @@
             else
             {
                 // 闈炵粍鐩樹换鍔★紝鐩存帴鍙戦�佸彇璐ф寚浠�
-                await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate);
+                await _taskProcessor.SendSocketRobotPickAsync(task, stateForUpdate, false);
             }
         }
     }

--
Gitblit v1.9.3