From 8c8a68df710d568f5f2b358c1e8c4b4799547d0b Mon Sep 17 00:00:00 2001
From: huanghongfeng <huanghongfeng@hnkhzn.com>
Date: 星期五, 31 十月 2025 15:24:34 +0800
Subject: [PATCH] 安全门,出入库

---
 代码管理/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RgvOperationService.cs |  293 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 289 insertions(+), 4 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RgvOperationService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RgvOperationService.cs"
index 0ac55b2..dddc198 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RgvOperationService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/RgvOperationService.cs"
@@ -48,15 +48,19 @@
 using WIDESEAWCS_QuartzJob.Service;
 using System.Net;
 using WIDESEAWCS_ISystemServices;
+using System.Security.Claims;
+using WIDESEAWCS_Common.TaskEnum;
 
 namespace WIDESEAWCS_TaskInfoService
 {
     public class RgvOperationService : ServiceBase<Dt_Task_hty, ITask_HtyRepository>, IRgvOperationService
     {
         private readonly IAgvStationService _gvStationService;
-        public RgvOperationService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService) : base(BaseDal)
+        private readonly ITaskRepository _taskRepository;
+        public RgvOperationService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService, ITaskRepository taskRepository) : base(BaseDal)
         {
             _gvStationService = agvStationService;
+            _taskRepository = taskRepository;
         }
 
 
@@ -88,6 +92,41 @@
             DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_taskcomplete", "RGV_taskcomplete");        //浠诲姟id
             RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, (short)1);
 
+            return webResponse.OK();
+        }
+
+        public WebResponseContent WriteRGVmokuai(SaveModel saveModel)
+        {
+            WebResponseContent webResponse = new WebResponseContent();
+            string DeviceName = saveModel.DelKeys[0].ToString();    //宸ヤ綔绫诲瀷
+            string DBType = saveModel.DelKeys[1].ToString();    //璁惧鍚嶇О
+            short WriteRGVvalue = short.Parse(saveModel.DelKeys[2].ToString());    //鍐欏叆鍊�
+            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
+            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
+            switch (DBType)
+            {
+                case "1":  // 宸ヤ綔妯″紡锛�0鎵嬪姩銆�1鑷姩锛�
+                           //鑾峰彇瀹炰緥
+                    DeviceProDTO? RGV_DWorkingmode = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");        //浠诲姟绫诲瀷
+                                                                                                                                                //绗竴姝ュ啓鍏ヤ换鍔�
+                    RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, WriteRGVvalue);
+                    break;
+                case "2":   //澶嶄綅鎿嶄綔锛�0涓嶅浣嶃��1澶嶄綅锛�
+                    DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand");        //浠诲姟绫诲瀷
+                                                                                                                                                    //绗竴姝ュ啓鍏ヤ换鍔�
+                    RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, WriteRGVvalue);
+                    break;
+                case "3":   //浠诲姟纭瀹屾垚锛�0涓嶇‘瀹氾紝1纭畾锛�
+                    DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_taskcomplete", "RGV_taskcomplete");        //浠诲姟绫诲瀷
+                                                                                                                                                   //绗竴姝ュ啓鍏ヤ换鍔�
+                    RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, WriteRGVvalue);
+                    break;
+                case "4":   //浠诲姟绫诲瀷(4娓呴櫎)
+                    DeviceProDTO? RGV_RGVtasktypet = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVtasktypet", "DeviceCommand");        //浠诲姟绫诲瀷
+                                                                                                                                                //绗竴姝ュ啓鍏ヤ换鍔�
+                    RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, WriteRGVvalue);
+                    break;
+            }
             return webResponse.OK();
         }
 
@@ -128,7 +167,7 @@
         }
 
         /// <summary>
