From 5da3a276b7847187a7c155ee069d3cd4c9e58074 Mon Sep 17 00:00:00 2001
From: HuBingJie <3146306518@qq.com>
Date: 星期日, 07 十二月 2025 23:28:14 +0800
Subject: [PATCH] 1

---
 代码管理/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RgvoperainformService.cs | 1032 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 973 insertions(+), 59 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RgvoperainformService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RgvoperainformService.cs"
index 5737886..e2a6bc2 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RgvoperainformService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RgvoperainformService.cs"
@@ -1,4 +1,4 @@
-锘�#region << 鐗� 鏈� 娉� 閲� >>
+#region << 鐗� 鏈� 娉� 閲� >>
 /*----------------------------------------------------------------
  * 鍛藉悕绌洪棿锛歐IDESEAWCS_TaskInfoService
  * 鍒涘缓鑰咃細鑳$搴�
@@ -25,6 +25,7 @@
 using Newtonsoft.Json;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
+using Quartz.Util;
 using SqlSugar;
 using System;
 using System.Collections.Generic;
@@ -40,7 +41,9 @@
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEA_Comm.Http;
+using WIDESEA_Common.Log;
 using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.BaseRepository;
 using WIDESEAWCS_Core.BaseServices;
 using WIDESEAWCS_Core.Enums;
 using WIDESEAWCS_DTO.Enum;
@@ -58,43 +61,45 @@
 {
     public class RgvoperainformService : ServiceBase<Dt_Task_hty, ITask_HtyRepository>, IRgvoperainformService
     {
-        private readonly IAgvStationService _gvStationService;
+        private readonly IAgvStationService _agvStationService;
         private readonly IServiceProvider _serviceProvider;
         private static bool _isMonitoring = false;
+        private readonly IRepository<DeviceAlarmLog> _deviceAlarmLog;
         //private static CancellationTokenSource _cancellationTokenSource;
-        
+
         // 鍦ㄧ被绾у埆娣诲姞鐙珛鐨勭洃鎺х姸鎬�
         private bool _isOutboundMonitoring = false;
         private bool _isInboundMonitoring = false;
         private bool _isSafetyDoorMonitoring = false;
+        private bool _isPlatformMonitoring = false;
 
+        // 鍦ㄧ被鐨勫瓧娈靛尯
+        private CancellationTokenSource? _platformCancellationTokenSource;
         private CancellationTokenSource _outboundCancellationTokenSource;
         private CancellationTokenSource _inboundCancellationTokenSource;
         private CancellationTokenSource _safetyDoorCancellationTokenSource;
-        public RgvoperainformService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService, IServiceProvider serviceProvider) : base(BaseDal)
+        public RgvoperainformService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService, IServiceProvider serviceProvider, IRepository<DeviceAlarmLog> deviceAlarmLog) : base(BaseDal)
         {
-            _gvStationService = agvStationService;
+            _agvStationService = agvStationService;
             _serviceProvider = serviceProvider;
+            _deviceAlarmLog = deviceAlarmLog;
         }
 
 
         //=================================================璇诲彇璁惧淇℃伅==========================================================
 
-
-
-
-
         /// <summary>
-        /// 鑾峰彇璁惧鐘舵�侊紙鏀寔鍑哄簱銆佸叆搴撳拰瀹夊叏闂ㄧ嫭绔嬬洃鎺э級
+        /// 鑾峰彇璁惧鐘舵�侊紙鏀寔鍑哄簱銆佸叆搴撱�佸畨鍏ㄩ棬鍜岀珯鍙扮嫭绔嬬洃鎺э級
         /// </summary>
         /// <param name="off">0:鍋滄 1:鍚姩 2:浠呮煡璇�</param>
-        /// <param name="monitorType">鐩戞帶绫诲瀷锛歰utbound-鍑哄簱 inbound-鍏ュ簱 safetydoor-瀹夊叏闂� all-鍏ㄩ儴</param>
+        /// <param name="monitorType">鐩戞帶绫诲瀷锛歰utbound-鍑哄簱 inbound-鍏ュ簱 safetydoor-瀹夊叏闂� platform-绔欏彴 all-鍏ㄩ儴</param>
         /// <returns></returns>
         public WebResponseContent GetDeviceStatusDto(int off, string monitorType = "outbound")
         {
             bool isOutbound = monitorType == "outbound" || monitorType == "all";//鍑哄簱
             bool isInbound = monitorType == "inbound" || monitorType == "all";//鍏ュ簱
             bool isSafetyDoor = monitorType == "safetydoor" || monitorType == "all";//瀹夊叏闂�
+            bool isPlatform = monitorType == "platform" || monitorType == "all";//绔欏彴
 
             if (off == 1)
             {
@@ -120,6 +125,13 @@
                     _ = Task.Run(async () => await StartDeviceMonitoring(_safetyDoorCancellationTokenSource.Token, "safetydoor"));
                 }
 
+                if (isPlatform && !_isPlatformMonitoring)
+                {
+                    _isPlatformMonitoring = true;
+                    _platformCancellationTokenSource = new CancellationTokenSource();
+                    _ = Task.Run(async () => await StartDeviceMonitoring(_platformCancellationTokenSource.Token, "platform"));
+                }
+
                 var immediateData = GetImmediateDeviceData(monitorType);
                 string message = GetMonitorStatusMessage(monitorType);
                 return WebResponseContent.Instance.OK($"璁惧鐘舵�佺洃鎺у凡鍚姩 - {message}", immediateData);
@@ -143,6 +155,12 @@
                 {
                     _isSafetyDoorMonitoring = false;
                     _safetyDoorCancellationTokenSource?.Cancel();
+                }
+
+                if (isPlatform && _isPlatformMonitoring)
+                {
+                    _isPlatformMonitoring = false;
+                    _platformCancellationTokenSource?.Cancel();
                 }
 
                 var finalData = GetImmediateDeviceData(monitorType);
@@ -212,6 +230,9 @@
                 case "safetydoor":
                     _isSafetyDoorMonitoring = false;
                     break;
+                case "platform":
+                    _isPlatformMonitoring = false;
+                    break;
             }
         }
 
@@ -236,7 +257,14 @@
                 ["MaterialIn"] = new List<string> { "RGV101" },
 
                 // 瀹夊叏闂ㄨ澶�
-                ["SafetyDoor"] = new List<string> { "HCJ2000" }, // 瀹夊叏闂�
+                ["SafetyDoor"] = new List<string> { "HCJ2000" },
+
+                // 绔欏彴璁惧 - 鏍规嵁鎮ㄦ彁渚涚殑鍗忚娣诲姞鎵�鏈夌珯鍙�
+                //        ["Platform"] = new List<string> {
+                //    "1001", "1002", "2016", "2017", "2018", "2019", "1021", "1061", "1131", "1171"
+                //}
+                ["Platform"] = new List<string> { "HCJ2000" },
+
             };
 
             // 璁惧绫诲瀷瀵瑰簲鐨勫弬鏁伴厤缃�
@@ -339,6 +367,13 @@
             ("ResetStatus", "ReadDeviceCommand", "瀹夊叏闂ㄥ浣嶇姸鎬�"),
             ("AlarmSummary", "DeviceCommand", "鎶ヨ淇℃伅"),
             ("OpenDoor", "DeviceCommand", "寮�闂ㄤ俊鎭�")
+        },
+
+                // 绔欏彴璁惧鍙傛暟閰嶇疆 - 鏍规嵁鎮ㄦ彁渚涚殑鍗忚娣诲姞
+                ["Platform"] = new List<(string, string, string)>
+        {
+            ("HCJ_GoodsStatus", "ReadDeviceCommand", "鍏夌數淇″彿"),
+            ("DoorRequest", "DeviceCommand", "浠诲姟id")
         }
             };
 
@@ -352,13 +387,13 @@
                 {
                     "outbound" => group.Key == "MotherCar" || group.Key == "TransferCar" || group.Key == "MaterialOut",
                     "inbound" => group.Key == "MaterialIn" || group.Key == "InboundMotherCar" || group.Key == "InboundTransferCar",
-                    "safetydoor" => group.Key == "SafetyDoor", // 瀹夊叏闂ㄧ洃鎺х被鍨�
+                    "safetydoor" => group.Key == "SafetyDoor",
+                    "platform" => group.Key == "Platform", // 绔欏彴鐩戞帶绫诲瀷
                     "all" => true,
                     _ => group.Key == "MotherCar" || group.Key == "TransferCar" || group.Key == "MaterialOut"
                 };
             }).ToDictionary(x => x.Key, x => x.Value);
 
-            int i = 0;
             // 閬嶅巻绛涢�夊悗鐨勮澶囩粍
             foreach (var deviceGroup in filteredDeviceGroups)
             {
@@ -413,57 +448,83 @@
                     }
                     else if (device is CommonConveyorLine conveyorLine)
                     {
-                        // 澶勭悊瀹夊叏闂ㄨ澶囷紙CommonConveyorLine 绫诲瀷锛�
-                        // 鍒涘缓涓変釜瀹夊叏闂ㄨ澶囩殑鏁版嵁
-                        List<string> safetyDoorList = new List<string> { "AQM001", "AQM002", "AQM003" };
-
-                        // 涓烘瘡涓畨鍏ㄩ棬鍒涘缓鏁版嵁
-                        foreach (string safetyDoorCode in safetyDoorList)
+                        // 澶勭悊瀹夊叏闂ㄨ澶囧拰绔欏彴璁惧锛圕ommonConveyorLine 绫诲瀷锛�
+                        if (deviceType == "SafetyDoor")
                         {
-                            var deviceData = new Dictionary<string, int>();
+                            // 瀹夊叏闂ㄨ澶囧鐞嗛�昏緫锛堜繚鎸佷笉鍙橈級
+                            List<string> safetyDoorList = new List<string> { "AQM001", "AQM002", "AQM003" };
 
-                            // 閬嶅巻璇ヨ澶囩殑鎵�鏈夊弬鏁�
-                            foreach (var param in deviceParams)
+                            foreach (string safetyDoorCode in safetyDoorList)
                             {
-                                try
-                                {
-                                    // 浣跨敤瀹夊叏闂ㄥ悕绉版煡璇㈠搴旂殑鍙傛暟
-                                    DeviceProDTO? devicePro = GetSafetyDoorDeviceProDTO(
-                                        conveyorLine, safetyDoorCode, param.DeviceProParamName, param.DeviceProParamType);
+                                var deviceData = new Dictionary<string, int>();
 
-                                    if (devicePro != null)
-                                    {
-                                        // 瀵逛簬 CommonConveyorLine 绫诲瀷锛屼娇鐢ㄩ�氱敤鐨勬暟鎹鍙栨柟娉�
-                                        int res = ReadCommonConveyorLineData(conveyorLine, devicePro.DeviceProAddress);
-                                        deviceData[param.DeviceProRemark] = res;
-                                    }
-                                    else
-                                    {
-                                        deviceData[param.DeviceProRemark] = -1; // 浣跨敤 -1 琛ㄧず鏌ヨ澶辫触
-                                    }
-                                }
-                                catch (Exception)
+                                foreach (var param in deviceParams)
                                 {
-                                    deviceData[param.DeviceProRemark] = -1; // 浣跨敤 -1 琛ㄧず鏌ヨ寮傚父
+                                    try
+                                    {
+                                        DeviceProDTO? devicePro = GetSafetyDoorDeviceProDTO(
+                                            conveyorLine, safetyDoorCode, param.DeviceProParamName, param.DeviceProParamType);
+
+                                        if (devicePro != null)
+                                        {
+                                            int res = ReadCommonConveyorLineData(conveyorLine, devicePro.DeviceProAddress);
+                                            deviceData[param.DeviceProRemark] = res;
+                                        }
+                                        else
+                                        {
+                                            deviceData[param.DeviceProRemark] = -1;
+                                        }
+                                    }
+                                    catch (Exception)
+                                    {
+                                        deviceData[param.DeviceProRemark] = -1;
+                                    }
                                 }
+
+                                finalResult[safetyDoorCode] = deviceData;
                             }
+                        }
 
-                            // 灏嗗綋鍓嶅畨鍏ㄩ棬璁惧鐨勬暟鎹坊鍔犲埌鏈�缁堢粨鏋滀腑锛屼娇鐢ㄥ畨鍏ㄩ棬鍚嶇О浣滀负key
-                            finalResult[safetyDoorCode] = deviceData;
+                        if (deviceType == "Platform")
+                        {
+                            // 瀹夊叏闂ㄨ澶囧鐞嗛�昏緫锛堜繚鎸佷笉鍙橈級
+                            List<string> PlatformList = new List<string> { "1001", "1002", "2016", "2017", "2018", "2019", "1021", "1061", "1131", "1171" };
+
+                            foreach (string Platform in PlatformList)
+                            {
+                                var deviceData = new Dictionary<string, int>();
+
+                                foreach (var param in deviceParams)
+                                {
+                                    try
+                                    {
+                                        DeviceProDTO? devicePro = GetSafetyDoorDeviceProDTO(
+                                            conveyorLine, Platform, param.DeviceProParamName, param.DeviceProParamType);
+
+                                        if (devicePro != null)
+                                        {
+                                            int res = ReadCommonConveyorLineData(conveyorLine, devicePro.DeviceProAddress);
+                                            deviceData[param.DeviceProRemark] = res;
+                                        }
+                                        else
+                                        {
+                                            deviceData[param.DeviceProRemark] = -1;
+                                        }
+                                    }
+                                    catch (Exception)
+                                    {
+                                        deviceData[param.DeviceProRemark] = -1;
+                                    }
+                                }
+
+                                finalResult[Platform] = deviceData;
+                            }
                         }
                     }
                     else
                     {
                         // 鍗充娇璁惧涓嶅瓨鍦ㄦ垨涓嶆槸鏀寔鐨勭被鍨嬶紝涔熷垱寤轰竴涓┖瀛楀吀
                         finalResult[deviceChildCode] = new Dictionary<string, int>();
-                        if (device != null)
-                        {
-                            Console.WriteLine($"璀﹀憡锛氳澶� {deviceChildCode} 绫诲瀷 {device.GetType().Name} 涓嶆敮鎸侊紝鏃犳硶璇诲彇鏁版嵁");
-                        }
-                        else
-                        {
-                            Console.WriteLine($"璀﹀憡锛氳澶� {deviceChildCode} 涓嶅瓨鍦�");
-                        }
                     }
                 }
             }
@@ -483,7 +544,8 @@
                 "outbound" => $"鍑哄簱鐩戞帶: {(_isOutboundMonitoring ? "杩愯涓�" : "宸插仠姝�")}",
                 "inbound" => $"鍏ュ簱鐩戞帶: {(_isInboundMonitoring ? "杩愯涓�" : "宸插仠姝�")}",
                 "safetydoor" => $"瀹夊叏闂ㄧ洃鎺�: {(_isSafetyDoorMonitoring ? "杩愯涓�" : "宸插仠姝�")}",
-                "all" => $"鍑哄簱鐩戞帶: {(_isOutboundMonitoring ? "杩愯涓�" : "宸插仠姝�")}, 鍏ュ簱鐩戞帶: {(_isInboundMonitoring ? "杩愯涓�" : "宸插仠姝�")}, 瀹夊叏闂ㄧ洃鎺�: {(_isSafetyDoorMonitoring ? "杩愯涓�" : "宸插仠姝�")}",
+                "platform" => $"绔欏彴鐩戞帶: {(_isPlatformMonitoring ? "杩愯涓�" : "宸插仠姝�")}", // 绔欏彴鐩戞帶鐘舵��
+                "all" => $"鍑哄簱鐩戞帶: {(_isOutboundMonitoring ? "杩愯涓�" : "宸插仠姝�")}, 鍏ュ簱鐩戞帶: {(_isInboundMonitoring ? "杩愯涓�" : "宸插仠姝�")}, 瀹夊叏闂ㄧ洃鎺�: {(_isSafetyDoorMonitoring ? "杩愯涓�" : "宸插仠姝�")}, 绔欏彴鐩戞帶: {(_isPlatformMonitoring ? "杩愯涓�" : "宸插仠姝�")}",
                 _ => $"鍑哄簱鐩戞帶: {(_isOutboundMonitoring ? "杩愯涓�" : "宸插仠姝�")}"
             };
         }
@@ -500,11 +562,11 @@
                 "outbound" => "鍑哄簱",
                 "inbound" => "鍏ュ簱",
                 "safetydoor" => "瀹夊叏闂�",
+                "platform" => "绔欏彴", // 绔欏彴鏄剧ず鍚嶇О
                 "all" => "鍏ㄩ儴",
                 _ => "鍑哄簱"
             };
         }
-
 
         /// <summary>
         /// 璇诲彇璁惧淇℃伅
@@ -517,7 +579,6 @@
             return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
         }
 
-
         /// <summary>
         /// 鏌ヨ瀹夊叏闂ㄨ澶�
         /// </summary>
@@ -528,6 +589,19 @@
         public static DeviceProDTO? GetSafetyDoorDeviceProDTO(CommonConveyorLine Commonstacker, string SCAddress, string DeviceProParamName, string DeviceProParamType)
         {
             return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == DeviceProParamName && x.DeviceProParamType == DeviceProParamType);
+        }
+
+        /// <summary>
+        /// 鏌ヨ绔欏彴璁惧
+        /// </summary>
+        /// <param name="Commonstacker"></param>
+        /// <param name="PlatformCode">绔欏彴缂栧彿</param>
+        /// <param name="DeviceProParamName">鍙傛暟鍚嶇О</param>
+        /// <param name="DeviceProParamType">鍙傛暟绫诲瀷</param>
+        /// <returns></returns>
+        public static DeviceProDTO? GetPlatformDeviceProDTO(CommonConveyorLine Commonstacker, string PlatformCode, string DeviceProParamName, string DeviceProParamType)
+        {
+            return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == PlatformCode && x.DeviceProParamName == DeviceProParamName && x.DeviceProParamType == DeviceProParamType);
         }
 
         //=================================================璇诲彇璁惧淇℃伅==========================================================
@@ -590,7 +664,7 @@
             int zhi = 1002011;
             try
             {
-
+                
             switch (operationType)
             {
                 case "cs":          //鍒濆鍖�
@@ -624,14 +698,39 @@
                     DeviceProParamName = "RGV_Risingsignalplace";
                     DeviceProParamType = "DeviceCommand";
                     zhi = parameter;
-                    break;
-                case "xj":          //涓嬮檷
+                    DeviceProDTO? RGV_Resetoperationss1 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, DeviceProParamName, DeviceProParamType);        //涓婂崌
+                    RgvOperationService.RgvSetLine(Commonstacker, RGV_Resetoperationss1.DeviceProAddress, (short)zhi);
+                    //DeviceProDTO? RGV_Resetoperationss2 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, "RGV_Risingsignalplace", "ReadDeviceCommand");        //涓婂崌鍒颁綅淇″彿
+                    //    int resss = 0;
+                    //    while (resss == 0)
+                    //    {
+                    //        Thread.Sleep(2000);
+                    //        resss = RgvOperationService.GetLine(Commonstacker, RGV_Resetoperationss2.DeviceProAddress);
+                    //    }
+                    //    DeviceProDTO? RGV_Resetoperationss3 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, DeviceProParamName, DeviceProParamType);        //涓婂崌
+                    //    RgvOperationService.RgvSetLine(Commonstacker, RGV_Resetoperationss3.DeviceProAddress, 0);
+                        return webResponse.OK();
+
+                    case "xj":          //涓嬮檷
                     DeviceProParamName = "RGV_Descentsignal";
                     DeviceProParamType = "DeviceCommand";
                     zhi = parameter;
-                    break;
+                        DeviceProDTO? RGV_Resetoperationxj1 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, DeviceProParamName, DeviceProParamType);        //涓嬮檷
+                        RgvOperationService.RgvSetLine(Commonstacker, RGV_Resetoperationxj1.DeviceProAddress, (short)zhi);
+                        //DeviceProDTO? RGV_Resetoperationxj2 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, "RGV_Descentsignal", "ReadDeviceCommand");        //涓嬮檷鍒颁綅淇″彿
+                        //int resxj = 0;
+                        //while (resxj == 0)
+                        //{
+                        //    Thread.Sleep(2000);
+                        //    resxj = RgvOperationService.GetLine(Commonstacker, RGV_Resetoperationxj2.DeviceProAddress);
+                        //}
+                        //DeviceProDTO? RGV_Resetoperationxj3 = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, deviceName, DeviceProParamName, DeviceProParamType);        //涓婂崌
+                        //RgvOperationService.RgvSetLine(Commonstacker, RGV_Resetoperationxj3.DeviceProAddress, 0);
+                        return webResponse.OK();
                 case "dz":          //鍦板潃
-                    DeviceProParamName = "RGV_RGVTasklocationt";
+
+                        if (!YiDongPD(Commonstacker, parameter)) { return webResponse.Error("鐩爣鍦板潃琚崰鐢ㄦ垨鏉′欢涓嶆弧瓒筹紝绂佹绉诲姩"); }
+                        DeviceProParamName = "RGV_RGVTasklocationt";
                     DeviceProParamType = "DeviceCommand";
                     zhi = parameter;
                         //鑾峰彇瀹炰緥
@@ -684,6 +783,657 @@
                 return webResponse.Error("璁惧鎿嶄綔澶辫触");
             }
 
+        }
+
+    /// <summary>
+    /// 1銆佸垽鏂瓙杞﹀尯鍩�
+    /// 2銆佸垽鏂瓙杞﹀綋鍓嶄綅缃�
+    /// 3銆佸垽鏂瓙杞﹁鍘荤殑浣嶇疆
+    /// 4銆佹牴鎹瓙杞﹁鍘荤殑涓鸿幏鍙栨瘝杞︿綅缃�
+    /// 
+    /// </summary>
+    /// <param name="device">瑕佺Щ鍔ㄧ殑璁惧</param>
+    /// <param name="parameter">瑕佸幓鐨勭洰鏍囧湴鍧�</param>
+    /// <returns></returns>
+
+        private bool YiDongPD(SpeStackerCrane Commonstacker, int parameter)
+        {
+
+            //鍏ュ簱璁惧
+            List<string> InDevices = new List<string> {  "RGV104", "RGV107" };
+            //鍑哄簱璁惧
+            List<string>  OutDevices = new List<string> {"RGV116", "RGV111"};
+
+            Dictionary<int, string> HCJ = new Dictionary<int, string>
+        {
+            { 1061, "HCJ106" },
+            { 1021, "HCJ102" },
+            { 1131, "HCJ113" },
+            { 1171, "HCJ117" },
+        };
+
+            AGVStation RGVTaskdevice = _agvStationService.Corridorequipment(Commonstacker.DeviceCode);   //鏍规嵁璁惧鑾峰彇鍒板唴瀹�
+
+            //鏍规嵁瀛愯溅鑾峰彇鍒版瘝杞﹁澶�
+            // 鏍规嵁瀛愯溅鑾峰彇鍒版瘝杞﹁澶�
+            AGVStation Mu1 = _agvStationService.GetMothervehicle(RGVTaskdevice.MotherCarDeviceCode);
+            AGVStation Mu2 = _agvStationService.GetMothervehicle(RGVTaskdevice.MotherCardeputy);
+
+            // 鑾峰彇瀛愯溅浣嶇疆
+            int zhicheWZ = GetzicheWZ(Commonstacker, Commonstacker.DeviceCode);
+
+            // 缁熶竴鐩爣鍗犵敤妫�鏌ワ紙鎵弿鍏跺畠 RGV 鏄惁鍦ㄥ悓涓�鐩爣鍦板潃锛�
+            bool IsAddressOccupied(int addr)
+            {
+                var allCodes = InDevices.Concat(OutDevices).Where(code => code != Commonstacker.DeviceCode).ToList();
+                foreach (var code in allCodes)
+                {
+                    var dev = Storage.Devices.FirstOrDefault(x => x.DeviceCode == code) as SpeStackerCrane;
+                    if (dev == null) continue;
+                    try
+                    {
+                        DeviceProDTO? locDto = RgvOperationService.GetRGVDeviceProDTO(dev, code, "RGVCurrentlocation", "RGVCurrentlocation");
+                        if (locDto == null) continue;
+                        int loc = RgvOperationService.GetLine(dev, locDto.DeviceProAddress);
+                        if (loc == addr) return true; // 鐩爣琚崰鐢�
+                    }
+                    catch
+                    {
+                        // 璇诲彇寮傚父涓嶅綋浣滃崰鐢紝閬垮厤璇嫆
+                    }
+                }
+                return false;
+            }
+
+            // 鐩爣琚叾浠� RGV 鍗犵敤鍒欑姝�
+            if (IsAddressOccupied(parameter)) return false;
+
+            if (RGVTaskdevice.Station_Area == 6) // 澶栦晶
+            {
+                if (zhicheWZ == RGVTaskdevice.WaitmomentOne) // 绛夊緟鐐�1
+                {
+                    // 鍒ゆ柇澶栦晶灏忚溅鏄惁鍦� HCJ 涓�
+                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
+                    int waiziche = GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
+
+                    //鍒ゆ柇浼犺繘鏉ヨ澶囨槸鍚︽槸鍏ュ簱
+                    if (InDevices.Contains(Commonstacker.DeviceCode))
+                    {
+                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress))
+                        {
+                            return false;
+                        }
+                    }
+                    else
+                    {
+                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1171) && waiziche != zichestation.HCJStorageaddress))
+                        {
+                            return false;
+                        }
+                    }
+
+                    if (parameter == Mu1.ZicheMotherinlaw) //姣�1
+                    {
+                        int taraddress = parameter;
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 == Mu1.ZicheMotherinlaw && mu1 != Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }
+                    else if (parameter == Mu2.ZicheMotherinlaw) // 姣�2
+                    {
+                        int taraddress = parameter;
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
+
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.ZicheMotherinlaw && mu2 != Mu2.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }
+                    else if (parameter == RGVTaskdevice.HCJStorageaddress)
+                    {
+                        string hcj = HCJ[RGVTaskdevice.HCJStorageaddress];
+                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
+
+                        if (Mucheywhaddres(Mu2.ChildPosiDeviceCode) && Mucheywhaddres(hcj))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu2 != Mu2.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && !IsAddressOccupied(Mu2.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }else if(parameter == 1021 || parameter == 1171)
+                    {
+                        if (RGVTaskdevice.ChildPosiDeviceCode == "RGV116" && Mucheywhaddres("HCJ102"))
+                        {
+                            return true;
+                        }
+                        string hcj = HCJ[parameter];
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(hcj))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 != Mu1.ZicheMotherinlaw && mu1 == Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }
+                    else
+                    {
+                        int taraddress = parameter;
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
+
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+
+                        }
+                    }
+                }
+                else if (zhicheWZ == RGVTaskdevice.WaitmomentTwo) // 绛夊緟鐐�2
+                {
+                    // 鍒ゆ柇澶栦晶灏忚溅鏄惁鍦� HCJ 涓�
+                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
+                    int waiziche = GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
+
+                    //鍒ゆ柇浼犺繘鏉ヨ澶囨槸鍚︽槸鍏ュ簱
+                    if (InDevices.Contains(Commonstacker.DeviceCode))
+                    {
+                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress))
+                        {
+                            return false;
+                        }
+                    }
+                    else
+                    {
+                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1171) && waiziche != zichestation.HCJStorageaddress))
+                        {
+                            return false;
+                        }
+                    }
+
+                    if (parameter == Mu1.ZicheMotherinlaw)
+                    {
+                        int taraddress = parameter;
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 == Mu1.ZicheMotherinlaw && mu1 != Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }
+                    else if (parameter == Mu2.ZicheMotherinlaw)
+                    {
+                        int taraddress = parameter;
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
+
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }
+                    else if (parameter == RGVTaskdevice.HCJStorageaddress)
+                    {
+                        string hcj = HCJ[RGVTaskdevice.HCJStorageaddress];
+                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
+
+                        if (Mucheywhaddres(Mu2.ChildPosiDeviceCode) && Mucheywhaddres(hcj))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu2 != Mu2.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && !IsAddressOccupied(Mu2.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }
+                    else if (parameter == 1021 || parameter == 1171)
+                    {
+                        string hcj = HCJ[parameter];
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
+
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode) && Mucheywhaddres(hcj))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 != Mu1.ZicheMotherinlaw && mu1 == Mu1.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }
+                    else
+                    {
+                        int taraddress = parameter;
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
+
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+
+                        }
+                    }
+                }
+            }
+            else if (RGVTaskdevice.Station_Area == 5) // 鍐呬晶
+            {
+                if (zhicheWZ == RGVTaskdevice.WaitmomentOne) // 绛夊緟鐐�1
+                {
+                    // 鍒ゆ柇澶栦晶灏忚溅鏄惁鍦� HCJ 涓�
+                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
+                    int waiziche = GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
+
+                    //鍒ゆ柇浼犺繘鏉ヨ澶囨槸鍚︽槸鍏ュ簱
+                    if (InDevices.Contains(Commonstacker.DeviceCode))
+                    {
+                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress))
+                        {
+                            return false;
+                        }
+                    }
+                    else
+                    {
+                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1171) && waiziche != zichestation.HCJStorageaddress))
+                        {
+                            return false;
+                        }
+                    }
+
+                    if (parameter == Mu1.ZicheMotherinlaw) //姣�1
+                    {
+                        int taraddress = parameter;
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 == Mu1.ZicheMotherinlaw && mu1 != Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }
+                    else if (parameter == Mu2.ZicheMotherinlaw) // 姣�2
+                    {
+                        int taraddress = parameter;
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
+
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }else if (parameter == RGVTaskdevice.HCJStorageaddress)
+                    {
+                        string hcj = HCJ[RGVTaskdevice.HCJStorageaddress];
+                        if (Mucheywhaddres(hcj))
+                        {
+                            return true;
+                        }
+                    }
+                    else
+                    {
+                        int taraddress = parameter;
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
+
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+
+                        }
+                    }
+                }
+                else if (zhicheWZ == RGVTaskdevice.WaitmomentTwo) // 绛夊緟鐐�2
+                {
+                    // 鍒ゆ柇澶栦晶灏忚溅鏄惁鍦� HCJ 涓�
+                    var zichestation = _agvStationService.OutGetZicheDeepHCJ(RGVTaskdevice.HCJStorageaddress);
+                    int waiziche = GetEquipmentlocation(zichestation.ChildPosiDeviceCode);
+
+                    //鍒ゆ柇浼犺繘鏉ヨ澶囨槸鍚︽槸鍏ュ簱
+                    if (InDevices.Contains(Commonstacker.DeviceCode))
+                    {
+                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1021) && waiziche != zichestation.HCJStorageaddress))
+                        {
+                            return false;
+                        }
+                    }
+                    else
+                    {
+                        if (!((waiziche == zichestation.WaitmomentOne || waiziche == zichestation.WaitmomentTwo || waiziche == zichestation.MotherCardeputy || waiziche == zichestation.MotherCarDeviceCode || waiziche == 1171) && waiziche != zichestation.HCJStorageaddress))
+                        {
+                            return false;
+                        }
+                    }
+
+                    if (parameter == Mu1.ZicheMotherinlaw)
+                    {
+                        int taraddress = parameter;
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 == Mu1.ZicheMotherinlaw && mu1 != Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }
+                    else if (parameter == Mu2.ZicheMotherinlaw)
+                    {
+                        int taraddress = parameter;
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
+
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }
+                    else if (parameter == RGVTaskdevice.HCJStorageaddress)
+                    {
+                        string hcj = HCJ[RGVTaskdevice.HCJStorageaddress];
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode)&&Mucheywhaddres(hcj))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 != Mu1.ZicheMotherinlaw && mu1 == Mu1.Motherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+                        }
+                    }
+                    else
+                    {
+                        int taraddress = parameter;
+                        int mu1 = GetEquipmentlocation(Mu1.ChildPosiDeviceCode);
+                        int mu2 = GetEquipmentlocation(Mu2.ChildPosiDeviceCode);
+
+                        if (Mucheywhaddres(Mu1.ChildPosiDeviceCode) && Mucheywhaddres(Mu2.ChildPosiDeviceCode))//鍒ゆ柇鏄惁鏈夎揣
+                        {
+                            if (mu1 == Mu1.Motherinlaw && mu1 != Mu1.ZicheMotherinlaw && mu2 == Mu2.Motherinlaw && mu2 != Mu2.ZicheMotherinlaw && !IsAddressOccupied(Mu1.ZicheMotherinlaw))
+                            {
+                                return true;
+                            }
+                            else
+                            {
+                                return false;
+                            }
+                        }
+                        else
+                        {
+                            return false;
+
+                        }
+                    }
+                }
+            }
+
+            // 榛樿锛氭湭琚嫤鎴笖鐩爣鏈崰鐢� -> 鏀捐
+            return true;
+
+        }
+
+        /// <summary>
+        /// 浼犲叆璁惧锛岃繑鍥炲綋鍓嶈澶囦俊鎭�
+        /// </summary>
+        /// <param name="ChildPosiDeviceCode">璁惧</param>
+        /// <returns></returns>
+        public static int GetEquipmentInformation(string ChildPosiDeviceCode)
+        {
+            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
+            SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
+            if (speStackerCrane == null)
+            {
+                Console.WriteLine($"璇诲彇鍒拌澶囦负绌�,璁惧缂栧彿锛歿ChildPosiDeviceCode},003");
+                return 0;
+            }
+            DeviceProDTO? deviceProDTOGZMS = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RgvCraneAutoStatus" && x.DeviceProParamType == "RgvCraneAutoStatus");
+            int GZMS = RGVGetLine(speStackerCrane, deviceProDTOGZMS.DeviceProAddress);
+
+            DeviceProDTO? deviceProDTORWZT = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RGV_Rgvtaskstutas" && x.DeviceProParamType == "RGV_Rgvtaskstutas");
+            int RWZT = RGVGetLine(speStackerCrane, deviceProDTORWZT.DeviceProAddress);
+
+            DeviceProDTO? deviceProDTOBJGC = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RGVStepprocess" && x.DeviceProParamType == "RGVStepprocess");
+            int BJGC = RGVGetLine(speStackerCrane, deviceProDTOBJGC.DeviceProAddress);
+
+            DeviceProDTO? deviceProDTOWZ = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RGVCurrentlocation" && x.DeviceProParamType == "RGVCurrentlocation");
+            int WZ = RGVGetLine(speStackerCrane, deviceProDTOWZ.DeviceProAddress);
+
+
+            if (GZMS == 1 && RWZT == 0 && BJGC == 0)
+            {
+                return WZ;
+            }
+            else
+            {
+                return 0;
+            }
+
+        }
+
+        public static bool Mucheywhaddres(string DeviceCode)
+        {
+            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
+            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
+
+            DeviceProDTO? deviceProDTO = Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeviceCode && x.DeviceProParamName == "RgvEquipmentStatus" && x.DeviceProParamType == "RgvEquipmentStatus");
+            int MCGStatus = RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
+            if (MCGStatus == (int)RgvEquipmentStatus.NoCargo)
+            {
+                return true;
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// RGV璁惧鐘舵��
+        /// </summary>
+        public enum RgvEquipmentStatus
+        {
+            /// <summary>
+            /// 鏃犺揣
+            /// </summary>
+            [Description("鏃犺揣")]
+            NoCargo,
+            /// <summary>
+            /// 鏈夎揣
+            /// </summary>
+            [Description("鏈夎揣")]
+            HasCargo,
+            /// <summary>
+            /// 鏈煡
+            /// </summary>
+            [Description("鏈煡")]
+            Unkonw = 6
+
+        }
+
+        /// <summary>
+        /// 浼犲叆璁惧锛岃幏鍙栧綋鍓嶄綅缃綅缃�
+        /// </summary>
+        /// <param name="ChildPosiDeviceCode">璁惧</param>
+        /// <returns></returns>
+        public static int GetEquipmentlocation(string ChildPosiDeviceCode)
+        {
+            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
+            SpeStackerCrane speStackerCrane = (SpeStackerCrane)device;
+            if (speStackerCrane == null) return 0;
+            DeviceProDTO? deviceProDTO = speStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == ChildPosiDeviceCode && x.DeviceProParamName == "RGVCurrentlocation" && x.DeviceProParamType == "RGVCurrentlocation");
+            int MCGStatus = RGVGetLine(speStackerCrane, deviceProDTO.DeviceProAddress);
+            return MCGStatus;
+        }
+
+        public static int RGVGetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock)
+        {
+            return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
+        }
+
+        /// <summary>
+        /// 鑾峰彇鍒板瓙杞︿綅缃�
+        /// </summary>
+        /// <param name="commonstacker"></param>
+        /// <param name="deviceCode"></param>
+        /// <returns></returns>
+
+        private int GetzicheWZ(SpeStackerCrane commonstacker, string deviceCode)
+        {
+            DeviceProDTO? RGVCurrentlocation = RgvOperationService.GetRGVDeviceProDTO(commonstacker, commonstacker.DeviceCode, "RGVCurrentlocation", "RGVCurrentlocation");
+            return RgvOperationService.GetLine(commonstacker, RGVCurrentlocation.DeviceProAddress);
         }
 
 
@@ -769,6 +1519,170 @@
                 return webResponse.Error("璁惧鎿嶄綔澶辫触");
             }
 }
+
+        /// <summary>
+        /// 鏌ョ湅鎶ヨ
+        /// </summary>
+        public WebResponseContent LogAlarmToDatabase(string JobDeviceName)
+        {
+            // 璁惧鍒嗙被 - 鍚堝苟鐗堟湰
+            var deviceCategories = new Dictionary<string, List<string>>
+            {
+                ["MotherCar"] = new List<string> { "RGV112", "RGV110", "RGV114", "RGV115", "RGV103", "RGV105", "RGV108", "RGV109" },
+                ["TransferCar"] = new List<string> { "RGV116", "RGV111", "RGV104", "RGV107" },
+                ["ExternalRGV"] = new List<string> { "RGV118", "RGV101" }
+            };
+
+            WebResponseContent webResponse = new WebResponseContent();
+            string DeviceName = JobDeviceName;    //璁惧鍚嶇О
+            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
+            if (device == null) return webResponse.Error();
+            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
+            DeviceProDTO? RGV_Resetoperation = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Faultcode", "ReadDeviceCommand");
+            DeviceProDTO? RGVCurrentlocation = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGVCurrentlocation", "RGVCurrentlocation");
+            DeviceProDTO? RGV_Rgvtaskid = RgvOperationService.GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Rgvtaskid", "ReadDeviceCommand");
+
+
+            int baoj = RgvOperationService.GetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress);
+
+            if (baoj<=0)
+            {
+                return null;
+            }
+            int Currentlocation = RgvOperationService.GetLine(Commonstacker, RGVCurrentlocation.DeviceProAddress);
+            int Rgvtaskid = RgvOperationService.GetLine(Commonstacker, RGV_Rgvtaskid.DeviceProAddress);
+
+            string alarmMessage = "";
+            if (deviceCategories["MotherCar"].Contains(DeviceName))
+            {
+                // 姣嶈溅涓撶敤鎶ヨ澶勭悊閫昏緫
+                alarmMessage = HandleMotherCarAlarm(baoj);
+            }
+            else if (deviceCategories["TransferCar"].Contains(DeviceName))
+            {
+                // 瀛愯溅涓撶敤鎶ヨ澶勭悊閫昏緫
+                alarmMessage = HandleTransferCarAlarm(baoj);
+            }
+            else if (deviceCategories["ExternalRGV"].Contains(DeviceName))
+            {
+                // 澶栧彛RGV涓撶敤鎶ヨ澶勭悊閫昏緫
+                alarmMessage = HandleExternalRGVAlarm(baoj);
+            }
+            
+            // 鍐欏叆鏂囨湰鏃ュ織锛堟寜璁惧鍒嗙粍/鎸夋棩鍒囧垎锛�
+            var logContent = $"璁惧:{DeviceName} | 鎶ヨ鐮�:{baoj} | 鎶ヨ鎻忚堪:{alarmMessage} | 褰撳墠浣嶇疆:{Currentlocation} | 浠诲姟鍙�:{Rgvtaskid}";
+            // groupName: Alarm锛宭ogName: 璁惧鍚�
+            WriteLog.Write_Log("Alarm", DeviceName, logContent, new
+            {
+                DeviceCode = DeviceName,
+                AlarmCode = baoj,
+                AlarmContent = alarmMessage,
+                DeviceLocation = Currentlocation,
+                TaskNum = Rgvtaskid,
+                Time = DateTime.Now
+            });
+            return webResponse.OK();
+        }
+
+
+        // 鎶ヨ浠g爜鏄犲皠鏂规硶
+        private string HandleExternalRGVAlarm(int alarmCode)
+        {
+            var alarmMessages = new Dictionary<int, string>
+{
+    {0, "鏃犳姤璀�"},
+    {1, "RGV灏忚溅鎬ュ仠琚寜涓�"},
+    {2, "姝h浆闆疯揪鎶ヨ"},
+    {3, "鍙嶈浆闆疯揪鎶ヨ"},
+    {4, "鍓嶈繘闄愪綅鎶ヨ"},
+    {5, "鍚庨��闄愪綅鎶ヨ"},
+    {6, ""},
+    {7, "PLC妯″潡鏁呴殰"},
+    {8, "PLC鎵╁睍妯″潡鏁呴殰"},
+    {9, "绉伴噸妯″潡鏁呴殰"},
+    {10, "鎵爜瀹氫綅鏁呴殰"},
+    {11, "RGV闀挎椂闂寸┖杞晠闅�"},
+    {12, "鐩殑鍦颁笉绛変簬瀹為檯浣嶇疆鏁呴殰"},
+    {13, "涓庢�绘帶閫氳鏁呴殰"},
+    {14, "鍓嶉浄杈惧睆钄借鍛�"},
+    {15, "鍚庨浄杈惧睆钄借鍛�"},
+    {16, "琛岃蛋鍙橀鍣ㄦ晠闅�"},
+    {17, "浼哥缉鍙夊彉棰戝櫒鏁呴殰"},
+    {18, "娑插帇鍗曞厓杩囪浇淇濇姢鏁呴殰"},
+    {19, "娑插帇涓婂崌瓒呮椂鎶ヨ"},
+    {20, "娑插帇涓嬮檷瓒呮椂鎶ヨ"},
+    {21, "浼哥缉鍙変几鍑鸿秴鏃舵姤璀�"},
+    {22, "浼哥缉鍙夌缉鍥炶秴鏃舵姤璀�"},
+    {23, "澶栧舰妫�娴嬫姤璀�"},
+    {24, "绉伴噸瓒呴噸鎶ヨ"},
+    {25, "璐у弶浼稿嚭鏋侀檺闄愪綅鎶ヨ"},
+    {26, "璐у弶缂╁洖鏋侀檺闄愪綅鎶ヨ"},
+    {27, "鍙栬揣鏃惰嚜韬湁璐х墿鎶ヨ"},
+    {28, "鏀捐揣鏃惰嚜韬棤璐х墿鎶ヨ"},
+    {29, "璐у弶鏈洖鍒板垵濮嬩綅鎶ヨ"},
+    {30, "瑙﹀彂浠呯Щ鍔ㄥ懡浠ゆ椂璐у弶涓嶅湪鍒濆浣嶆姤璀�"},
+    {31, "璐у弶鍒拌揪鍒濆浣嶄絾涓綅浼犳劅鍣ㄦ湭妫�娴嬪埌鎶ヨ"},
+    {32, "琛岃蛋杞存病鍒颁綅绂佹璐у弶浼稿嚭"},
+    {33, "鍙栬揣寮傚父鎶ヨ"},
+    {34, "鏀捐揣寮傚父鎶ヨ"},
+    {35, "澶栧瀷妫�娴�-鍓嶈秴鍑烘姤璀�"},
+    {36, "澶栧瀷妫�娴�-鍚庤秴鍑烘姤璀�"},
+    {37, "澶栧瀷妫�娴�-宸﹁秴鍑烘姤璀�"},
+    {38, "澶栧瀷妫�娴�-鍙宠秴鍑烘姤璀�"},
+    {39, "澶栧瀷妫�娴�-涓婅秴鍑烘姤璀�"}
+};
+
+            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "鏈煡鎶ヨ浠g爜";
+        }
+
+
+        private string HandleTransferCarAlarm(int alarmCode)
+        {
+            var alarmMessages = new Dictionary<int, string>
+    {
+        {0, "鏃犳姤璀�"},
+        {1, "RGV灏忚溅鎬ュ仠琚寜涓�"},
+        {2, "鍓嶈繘闄愪綅鎶ヨ"},
+        {3, "鍚庨��闄愪綅鎶ヨ"},
+        {4, "PLC鎽稿潡鏁呴殰"},
+        {5, "PLC鎵╁睍妯″潡鏁呴殰"},
+        {6, "鎵爜瀹氫綅鏁呴殰"},
+        {7, "RGV闀挎椂闂寸┖杞晠闅�"},
+        {8, "鐩殑鍦颁笉绛変簬瀹為檯浣嶇疆鏁呴殰"},
+        {9, "涓庢�绘帶閫氳鏁呴殰"},
+        {10, "琛岃蛋鍙橀鍣ㄦ晠闅�"},
+        {11, "娑插帇鍗曞厓杩囪浇淇濇姢鏁呴殰"},
+        {12, "娑插帇涓婂崌瓒呮椂鎶ヨ"},
+        {13, "娑插帇涓嬮檷瓒呮椂鎶ヨ"},
+        {14, "鍙栬揣鏃惰嚜韬湁璐х墿鎶ヨ"},
+        {15, "鏀捐揣鏃惰嚜韬棤璐х墿鎶ヨ"},
+        {16, "鍙栬揣妫�娴嬩笉鍒拌揣鐗╂姤璀�"}
+    };
+
+            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "鏈煡鎶ヨ浠g爜";
+        }
+
+        private string HandleMotherCarAlarm(int alarmCode)
+        {
+            var alarmMessages = new Dictionary<int, string>
+    {
+        {0, "鏃犳姤璀�"},
+        {1, "RGV灏忚溅鎬ュ仠琚寜涓�"},
+        {2, "鍓嶈繘闄愪綅鎶ヨ"},
+        {3, "鍚庨��闄愪綅鎶ヨ"},
+        {4, "PLC鎽稿潡鏁呴殰"},
+        {5, "PLC鎵╁睍妯″潡鏁呴殰"},
+        {6, "RGV闀挎椂闂寸┖杞晠闅�"},
+        {7, "鐩殑鍦颁笉绛変簬瀹為檯浣嶇疆鏁呴殰"},
+        {8, "涓庢�绘帶閫氳鏁呴殰"},
+        {9, "琛岃蛋鍙橀鍣ㄦ晠闅�"},
+        {10, "鍙栬揣鏃惰嚜韬湁璐х墿鎶ヨ"},
+        {11, "鏀捐揣鏃惰嚜韬棤璐х墿鎶ヨ"},
+        {12, "鍋滄鏃朵綅缃繃鍐叉姤璀�"}
+    };
+
+            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "鏈煡鎶ヨ浠g爜";
+        }
     }
 }
     
\ No newline at end of file

--
Gitblit v1.9.3