From 0e450768c357b45701a2e5ed162f4e93b3dd617c Mon Sep 17 00:00:00 2001
From: zhangchengsong <zhangchengsong@hnkhzn.com>
Date: 星期三, 15 四月 2026 20:53:24 +0800
Subject: [PATCH] 最新

---
 项目代码/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs |  131 ++++++++++++++++++++++++++-----------------
 1 files changed, 79 insertions(+), 52 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 0860808..91bc82b 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"
@@ -8,6 +8,8 @@
 using System.Collections.Generic;
 using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics.Eventing.Reader;
+using System.DirectoryServices.Protocols;
+using System.IO.Ports;
 using System.Linq;
 using System.Net;
 using System.Reflection.Metadata;
@@ -19,6 +21,7 @@
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Enums;
+using WIDESEAWCS_DTO.TaskInfo;
 using WIDESEAWCS_ISystemServices;
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
@@ -30,6 +33,7 @@
 using WIDESEAWCS_QuartzJob.Models;
 using WIDESEAWCS_QuartzJob.Service;
 using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
+using WIDESEAWCS_TaskInfoService;
 using WIDESEAWCS_Tasks.StackerCraneJob;
 
 namespace WIDESEAWCS_Tasks
@@ -52,13 +56,16 @@
             _DtPlatformStationService= dt_PlatformStationService;
         }
 
-        public Task Execute(IJobExecutionContext context)
+        public  Task Execute(IJobExecutionContext context)
         {
             try
             {
+
                 CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
                 if (commonStackerCrane != null)
                 {
+
+                    UpdateHandShake(commonStackerCrane.CurrentTaskNum, commonStackerCrane.StackerCraneWorkStatusDes);
                     //浠诲姟瀹屾垚StackerCraneWorkStatus
                     if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.WorkCompleted)
                     {
@@ -82,15 +89,13 @@
                             if (webResponse.Status)
                             {
                                 WriteLog.Write_Log("鍫嗗灈鏈轰换鍔′笂鎶ュ畬鎴愪俊鎭�", "鍫嗗灈鏈轰换鍔′笂鎶ュ畬鎴愪俊鎭�", $"銆恵commonStackerCrane.DeviceCode}銆戝簱鍫嗗灈鏈轰笂鎶ヤ换鍔″彿:銆恵commonStackerCrane.CurrentTaskNum}銆戝畬鎴愪俊鍙凤紒");
+
                                 bool ddjfk = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                             }
                         }
                     }
 
-                    WriteLog.Write_Log("鍫嗗灈鏈哄綋鍓嶇姸鎬�", "鍫嗗灈鏈哄綋鍓嶇姸鎬佷俊鎭�", $"鍫嗗灈鏈鸿澶囧湴鍧�:銆怐B105.2.0銆�,璇诲彇鐨勬暟鎹細銆恵commonStackerCrane.StackerCraneAutoStatusDes}銆慭n" +
-                           $"鍫嗗灈鏈哄伐浣滄ā寮忓湴鍧�:銆怐B105.3.0銆�,璇诲彇鐨勬暟鎹細銆恵commonStackerCrane.StackerCraneStatusDes}銆慭n" +
-                           $"鍫嗗灈鏈轰綔涓氱姸鎬佸湴鍧�:銆怐B105.22.0銆�,璇诲彇鐨勬暟鎹細銆恵commonStackerCrane.StackerCraneWorkStatusDes}銆慭n" +
-                           $"鍫嗗灈鏈哄綋鍓嶄换鍔℃墽琛屼腑鍦板潃:銆怐B105.18.0銆�,璇诲彇鐨勬暟鎹細銆恵commonStackerCrane.CurrentTaskNum}銆慭n");
+
                     if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal)
                     {
                        
@@ -172,7 +177,6 @@
                         }
                         else if (taskItem.TaskType == (int)TaskTypeEnum.Inbound || taskItem.TaskType == (int)TaskTypeEnum.Inventorybound)
                         {
-                            InTaskStationIsOccupied(taskItem.SourceAddress, taskItem.Roadway);
                             return taskItem;
                         }
                     }
