From 559bb7b4be83575cc5fedee98484647243c96f89 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 08 四月 2026 15:57:44 +0800
Subject: [PATCH] feat: 空托盘出库完整流程 + 输送线调度优化 + S7Simulator 协议同步增强

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs |   39 +++++++++++++++++++++------------------
 1 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
index cad24d5..d4d915d 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
@@ -1,6 +1,7 @@
 using MapsterMapper;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
 using Quartz;
 using SqlSugar;
 using System.Text.Json;
@@ -131,19 +132,20 @@
                     }
 
                     // 鍒涘缓骞惰閫夐」锛岄檺鍒舵渶澶у苟鍙戞暟
-                    var parallelOptions = new ParallelOptions
-                    {
-                        // 闄愬埗骞跺彂鏁帮細瀛愯澶囨暟閲忓拰 CPU 鏍稿績鏁�*2 鐨勮緝灏忓��
-                        MaxDegreeOfParallelism = Math.Min(childDeviceCodes.Count, Environment.ProcessorCount * 2),
-                    };
+                    //var parallelOptions = new ParallelOptions
+                    //{
+                    //    // 闄愬埗骞跺彂鏁帮細瀛愯澶囨暟閲忓拰 CPU 鏍稿績鏁�*2 鐨勮緝灏忓��
+                    //    MaxDegreeOfParallelism = Math.Min(childDeviceCodes.Count, Environment.ProcessorCount * 2),
+                    //};
 
                     _logger.LogDebug("Execute锛氬紑濮嬪苟琛屽鐞嗚緭閫佺嚎 {DeviceCode}锛屽瓙璁惧鏁伴噺: {Count}", conveyorLine.DeviceCode, childDeviceCodes.Count);
                     QuartzLogger.Debug($"寮�濮嬪苟琛屽鐞嗚緭閫佺嚎锛屽瓙璁惧鏁伴噺: {childDeviceCodes.Count}", conveyorLine.DeviceCode);
 
                     // 骞惰澶勭悊姣忎釜瀛愯澶�
-                    Parallel.For(0, childDeviceCodes.Count, parallelOptions, i =>
+                    //Parallel.For(0, childDeviceCodes.Count, parallelOptions, i =>
+                    foreach (var childDeviceCode in childDeviceCodes)
                     {
-                        string childDeviceCode = childDeviceCodes[i];
+                        //string childDeviceCode = childDeviceCodes[i];
                         var correlationId = Guid.NewGuid().ToString("N");
                         try
                         {
@@ -155,7 +157,7 @@
                             {
                                 _logger.LogDebug("Execute锛氬瓙璁惧 {ChildDeviceCode} 鍛戒护涓虹┖锛岃烦杩�", childDeviceCode);
                                 QuartzLogger.Debug($"瀛愯澶� {childDeviceCode} 鍛戒护涓虹┖锛岃烦杩�", conveyorLine.DeviceCode);
-                                return;
+                                return Task.CompletedTask;
                             }
 
                             // 濡傛灉 WCS_ACK 涓� 1锛屽厛娓呴櫎锛堣〃绀哄鐞嗚繃涓婁竴娆¤姹傦級
@@ -171,10 +173,10 @@
                             if (checkPalletPositions.Any(x => x.Code == childDeviceCode))
                             {
                                 // 妫�鏌ヨ緭閫佺嚎鐘舵�侊紙鏄惁鏈夋墭鐩橈級
-                                if (command.CV_State.ObjToBool())
+                                if (command.CV_State == 1)
                                 {
                                     // 妫�鏌ヨ浣嶇疆鏄惁宸叉湁浠诲姟
-                                    var existingTask = _taskService.Repository.QueryFirst(x => x.TargetAddress == childDeviceCode);
+                                    var existingTask = _taskService.Db.Queryable<Dt_Task>().First(x => x.TargetAddress == childDeviceCode);
                                     if (existingTask.IsNullOrEmpty())
                                     {
                                         // 娌℃湁浠诲姟锛屽悜 WMS 璇锋眰鍑哄簱鎵樼洏浠诲姟
@@ -191,9 +193,10 @@
                                         // 濡傛灉璇锋眰鎴愬姛锛屾帴鏀� WMS 杩斿洖鐨勪换鍔�
                                         if (responseResult.IsSuccess && responseResult.Data.Status)
                                         {
-                                            var wmsTask = JsonSerializer.Deserialize<List<WMSTaskDTO>>(responseResult.Data.Data.Serialize());
+                                            var wmsTask = JsonConvert.DeserializeObject<WMSTaskDTO>(responseResult.Data.Data.ToString());
+                                            List<WMSTaskDTO> taskDTOs = new List<WMSTaskDTO> { wmsTask };
                                             if (wmsTask != null)
-                                                _taskService.ReceiveWMSTask(wmsTask);
+                                                _taskService.ReceiveWMSTask(taskDTOs);
                                         }
                                     }
                                 }
@@ -203,9 +206,9 @@
                             // 鍙湁褰� PLC_STB 涓� 1 鏃舵墠澶勭悊浠诲姟
                             if (command.PLC_STB != 1)
                             {
-                                _logger.LogDebug("Execute锛氬瓙璁惧 {ChildDeviceCode} PLC_STB 涓嶄负1锛岃烦杩�", childDeviceCode);
-                                QuartzLogger.Debug($"瀛愯澶� {childDeviceCode} PLC_STB 涓嶄负1锛岃烦杩�", conveyorLine.DeviceCode);
-                                return;
+                                //_logger.LogDebug("Execute锛氬瓙璁惧 {ChildDeviceCode} PLC_STB 涓嶄负1锛岃烦杩�", childDeviceCode);
+                                //QuartzLogger.Debug($"瀛愯澶� {childDeviceCode} PLC_STB 涓嶄负1锛岃烦杩�", conveyorLine.DeviceCode);
+                                return Task.CompletedTask;
                             }
 
                             // ========== 澶勭悊鏃犳墭鐩樻潯鐮佺殑鎯呭喌 ==========
@@ -215,7 +218,7 @@
                                 _logger.LogDebug("Execute锛氬瓙璁惧 {ChildDeviceCode} 鏃犳墭鐩樻潯鐮侊紝璇锋眰鍑哄簱浠诲姟", childDeviceCode);
                                 QuartzLogger.Debug($"瀛愯澶� {childDeviceCode} 鏃犳墭鐩樻潯鐮侊紝璇锋眰鍑哄簱浠诲姟", conveyorLine.DeviceCode);
                                 _conveyorLineDispatch.RequestOutbound(conveyorLine, command, childDeviceCode);
-                                return;
+                                return Task.CompletedTask;
                             }
 
                             // ========== 澶勭悊宸叉湁浠诲姟鍙风殑鎯呭喌 ==========
@@ -229,7 +232,7 @@
                                     QuartzLogger.Info($"澶勭悊浠诲姟 {task.TaskNum}锛岀姸鎬�: {task.TaskStatus}", conveyorLine.DeviceCode);
                                     // 澶勭悊浠诲姟鐘舵�侊紙鏍规嵁鐘舵�佸垎鍙戝埌涓嶅悓鏂规硶锛�
                                     ProcessTaskState(conveyorLine, command, task, childDeviceCode);
-                                    return;
+                                    return Task.CompletedTask;
                                 }
                             }
                         }
@@ -239,7 +242,7 @@
                             _logger.LogError(innerEx, "Execute锛氬瓙璁惧 {ChildDeviceCode} 澶勭悊寮傚父锛孋orrelationId: {CorrelationId}", childDeviceCode, correlationId);
                             QuartzLogger.Error($"瀛愯澶囧鐞嗗紓甯�: {innerEx.Message}", conveyorLine.DeviceCode, innerEx);
                         }
-                    });
+                    }
                 }
             }
             catch (Exception ex)

--
Gitblit v1.9.3