From 2381da9301f2a269e763b1325fb1ea0d5dfd1005 Mon Sep 17 00:00:00 2001
From: zhangchengsong <zhangchengsong@hnkhzn.com>
Date: 星期四, 23 四月 2026 20:47:26 +0800
Subject: [PATCH] 最新

---
 项目代码/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs |   62 +++++++++++++++++++++----------
 1 files changed, 42 insertions(+), 20 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
index cff8018..c683664 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
@@ -27,6 +27,7 @@
 using WIDESEAWCS_ISystemServices;
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
+using WIDESEAWCS_Model;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_Model.Models.System;
 using WIDESEAWCS_QuartzJob;
@@ -49,17 +50,23 @@
         private readonly ITaskRepository _taskRepository;
         private readonly IRouterService _routerService;
         private readonly IDt_PlatformStationService _DtPlatformStationService;
+        private readonly IDt_roadwayinfoService _Dt_roadwayinfoService;
 
-        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IDt_PlatformStationService dt_PlatformStationService)
+        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IDt_roadwayinfoService dt_roadwayinfoService, ITaskRepository taskRepository, IRouterService routerService, IDt_PlatformStationService dt_PlatformStationService)
         {
             _taskService = taskService;
             _taskExecuteDetailService = taskExecuteDetailService;
             _taskRepository = taskRepository;
             _routerService = routerService;
             _DtPlatformStationService = dt_PlatformStationService;
+            _Dt_roadwayinfoService = dt_roadwayinfoService;
         }
         private static readonly Dictionary<string, bool> _deviceLastStatus = new Dictionary<string, bool>();
         public string urlWMSdeverror = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlWMSdeverror"];
+        private static readonly StackerFault[] _stackerFaultEnumCache = Enum.GetValues(typeof(StackerFault)).Cast<StackerFault>().ToArray();
+        // 鐢ㄦ潵璁板綍鍝簺浠诲姟宸茬粡涓婃姤杩囨斁璐т腑
+        private static readonly HashSet<int> _reportedPickupTaskIds = new HashSet<int>();
+
 
 
         public Task Execute(IJobExecutionContext context)
@@ -124,7 +131,7 @@
                             WebResponseContent webResponse = _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum, PalletCode);
                             if (webResponse.Status)
                             {
-                                Task.Run(() => WriteLog.Write_Log("鍫嗗灈鏈轰换鍔′笂鎶ュ畬鎴愪俊鎭�", "鍫嗗灈鏈轰换鍔′笂鎶ュ畬鎴愪俊鎭�", $"銆恵commonStackerCrane.DeviceCode}銆戝簱鍫嗗灈鏈轰笂鎶ヤ换鍔″彿:銆恵commonStackerCrane.CurrentTaskNum}銆戝畬鎴愪俊鍙凤紒"));
+                               WriteLog.Write_Log("鍫嗗灈鏈轰换鍔′笂鎶ュ畬鎴愪俊鎭�", "鍫嗗灈鏈轰换鍔′笂鎶ュ畬鎴愪俊鎭�", $"銆恵commonStackerCrane.DeviceCode}銆戝簱鍫嗗灈鏈轰笂鎶ヤ换鍔″彿:銆恵commonStackerCrane.CurrentTaskNum}銆戝畬鎴愪俊鍙凤紒");
 
                                 bool ddjfk = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                             }
@@ -257,12 +264,9 @@
         {
             try
             {
-                CommonConveyorLine? conveyorLine = null;
-                lock (Storage.Devices)
-                {
+                    CommonConveyorLine? conveyorLine = null;
                     string deviceCode = Roadway == "C" ? "1004" : "1003";
                     conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceCode) as CommonConveyorLine;
-                }
                 if (conveyorLine == null) return false;
 
                 DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "StationNum");
@@ -291,11 +295,8 @@
             {
 
                 CommonConveyorLine? conveyorLine = null;
-                lock (Storage.Devices)
-                {
                     string deviceCode = Roadway == "C" ? "1004" : "1003";
                     conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceCode) as CommonConveyorLine;
-                }
                 if (conveyorLine == null) return false;
 
                 DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SourceAddress && x.DeviceProParamName == "StationNum");