@@ -207,8 +211,9 @@
 
                     int StationNum = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
                     int HandShake = conveyorLine.Communicator.Read<ushort>(HandShakeprodto.DeviceProAddress);
-                    WriteLog.Write_Log("鍑哄簱搴撳彛鐘舵�佷俊鎭�", "鍑哄簱搴撳彛鐘舵�佷俊鎭�", $"搴撳彛鏄�恵NextAddress}銆戯紝鐢宠鐘舵�佸湴鍧�锛氥�恵HandShakeprodto.DeviceProAddress}銆慭n" +
-                         $"璇诲彇鐨勬暟鎹細銆恵HandShake}銆戯紱搴撳彛鏄惁鏈夎揣鐘舵�佸湴鍧�锛氥�恵deviceProDTO.DeviceProAddress}銆戯紝璇诲彇鐨勬暟鎹�恵StationNum}銆�");
+
+                    WriteLog.Write_Log("鍑哄簱搴撳彛鐘舵�佷俊鎭�", "鍑哄簱搴撳彛鐘舵�佷俊鎭�", $"搴撳彛鏄�恵NextAddress}銆戯紝鐢宠鐘舵�佸湴鍧�锛氥�恵HandShakeprodto.DeviceProAddress}銆�,璇诲彇鐨勬暟鎹細銆恵HandShake}銆慭n" +
+                         $"搴撳彛鏄惁鏈夎揣鐘舵�佸湴鍧�锛氥�恵deviceProDTO.DeviceProAddress}銆戯紝璇诲彇鐨勬暟鎹�恵StationNum}銆�");
                     if (StationNum == 0 && HandShake == 0 && Roadway == "C")
                     {
                         return true;
@@ -241,44 +246,7 @@
 
             return false;
         }
-        /// <summary>
-        /// 鍏ュ簱浠诲姟搴撳彛鏈夎揣鏃犺揣鐘舵��
-        /// </summary>
-        private void InTaskStationIsOccupied(string SourceAddress, string Roadway)
-        {
-            try
-            {
-                if (Roadway == "C")
-                {
-                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1004");
-                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
-                    DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SourceAddress && x.DeviceProParamName == "StationNum");
-                    DeviceProDTO? HandShakeprodto = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SourceAddress && x.DeviceProParamName == "HandShake");
- 
-                    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}銆�");
-                }
-                else
-                {
-                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1003");
-                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
-                    DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SourceAddress && x.DeviceProParamName == "StationNum");
-                    DeviceProDTO? HandShakeprodto = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SourceAddress && x.DeviceProParamName == "HandShake");
 
-                    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}銆�");
-                }
-            }
-            catch (Exception ex)
-            {
-                Console.WriteLine("璇诲彇绔欏彴淇℃伅閿欒锛�" + ex.Message);
-            }
-
-        }
 
         /// <summary>
         /// 浠诲姟瀹炰綋杞崲鎴愬懡浠odel
