From 0939aa5f3cc12a8856456a51cf2b661b6cd780c7 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期四, 31 七月 2025 17:25:49 +0800
Subject: [PATCH] 1

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs |  154 ++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 122 insertions(+), 32 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
index 894c017..4045cd2 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
@@ -26,6 +26,8 @@
 using WIDESEAWCS_Model.BasicInfo;
 using WIDESEAWCS_Tasks.RGVJob;
 using WIDESEAWCS_Tasks.ConveyorLineJob;
+using WIDESEAWCS_TaskInfoRepository;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
 
 namespace WIDESEAWCS_Tasks
 {
@@ -58,13 +60,6 @@
                 CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
                 if (commonStackerCrane != null)
                 {
-                    //if (!commonStackerCrane.IsEventSubscribed)
-                    //{
-                    //    commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//璁㈤槄浠诲姟瀹屾垚浜嬩欢
-                    //}
-
-                    //commonStackerCrane.CheckStackerCraneTaskCompleted();//闃叉浠诲姟瀹屾垚浜嬩欢鐩戞祴瓒呮椂锛屽啀鎵嬪姩瑙﹀彂涓�娆�
-
                     if (commonStackerCrane.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.TaskCompleted))
                     {
                         var x = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.CurrentTaskNum);
@@ -112,17 +107,69 @@
                     var userTokenIds = tokenInfos?.Select(x => x.Token_ID).ToList();
                     var userIds = tokenInfos?.Select(x => x.UserId).ToList();
 
+                    string StackerCraneAutoStatus(bool AutoStatus) => AutoStatus switch
+                    {
+                        true => "鑱旀満妯″紡",
+                        false => "鍗曟満妯″紡",
+                    };
+                    string StackerCraneWorkStatus(bool WorkStatus) => WorkStatus switch
+                    {
+                        true => "杩愯涓�",
+                        false => "寰呮満",
+                    };
+                    string StackerCraneStatus(bool Status) => Status switch
+                    {
+                        true => "鏁呴殰",
+                        false => "姝e父",
+                    };
+                    string StackerCraneAlarm(uint alarm) => alarm switch
+                    {
+                        0 => "鎸囦护鎴栧湴鍧�閿欒",
+                        1 => "鎬ュ仠",
+                        2 => "鍏夐�氳涓柇",
+                        3 => "缁勬�佸け鑱�",
+                        4 => "琛岃蛋鍙橀鏁呴殰",
+                        5 => "琛岃蛋鏋侀檺瑙﹀彂",
+                        6 => "琛岃蛋杩愯瓒呮椂",
+                        7 => "鎻愬崌鍙橀鏁呴殰",
+                        8 => "鎻愬崌鏋侀檺瑙﹀彂",
+                        9 => "鎻愬崌杩愯瓒呮椂",
+                        10 => "杞借揣鍙拌秴杞�",
+                        11 => "杞借揣鍙版瑺杞斤紙鏉剧怀)",
+                        12 => "杞借揣鍙板け閫�",
+                        13 => "璐у弶鍙橀鎶ヨ",
+                        14 => "璐у弶杩愯瓒呮椂",
+                        15 => "璐у弶鏋侀檺瑙﹀彂",
+                        16 => "璐у弶涓嶅眳涓�",
+                        17 => "宸︿晶瓒呴珮",
+                        18 => "鍙充晶瓒呴珮",
+                        19 => "宸︿晶瓒呭",
+                        20 => "鍙充晶瓒呭",
+                        21 => "宸﹁秴鍑�",
+                        22 => "鍙宠秴鍑�",
+                        23 => "鍙栬揣鏃惰浇璐у彴鏈夎揣",
+                        24 => "鍙栬揣鍚庤浇璐у彴鏃犺揣",
+                        25 => "鍙栨繁璐т綅鏃舵祬璐т綅鏈夎揣",
+                        26 => "鏀捐揣鏃惰浇璐у彴鏃犺揣",
+                        27 => "鏀捐揣鏃惰揣鏋舵湁璐�",
+                        28 => "鏀捐揣鍚庤浇璐у彴鏈夎揣",
+                        29 => "鏀炬繁璐ф椂娴呰揣浣嶆湁璐�",
+                        30 => "",
+                        31 => "",
+                    };
                     object obj = new
                     {
-                        Automatic = commonStackerCrane.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Automatic),
-                        Fault = commonStackerCrane.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Fault),
-                        Running = commonStackerCrane.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Running),
-                        //commonStackerCrane.StackerCraneAutoStatusDes,
-                        //commonStackerCrane.StackerCraneWorkStatusDes,
-                        //commonStackerCrane.DeviceCode,
-                        //commonStackerCrane.DeviceName,
-                        //commonStackerCrane.CurrentTaskNum,
-                        //commonStackerCrane.LastTaskNum,
+                        Automatic = StackerCraneAutoStatus(commonStackerCrane.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Automatic)),
+                        Fault = StackerCraneStatus(commonStackerCrane.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Fault)),
+                        Running = StackerCraneWorkStatus(commonStackerCrane.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Running)),
+                        CurrentColumn = Convert.ToInt32(commonStackerCrane.GetValue<StackerCraneDBName, byte>(StackerCraneDBName.CurrentColumn)),
+                        CurrentLayer = Convert.ToInt32(commonStackerCrane.GetValue<StackerCraneDBName, byte>(StackerCraneDBName.CurrentLayer)),
+                        LevelPoint = commonStackerCrane.GetValue<StackerCraneDBName, int>(StackerCraneDBName.LevelPoint),
+                        CurrentTaskNum = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.CurrentTaskNum),
+                        StackerAlarm = StackerCraneAlarm(commonStackerCrane.GetValue<StackerCraneDBName, uint>(StackerCraneDBName.StackerAlarm)),
+
+                        commonStackerCrane.DeviceCode,
+                        commonStackerCrane.DeviceName,
                     };
                     _noticeService.StackerData(userIds?.FirstOrDefault(), userTokenIds, new { commonStackerCrane.DeviceName, data = obj });
 