-        /// 鍐欏叆澶嶄綅锛堝叆搴撶锛�
+        /// 涓�閿惎鍔ㄥ叆搴撳瓙姣嶈溅
         /// </summary>
         public WebResponseContent WriteInReset(SaveModel saveModel)
         {
@@ -137,7 +176,7 @@
             List<AGVStation> rgvdata = _gvStationService.GetInStroller();
             foreach (AGVStation rgvstation in rgvdata)
             {
-                string DeviceName = saveModel.DelKeys[0].ToString();    //璁惧鍚嶇О
+                string DeviceName = rgvstation.ChildPosiDeviceCode;    //璁惧鍚嶇О
                 IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
                 if (device == null) continue;
                 SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
@@ -165,6 +204,70 @@
 
                 //鑾峰彇闇�瑕佸浣嶇殑璁惧
                 DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand");        //澶嶄綅鎶ヨ淇℃伅
+                RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0);
+            }
+            return webResponse.OK();
+        }
+
+        /// <summary>
+        /// 涓�閿殏鍋�
+        /// </summary>
+        /// <param name="saveModel"></param>
+        /// <returns></returns>
+        public WebResponseContent WriteOutbuttonpause(SaveModel saveModel)
+        {
+            WebResponseContent webResponse = new WebResponseContent();
+            List<AGVStation> rgvdata = _gvStationService.GetOutStroller();
+            foreach (AGVStation rgvstation in rgvdata)
+            {
+                string DeviceName = rgvstation.ChildPosiDeviceCode;    //璁惧鍚嶇О
+                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
+                if (device == null) continue;
+                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
+
+                //鑾峰彇闇�瑕佸浣嶇殑璁惧
+                DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");        
+                RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0);
+            }
+            return webResponse.OK();
+        }
+
+        public WebResponseContent InWriteOutbuttonpause(SaveModel saveModel)
+        {
+            WebResponseContent webResponse = new WebResponseContent();
+            List<AGVStation> rgvdata = _gvStationService.InGetOutStroller();
+            foreach (AGVStation rgvstation in rgvdata)
+            {
+                string DeviceName = rgvstation.ChildPosiDeviceCode;    //璁惧鍚嶇О
+                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
+                if (device == null) continue;
+                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
+
+                //鑾峰彇闇�瑕佸浣嶇殑璁惧
+                DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");
+                RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0);
+            }
+            return webResponse.OK();
+        }
+
+        /// <summary>
+        /// 涓�閿惎鍔�
+        /// </summary>
+        /// <param name="saveModel"></param>
+        /// <returns></returns>
+        public WebResponseContent WriteOuttouchstart(SaveModel saveModel)
+        {
+            WebResponseContent webResponse = new WebResponseContent();
+            List<AGVStation> rgvdata = _gvStationService.GetOutStroller();
+            foreach (AGVStation rgvstation in rgvdata)
+            {
+                string DeviceName = rgvstation.ChildPosiDeviceCode;    //璁惧鍚嶇О
+                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
+                if (device == null) continue;
+                SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
+
+                //鑾峰彇闇�瑕佸浣嶇殑璁惧
+                DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");        
                 RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)1);
             }
             return webResponse.OK();
@@ -189,7 +292,7 @@
         /// <param name="conveyorLine"></param>
         /// <param name="DeviceProDataBlock"></param>
         /// <returns></returns>
-        public static int GetLine(CommonConveyorLine Commonstacker, string DeviceProDataBlock)
+        public static int GetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock)
         {
             return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
         }
@@ -205,7 +308,189 @@
             return Commonstacker.Communicator.Write<short>(DeviceProDataBlock, rgvvalues);
         }
 