@@ -290,15 +258,34 @@
         {
             StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand();
 
-
-            stackerCraneTaskCommand.Barcode = task.PalletCode;
             stackerCraneTaskCommand.TaskNum = task.TaskNum;
             stackerCraneTaskCommand.WorkType = 1;
             stackerCraneTaskCommand.TrayType = 0;
+            if (task.Roadway == "B" || task.Roadway == "C")
+            {
+                //鍒ゆ柇 task.PalletCode 鏄笉鏄竴涓湁鏁堢殑 GUID
+                stackerCraneTaskCommand.Barcode = stackerCraneTaskCommand.Barcode = Guid.TryParse(task.PalletCode, out var guid) ? guid.ToString("N")[0..6] : task.PalletCode;
+            }
+            else if (task.Roadway == "G" )
+            {
+                if (Guid.TryParse(task.PalletCode, out var palletGuid))
+                {
+                    stackerCraneTaskCommand.Barcode = palletGuid.ToString("N")[0..6];
+
+                    // 鏍囧噯GUID灏辨槸36浣嶏紝鎵�浠ョ洿鎺ュ垽鏂暱搴﹀嵆鍙�
+                    stackerCraneTaskCommand.TrayType = (short)(task.PalletCode.Length == 36 ? 1 : 2);
+                }
+                else
+                {
+                    stackerCraneTaskCommand.Barcode = task.PalletCode;
+                    stackerCraneTaskCommand.TrayType = 2;
+                }
+            }
+
             if (task.TaskType == (int)TaskTypeEnum.Inbound)//鍒ゆ柇鏄惁鏄叆搴撲换鍔�
             {
                 //鑾峰彇绔欏彴缂栧彿
-                Dt_PlatformStation dt_Platform=_DtPlatformStationService.getStatiomInfo(task.SourceAddress);
+                Dt_PlatformStation dt_Platform = _DtPlatformStationService.getStatiomInfo(task.SourceAddress);
                 string[] targetCodest = dt_Platform.Station_storey.Split("-");
                 if (targetCodest.Length == 3)
                 {
@@ -319,7 +306,7 @@
                     string EndRow = EndCodest[0].Substring(1);
                     string SCEndRow = LaneModification(task.Roadway, int.Parse(EndRow));
 
-                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(SCEndRow );
+                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(SCEndRow);
                     stackerCraneTaskCommand.EndColumn = Convert.ToInt16(EndCodest[1]);
                     stackerCraneTaskCommand.EndLayer = Convert.ToInt16(EndCodest[2]);
                 }
@@ -377,7 +364,7 @@
                 if (EndCodest.Length == 3)
                 {
                     string EndRow = EndCodest[0].Substring(1);
-                   string SCEnRow=LaneModification(task.Roadway,int.Parse(EndRow));
+                    string SCEnRow = LaneModification(task.Roadway, int.Parse(EndRow));
 
                     stackerCraneTaskCommand.EndRow = Convert.ToInt16(SCEnRow);
                     stackerCraneTaskCommand.EndColumn = (short)(Convert.ToInt16(EndCodest[1]) + 1);
@@ -385,13 +372,13 @@
                 }
                 else
                 {
-                    
+
                     //鏁版嵁閰嶇疆閿欒
                     _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�");
                     return null;
                 }
 
-               
+
             }
             return stackerCraneTaskCommand;
         }
@@ -410,5 +397,45 @@
                 return SCRow.ToString();
             }
         }
+        /// <summary>
+        /// 鐩戞祴G搴撱�丆搴撳嚭搴撴斁璐ф椂灞忚斀鍏夋爡
+        /// </summary>
+        /// <param name="taskNum"></param>
+        /// <param name="stackerCraneWorkStatusDes"></param>
+        public void UpdateHandShake(int taskNum, string stackerCraneWorkStatusDes)
+        {
+            try
+            {
+                Dt_Task? dtTask = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
+                if (dtTask == null) return;
+
+                string[] targetAddresses = { "G03", "G04", "C02", "C01" };
+                if (dtTask.TaskType != 100 || !targetAddresses.Contains(dtTask.TargetAddress))
+                    return;
+
+                short writeValue = stackerCraneWorkStatusDes switch
+                {
+                    "鏀捐揣涓�" => 1,
+                    "浠诲姟瀹屾垚" => 0,
+                    _ => -1
+                };
+
+                if (writeValue == -1) return;
+
+                string deviceCode = dtTask.CurrentAddress.StartsWith("C") ? "1004" : "1003";
+                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceCode);
+                if (device == null) return;
+
+                CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
+                DeviceProDTO? handShake = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == dtTask.TargetAddress && x.DeviceProParamName == "HandShake");
+                if (handShake == null) return;
+
+                conveyorLine.Communicator.Write<short>(handShake.DeviceProAddress, writeValue);
+            }
+            catch
+            {
+            }
+        }
+
     }
 }

--
Gitblit v1.9.3