@@ -169,18 +216,37 @@
         {
             if (commonStackerCrane != null)
             {
-                #region 鏃ュ織璁板綍
-                ConsoleHelper.WriteColorLine($"銆恵commonStackerCrane.DeviceName}銆戝爢鍨涙満浣滀笟鐘舵�侊細銆愩�戞椂闂淬�恵DateTime.Now}銆�", ConsoleColor.Magenta);
-
-                string str = $"銆恵commonStackerCrane.DeviceName}銆戜换鍔″畬鎴�,浠诲姟鍙凤細銆恵TaskNum}銆戞椂闂淬�恵DateTime.Now}銆�";
-                WriteInfo(commonStackerCrane.DeviceName, str);
-                ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
-
-                #endregion
-
                 var task = _taskRepository.QueryFirst(x => x.TaskNum == TaskNum);
                 if (task != null)
                 {
+                    if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
+                    {
+                        if (Convert.ToInt32(task.TargetAddress) > 1999 && Convert.ToInt32(task.TargetAddress) < 3000)
+                        {
+
+                            Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationChildCode == task.TargetAddress);
+                            if (stationManager != null)
+                            {
+                                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC);
+                                if (device != null)
+                                {
+                                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
+
+                                    var InteractiveSignal = conveyorLine.GetValue<ConveyorLineDBName, byte>(ConveyorLineDBName.InteractiveSignal, stationManager.stationChildCode);
+
+                                    var structs = BitConverter.GetBytes(InteractiveSignal).ToArray().ToBoolArray();
+                                    if (structs[2])
+                                    {
+                                        conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, Convert.ToInt16(stationManager.stationNextChildCode), stationManager.stationChildCode);
+                                        Thread.Sleep(100);
+                                        conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTaskNum, Convert.ToInt16(task.TaskNum), stationManager.stationChildCode);
+                                        Thread.Sleep(100);
+                                        conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(2), stationManager.stationChildCode);
+                                    }
+                                }
+                            }
+                        }
+                    }
                     var content = _taskService.StackCraneTaskCompleted(TaskNum);
                 }
             }