+        /// <summary>
+        /// 姝e父鍏ュ簱
+        /// </summary>
+        public WebResponseContent WriteInNormal(SaveModel saveModel)
+        {
+            WebResponseContent content = new WebResponseContent();
+            Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.TaskState == (int)TaskInStatusEnum.InAbnormalFinish);
+            if (dt_Task == null)
+            {
+               return WebResponseContent.Instance.Error("娌℃湁寮傚父鍏ュ簱浠诲姟");
+            }
+            dt_Task.TaskState = (int)TaskInStatusEnum.RGV_InPickupFinish;
+            dt_Task.RGVTaskType = (int)RGVTaskTypeEnum.Placing;
+            dt_Task.NextAddress = "1021";
+            _taskRepository.UpdateData(dt_Task);
+            return content;
+        }
+        /// <summary>
+        /// 鍏ュ簱寮傚父鎺掑嚭
+        /// </summary>
+        public WebResponseContent WriteInAbnormal(SaveModel saveModel)
+        {
+            WebResponseContent content = new WebResponseContent();
+            Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.TaskState == (int)TaskInStatusEnum.InAbnormalFinish);
+            if (dt_Task == null)
+            {
+                return WebResponseContent.Instance.Error("娌℃湁寮傚父鍏ュ簱浠诲姟");
+            }
+            dt_Task.TaskState = (int)TaskInStatusEnum.InexceptionalSelection;
+            dt_Task.RGVTaskType = (int)RGVTaskTypeEnum.Placing;
+            _taskRepository.UpdateData(dt_Task);
+            return content;
+        }
 
 
+
+        public static List<string> OutStationareaList = new List<string>() { "RGV111", "RGV116", "RGV110", "RGV112", "RGV114", "RGV115", "RGV118" };
+        public static List<string> InStationareaList = new List<string>() { "RGV111", "RGV116", "RGV110", "RGV112", "RGV114", "RGV115", "RGV118" };
+        /// <summary>
+        /// 鏌ョ湅鎶ヨ
+        /// </summary>
+        public bool AQMReadAlarminform(int tasktype)
+        {
+            var deviceList = tasktype == 1 ? InStationareaList : OutStationareaList;
+
+            foreach (string deviceName in deviceList)
+            {
+                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceName);
+                if (device == null) return false;
+
+                SpeStackerCrane stacker = (SpeStackerCrane)device;
+                DeviceProDTO? faultInfo = GetRGVDeviceProDTO(stacker, deviceName, "RGV_Faultcode", "ReadDeviceCommand");
+                int alarmCode = GetLine(stacker, faultInfo.DeviceProAddress);
+
+                if (alarmCode != 0)
+                {
+                    return true;
+                }
+            }
+
+            return false;
+        }
+
+
+        /// <summary>
+        /// 鏌ョ湅鎶ヨ
+        /// </summary>
+        public WebResponseContent ReadAlarminformation(SaveModel saveModel)
+        {
+            WebResponseContent webResponse = new WebResponseContent();
+            string DeviceName = saveModel.DelKeys[0].ToString();    //璁惧鍚嶇О
+            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
+            if (device == null) return webResponse.Error();
+            SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
+            DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Faultcode", "ReadDeviceCommand");
+            int baoj = GetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress);
+            string alarmMessage = "";
+            if (DeviceName == "RGV118")
+            {
+                 alarmMessage = GetAlarmMessage(baoj);
+            }
+            else if (DeviceName == "RGV111" || DeviceName == "RGV116")
+            {
+                 alarmMessage = GetAlarmMessage2(baoj);
+            }
+            else if (DeviceName == "RGV110" || DeviceName == "RGV112" || DeviceName == "RGV114" || DeviceName == "RGV115")
+            {
+                 alarmMessage = GetAlarmMessage3(baoj);
+            }
+
+
+            return webResponse.OK(data: alarmMessage);
+        }
+
+        // 鎶ヨ浠g爜鏄犲皠鏂规硶
+        private string GetAlarmMessage(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, "璐у弶鍒拌揪鍒濆浣嶄絾涓綅浼犳劅鍣ㄦ湭妫�娴嬪埌鎶ヨ"}
+            };
+
+            return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "鏈煡鎶ヨ浠g爜";
+        }
+
+
+        private string GetAlarmMessage2(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 GetAlarmMessage3(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爜";
+        }
     }
 }

--
Gitblit v1.9.3