@@ -305,7 +306,7 @@
                 int StationNum = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
                 int HandShake = conveyorLine.Communicator.Read<ushort>(HandShakeprodto.DeviceProAddress);
                 WriteLog.Write_Log("鍏ュ簱搴撳彛鐘舵�佷俊鎭�", "鍏ュ簱搴撳彛鐘舵�佷俊鎭�", $"搴撳彛鏄�恵SourceAddress}銆戯紝鐢宠鐘舵�佸湴鍧�锛氥�恵HandShakeprodto.DeviceProAddress}銆�,璇诲彇鐨勬暟鎹細銆恵HandShake}銆慭n搴撳彛鏄惁鏈夎揣鐘舵�佸湴鍧�锛氥�恵deviceProDTO.DeviceProAddress}銆戯紝璇诲彇鐨勬暟鎹�恵StationNum}銆�");
-                return (StationNum == 1 && HandShake == 0) ? true : false;
+                return StationNum == 1;
             }
             catch (Exception ex)
             {
@@ -474,7 +475,28 @@
                 {
                     var dtTask = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
                     if (dtTask == null) return;
+                    //鍫嗗灈鏈烘斁璐т腑鏄换鍔$姸鎬佸洖璋冩嬁pickup
+                    // ===================== 鍑哄簱鏀捐揣涓細鍙笂鎶�1娆� =====================
+                    if (dtTask.TaskType == (int)TaskTypeEnum.Inbound && stackerCraneWorkStatusDes == "鏀捐揣涓�")
+                    {
+                        // 鍒ゆ柇鏄惁宸茬粡涓婃姤杩�
+                        if (_reportedPickupTaskIds.Contains(taskNum))
+                        {
+                            return; // 宸蹭笂鎶ワ紝鐩存帴璺宠繃
+                        }
+                        // 绗竴娆′笂鎶�
+                        string Result = WMSTaskStatusEnum.pickup.GetDescription();
+                        Dt_roadwayinfo roadwayinfo = _Dt_roadwayinfoService.GetRoadwayinfo(dtTask.Roadway);
+                        CommandResult command = _taskService.taskreturn(int.Parse(dtTask.WMStaskid), Result, roadwayinfo.WarehouseInvType, "");
 
+                        // 鏍囪涓哄凡涓婃姤
+                        _reportedPickupTaskIds.Add(taskNum);
+                    }
+                    // 浠诲姟瀹屾垚鏃舵竻鐞嗚褰�
+                    if (stackerCraneWorkStatusDes == "浠诲姟瀹屾垚")
+                    {
+                        _reportedPickupTaskIds.Remove(taskNum);
+                    }
                     string[] targets = { "G02", "G03", "G04", "C02", "C01" };
                     if (dtTask.TaskType != 100 || !targets.Contains(dtTask.TargetAddress)) return;
 
@@ -499,18 +521,21 @@
 
                     conveyorLine.Communicator.Write<short>(handShake.DeviceProAddress, writeValue);
                 }
-                catch
-                { }
+                catch(Exception e)
+                {
+                    WriteLog.Write_Log("鍑哄簱灞忚斀鍏夋爡/鍫嗗灈鍏ュ簱瑕佹斁璐у紓甯�", "閿欒", e.ToString());
+                }
         }
-
         /// <summary>
-        /// 璇诲彇鏁呴殰锛堜紭鍖朑C锛�
+        /// 鏁呴殰淇℃伅
         /// </summary>
+        /// <param name="crane"></param>
+        /// <returns></returns>
         public string ReadStackerFaults(CommonStackerCrane crane)
         {
             try
             {
-                foreach (StackerFault fault in Enum.GetValues(typeof(StackerFault)))
+                foreach (StackerFault fault in _stackerFaultEnumCache)
                 {
                     try
                     {
@@ -518,13 +543,10 @@
                         if (isFault)
                             return fault.GetDesc();
                     }
-                    catch { }
+                    catch { continue; }
                 }
             }
-            catch (Exception ex)
-            {
-                WriteLog.Write_Log("DB107鏁呴殰璇诲彇寮傚父", "閿欒", ex.ToString());
-            }
+            catch { }
             return string.Empty;
         }
     }

--
Gitblit v1.9.3