@@ -317,7 +383,7 @@
         {
             StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand();
 
-            stackerCraneTaskCommand.TaskNum = (byte)Convert.ToSByte(task.TaskNum);
+            stackerCraneTaskCommand.TaskNum = (short)Convert.ToInt16(task.TaskNum);
             if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//鍒ゆ柇鏄惁鏄叆搴撲换鍔�
             {
 
@@ -328,7 +394,7 @@
                     string[] sourceCodes = stationManager.stationLocation.Split("-");
                     if (sourceCodes.Length == 3)
                     {
-                        stackerCraneTaskCommand.StartRow = (byte)Convert.ToSByte(sourceCodes[0]);
+                        stackerCraneTaskCommand.StartRow = (byte)Convert.ToSByte(GetRowCode(Convert.ToInt32(sourceCodes[0])));
                         stackerCraneTaskCommand.StartColumn = (byte)Convert.ToSByte(sourceCodes[1]);
                         stackerCraneTaskCommand.StartLayer = (byte)Convert.ToSByte(sourceCodes[2]);
                     }
@@ -342,7 +408,7 @@
                     string[] targetCodes = task.TargetAddress.Split("-");
                     if (targetCodes.Length == 3)
                     {
-                        stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(targetCodes[0]);
+                        stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(GetRowCode(Convert.ToInt32(targetCodes[0])));
                         stackerCraneTaskCommand.EndColumn = (byte)Convert.ToSByte(targetCodes[1]);
                         stackerCraneTaskCommand.EndLayer = (byte)Convert.ToSByte(targetCodes[2]);
                     }
@@ -368,7 +434,7 @@
                     string[] sourceCodes = task.CurrentAddress.Split("-");
                     if (sourceCodes.Length == 3)
                     {
-                        stackerCraneTaskCommand.StartRow = (byte)Convert.ToSByte(sourceCodes[0]);
+                        stackerCraneTaskCommand.StartRow = (byte)Convert.ToSByte(GetRowCode(Convert.ToInt32(sourceCodes[0])));
                         stackerCraneTaskCommand.StartColumn = (byte)Convert.ToSByte(sourceCodes[1]);
                         stackerCraneTaskCommand.StartLayer = (byte)Convert.ToSByte(sourceCodes[2]);
                     }
@@ -381,7 +447,7 @@
                     string[] targetCodes = stationManager.stationLocation.Split("-");
                     if (targetCodes.Length == 3)
                     {
-                        stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(targetCodes[0]);
+                        stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(GetRowCode(Convert.ToInt32(targetCodes[0])));
                         stackerCraneTaskCommand.EndColumn = (byte)Convert.ToSByte(targetCodes[1]);
                         stackerCraneTaskCommand.EndLayer = (byte)Convert.ToSByte(targetCodes[2]);
                     }
@@ -404,7 +470,7 @@
                 string[] sourceCodes = task.SourceAddress.Split("-");
                 if (sourceCodes.Length == 3)
                 {
-                    stackerCraneTaskCommand.StartRow = (byte)Convert.ToSByte(Convert.ToInt16(sourceCodes[0]) % 2 != 0 ? (short)1 : (short)2);
+                    stackerCraneTaskCommand.StartRow = (byte)Convert.ToSByte(GetRowCode(Convert.ToInt32(sourceCodes[0])));
                     stackerCraneTaskCommand.StartColumn = (byte)Convert.ToSByte(sourceCodes[1]);
                     stackerCraneTaskCommand.StartLayer = (byte)Convert.ToSByte(sourceCodes[2]);
                 }
@@ -417,7 +483,7 @@
                 string[] targetCodes = task.TargetAddress.Split("-");
                 if (targetCodes.Length == 3)
                 {
-                    stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(Convert.ToInt16(targetCodes[0]) % 2 != 0 ? (short)1 : (short)2);
+                    stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(GetRowCode(Convert.ToInt32(targetCodes[0])));
                     stackerCraneTaskCommand.EndColumn = (byte)Convert.ToSByte(targetCodes[1]);
                     stackerCraneTaskCommand.EndLayer = (byte)Convert.ToSByte(targetCodes[2]);
                 }
@@ -430,5 +496,29 @@
             }
             return stackerCraneTaskCommand;
         }
+
+        public int GetRowCode(int number)
+        {
+            if (number == 1 || number == 15 || number == 11 || number == 19)
+            {
+                return 1;
+            }
+            else if (number == 2 || number == 5 || number == 8 || number == 12 || number == 16 || number == 20)
+            {
+                return 2;
+            }
+            else if (number == 3 || number == 6 || number == 9 || number == 13 || number == 17 || number == 21)
+            {
+                return 3;
+            }
+            else if (number == 4 || number == 7 || number == 10 || number == 14 || number == 18 || number == 22)
+            {
+                return 4;
+            }
+            else
+            {
+                throw new ArgumentOutOfRangeException(nameof(number), "杈撳叆鐨勬暟瀛楀繀椤诲湪1-16鑼冨洿鍐�");
+            }
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3