From b0b5deb5825684bca5b3fa7c2ab59f60ce0e799f Mon Sep 17 00:00:00 2001
From: xiazhengtongxue <133085197+xiazhengtongxue@users.noreply.github.com>
Date: 星期二, 07 四月 2026 16:36:57 +0800
Subject: [PATCH] fix: 修复移库任务号重复问题,优化策略优先处理正常任务,避免任务堵塞

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WMSCruJob.cs |   34 +++++++++++++++-------------------
 1 files changed, 15 insertions(+), 19 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WMSCruJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WMSCruJob.cs"
index b75d4a9..6afd72c 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WMSCruJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WMSCruJob.cs"
@@ -57,12 +57,7 @@
             _taskService=taskService;
         }
         private static readonly object _taskProcessLock = new object();
-        private const int TASK_PROCESS_TIMEOUT = 2000; // 2绉掕秴鏃�
-
-        private static readonly object _taskProcessLockPLC = new object();
-        private const int TASK_PROCESS_TIMEOUTPLC = 3000; // 2绉掕秴鏃�
-
-        
+        private const int TASK_PROCESS_TIMEOUT = 1000; // 2绉掕秴鏃�
         private readonly Queue<int> _deviceQueueSC = new Queue<int>();
 
         public Task StartAsync(CancellationToken cancellationToken)
@@ -73,8 +68,8 @@
                 _deviceQueueSC.Enqueue(i);
             }
 
-            _timer = new Timer(SCProcessNextDevice, null, TimeSpan.Zero, TimeSpan.FromSeconds(2));
-            _timer2 = new Timer(PLCDoDeciceWork, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2));
+            _timer = new Timer(SCProcessNextDevice, null, TimeSpan.Zero, TimeSpan.FromSeconds(1));
+            //_timer2 = new Timer(PLCDoDeciceWork, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2));
             return Task.CompletedTask;
         }
 
@@ -92,7 +87,8 @@
                 try
                 {
                     SCDoDeviceWork(deviceId);
-                    _deviceQueueSC.Enqueue(deviceId);  
+                    _deviceQueueSC.Enqueue(deviceId);
+                    PLCDoDeciceWork();
                 }
                 catch (Exception ex)
                 {
@@ -123,7 +119,11 @@
                 foreach (Dt_Task task in taskList)
                 {
                     WebResponseContent webResponse = JudgmentIsRelocations(task);
-                    if (!webResponse.Status) return;
+                    if (!webResponse.Status)
+                    {
+                        WriteLog.Write_Log("WMS_绉诲簱鏁呴殰", $"绉诲簱杩斿洖澶辫触鍐呭", "澶辫触", $"绉诲簱澶辫触,鍘熷洜锛歿webResponse.Message}");
+                        return;
+                    }
 
                     WCSginseng result = _taskService.SC_IssueTasks(
                         task.TaskId,
@@ -146,9 +146,8 @@
             }
         }
 
-        private void PLCDoDeciceWork(object state)
+        private void PLCDoDeciceWork()
         {
-            if (!Monitor.TryEnter(_taskProcessLockPLC, TASK_PROCESS_TIMEOUTPLC)) return;
             try
             {
                 // 鑾峰彇褰撳墠浠诲姟鏁版嵁
@@ -157,17 +156,13 @@
                 foreach (var task in allTasks)
                 {
                     // 涓嬪彂PLC浠诲姟
-                    WCSginseng result = _taskService.PLC_IssueTasks(task.TaskId, int.Parse(task.Roadway), task.TaskNum, task.PalletCode, int.Parse(task.PalletType), task.CurrentAddress, task.NextAddress, "");
+                    WCSginseng result = _taskService.PLC_IssueTasks(task.TaskId, task.WarehouseId, task.TaskNum, task.PalletCode, int.Parse(task.PalletType), task.CurrentAddress, task.NextAddress, "");
                     UpdateTaskStatus(task, result, (int)OutTaskStatusEnum.PLC_OutExecuting, 2);
                 }
             }
             catch (Exception ex)
             {
                 Console.WriteLine($"鍫嗗灈鏈哄畬鎴愶紝涓嬪彂杈撻�佺嚎鎵ц浠诲姟澶辫触锛� 鍘熷洜: {ex.Message}");
-            }
-            finally
-            {
-                Monitor.Exit(_taskProcessLockPLC);
             }
         }
         
@@ -182,6 +177,7 @@
                 task.TaskStatus = successStatus;
                 if(task.TaskStatus== (int)OutTaskStatusEnum.SC_OutExecuting)
                 {
+                    task.Dispatchertime = DateTime.Now;
                     string Result = MesOutTaskStatusEnum.Start.GetDescription();
                     //璋冨彇涓婃父绯荤粺鍙嶉寮�濮嬩换鍔�
                     _taskService.OutStoreDocCallback(task.TaskNum,Result, "鎿嶄綔鎴愬姛");
@@ -190,8 +186,8 @@
             else
             {
                 task.Remark = result.Message;
-                task.NumberSsuances++;
-            }
+                //task.NumberSsuances++;
+            }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
 
             _taskService.Repository.UpdateData(task);
         }

--
Gitblit v1.9.3