From 67348f250a1b7970059698002949a5e0a5f3c52f Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期四, 14 八月 2025 08:51:04 +0800
Subject: [PATCH] 上传最新代码

---
 项目代码/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs |  115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 114 insertions(+), 1 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs"
index 8b60d42..57151fe 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs"
@@ -1,18 +1,23 @@
 锘縰sing Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
+using System.Text;
 using WIDESEA_DTO.Agv;
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Enums;
 using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_Core.LogHelper;
+using WIDESEAWCS_DTO.Agv;
 using WIDESEAWCS_IBasicInfoRepository;
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.DTO;
 using WIDESEAWCS_Tasks;
-using static Dm.net.buffer.ByteArrayBuffer;
+using WIDESEAWCS_Tasks.ConveyorLineJob;
+using WIDESEAWCS_Tasks.DBNames;
 
 namespace WIDESEAWCS_Server.Controllers
 {
@@ -77,6 +82,114 @@
             //return _taskService.AgvSecureApply(secureApplyModel);
         }
         /// <summary>
+        /// 鎻愬崌鏈虹敵璇� AGV-WCS
+        /// </summary>
+        /// <param name="secureApplyModel"></param>
+        /// <returns></returns>
+        [HttpPost, HttpGet, Route("AgvHoisterApply"), AllowAnonymous]
+        public AgvResponse AgvHoisterApply([FromBody] AgvHoisterApplyDTO agvHoisterApplyDTO)
+        {
+            AgvResponse agvResponse = new AgvResponse();
+            try
+            {
+                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == agvHoisterApplyDTO.HoisterCode);
+                if (device == null)
+                {
+                    return agvResponse.Error($"鏈壘鍒板搴旇澶噞agvHoisterApplyDTO.HoisterCode}");
+                }
+                OtherDevice otherDevice = (OtherDevice)device;
+                //鑾峰彇璁惧鍗忚
+                DeviceProDTO? deviceProRead = otherDevice.DeviceProDTOs.Where(x => x.DeviceChildCode == device.DeviceCode && x.DeviceProParamType == nameof(R_HoisterDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+                DeviceProDTO? deviceProWrite = otherDevice.DeviceProDTOs.Where(x => x.DeviceChildCode == device.DeviceCode && x.DeviceProParamType == nameof(W_HoisterDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+                if (deviceProRead == null || deviceProWrite == null)
+                {
+                    return agvResponse.Error($"鏈壘鍒拌澶噞device.DeviceCode}鍗忚");
+                }
+                //鑾峰彇璇诲彇鍜屽啓鍏�
+                R_HoisterInfo r_HoisterInfo = otherDevice.Communicator.ReadCustomer<R_HoisterInfo>(deviceProRead.DeviceProAddress);
+                W_HoisterInfo w_HoisterInfo = otherDevice.Communicator.ReadCustomer<W_HoisterInfo>(deviceProWrite.DeviceProAddress);
+                if (r_HoisterInfo == null || w_HoisterInfo == null)
+                {
+                    return agvResponse.Error($"鏈鍙栧埌璁惧{device.DeviceCode}淇″彿");
+                }
+                if (r_HoisterInfo.R_HoisterSysStatus!=3)
+                {
+                    return agvResponse.Error($"璁惧鐘舵�佷笉涓鸿嚜鍔�");
+                }
+                QuartzLogger.WriteLogToFile("Info_" + device.DeviceCode, $"r_HoisterInfo:{r_HoisterInfo.Serialize()}{Environment.NewLine}w_HoisterInfo:{w_HoisterInfo.Serialize()}{Environment.NewLine}");
+                bool IsSuccess = false;
+                switch (agvHoisterApplyDTO.Request)
+                {
+                    case "1":
+                        //鍒ゆ柇鎻愬崌鏈烘槸鍚﹀湪褰撳墠灞� 濡傛灉褰撳墠灞傦紝鍏抽棬鐘舵�侊紝鏃犺揣寰呭懡鐩存帴鍐欏叆寮�闂ㄤ俊鍙�
+                        if (r_HoisterInfo.R_HoisterCurrent == agvHoisterApplyDTO.CurrentLayer && r_HoisterInfo.R_HoisterLoadStatus == 2 && r_HoisterInfo.R_HoisterDoorStatus == 2)
+                        {
+                            otherDevice.SetValue(W_HoisterDB.W_HoisterDoorStatus, 1);
+                            IsSuccess = true;
+                        }
+                        else if (r_HoisterInfo.R_HoisterCurrent == agvHoisterApplyDTO.CurrentLayer && r_HoisterInfo.R_HoisterLoadStatus == 2 && r_HoisterInfo.R_HoisterDoorStatus == 1)
+                        {
+                            IsSuccess = true;
+                        }
+                        else if (r_HoisterInfo.R_HoisterCurrent != agvHoisterApplyDTO.CurrentLayer && r_HoisterInfo.R_HoisterLoadStatus == 2 && r_HoisterInfo.R_HoisterDoorStatus == 1)
+                        {
+                            otherDevice.SetValue(W_HoisterDB.W_HoisterDoorStatus, 2);
+                        }
+                        //鍒ゆ柇鎻愬崌鏈轰笉鍦ㄥ綋鍓嶅眰 濡傛灉涓嶅湪褰撳墠灞傦紝鍏抽棬鐘舵�侊紝鏃犺揣寰呭懡鐩存帴鍐欏叆绉诲姩寮�闂ㄤ俊鍙�(褰撳墠)
+                        else if (r_HoisterInfo.R_HoisterCurrent != agvHoisterApplyDTO.CurrentLayer && r_HoisterInfo.R_HoisterLoadStatus == 2 && r_HoisterInfo.R_HoisterDoorStatus == 2)
+                        {
+                            otherDevice.SetValue(W_HoisterDB.W_HoisterTarget, agvHoisterApplyDTO.CurrentLayer);
+                            otherDevice.SetValue(W_HoisterDB.W_HoisterTask, 99);
+                        }
+                        return IsSuccess ? agvResponse.OK($"璇锋眰{agvHoisterApplyDTO.Request}鎴愬姛,浠诲姟{agvHoisterApplyDTO.ReceiveTaskID}","1"): agvResponse.Error($"璇锋眰{agvHoisterApplyDTO.Request}澶辫触,浠诲姟{agvHoisterApplyDTO.ReceiveTaskID}");
+                    case "2":
+                        //鍒ゆ柇鎻愬崌鏈烘槸鍚﹀湪褰撳墠灞� 濡傛灉褰撳墠灞傦紝寮�闂ㄧ姸鎬侊紝鏃犺揣寰呭懡 鏀捐
+                        if (r_HoisterInfo.R_HoisterCurrent == agvHoisterApplyDTO.CurrentLayer && r_HoisterInfo.R_HoisterLoadStatus == 2 && r_HoisterInfo.R_HoisterDoorStatus == 1)
+                        {
+                            IsSuccess = true;
+                        }
+                        return IsSuccess ? agvResponse.OK($"璇锋眰{agvHoisterApplyDTO.Request}鎴愬姛,浠诲姟{agvHoisterApplyDTO.ReceiveTaskID}", "2") : agvResponse.Error($"璇锋眰{agvHoisterApplyDTO.Request}澶辫触,浠诲姟{agvHoisterApplyDTO.ReceiveTaskID}");
+                    case "3":
+                        //鍒ゆ柇鎻愬崌鏈烘槸鍚﹀湪褰撳墠灞� 濡傛灉褰撳墠灞傦紝寮�闂ㄧ姸鎬侊紝鏈夎揣寰呭懡鍐欏叆鍏抽棬淇″彿
+                        if (r_HoisterInfo.R_HoisterCurrent == agvHoisterApplyDTO.CurrentLayer && r_HoisterInfo.R_HoisterLoadStatus == 1 && r_HoisterInfo.R_HoisterDoorStatus == 1 && w_HoisterInfo.W_HoisterDoorStatus!=2)
+                        {
+                            otherDevice.SetValue(W_HoisterDB.W_HoisterDoorStatus, 2);
+                        }
+                        //鍒ゆ柇鎻愬崌鏈烘槸鍚﹀湪褰撳墠灞� 濡傛灉褰撳墠灞傦紝鍏抽棬鐘舵�侊紝鏈夎揣寰呭懡鍐欏叆绉诲姩寮�闂ㄤ俊鍙�(鐩殑)
+                        if (r_HoisterInfo.R_HoisterCurrent == agvHoisterApplyDTO.CurrentLayer && r_HoisterInfo.R_HoisterLoadStatus == 1 && r_HoisterInfo.R_HoisterDoorStatus == 2)
+                        {
+                            otherDevice.SetValue(W_HoisterDB.W_HoisterTarget, agvHoisterApplyDTO.TargetLayer);
+                            otherDevice.SetValue(W_HoisterDB.W_HoisterDoorStatus, 1);
+                            otherDevice.SetValue(W_HoisterDB.W_HoisterTask, 99);
+                            IsSuccess = true;
+                        }
+                        return IsSuccess ? agvResponse.OK($"璇锋眰{agvHoisterApplyDTO.Request}鎴愬姛,浠诲姟{agvHoisterApplyDTO.ReceiveTaskID}", "3") : agvResponse.Error($"璇锋眰{agvHoisterApplyDTO.Request}澶辫触,浠诲姟{agvHoisterApplyDTO.ReceiveTaskID}");
+                    case "4":
+                        //鍒ゆ柇鎻愬崌鏈烘槸鍚﹀湪鐩殑灞� 濡傛灉鐩殑灞傦紝寮�闂ㄧ姸鎬侊紝鏈夎揣寰呭懡 鏀捐
+                        if (r_HoisterInfo.R_HoisterCurrent == agvHoisterApplyDTO.TargetLayer && r_HoisterInfo.R_HoisterLoadStatus == 1 && r_HoisterInfo.R_HoisterDoorStatus == 1)
+                        {
+                            IsSuccess = true;
+                        }
+                        return IsSuccess ? agvResponse.OK($"璇锋眰{agvHoisterApplyDTO.Request}鎴愬姛,浠诲姟{agvHoisterApplyDTO.ReceiveTaskID}", "4") : agvResponse.Error($"璇锋眰{agvHoisterApplyDTO.Request}澶辫触,浠诲姟{agvHoisterApplyDTO.ReceiveTaskID}");
+                    case "5":
+                        //鍒ゆ柇鎻愬崌鏈烘槸鍚﹀湪鐩殑灞� 濡傛灉鐩殑灞傦紝寮�闂ㄧ姸鎬侊紝鏃犺揣寰呭懡鍐欏叆鍏抽棬淇″彿
+                        if (r_HoisterInfo.R_HoisterCurrent == agvHoisterApplyDTO.TargetLayer && r_HoisterInfo.R_HoisterLoadStatus == 2 && r_HoisterInfo.R_HoisterDoorStatus == 1)
+                        {
+                            otherDevice.SetValue(W_HoisterDB.W_HoisterDoorStatus, 2);
+                            IsSuccess = true;
+                        }
+                        return IsSuccess ? agvResponse.OK($"璇锋眰{agvHoisterApplyDTO.Request}鎴愬姛,浠诲姟{agvHoisterApplyDTO.ReceiveTaskID}", "5") : agvResponse.Error($"璇锋眰{agvHoisterApplyDTO.Request}澶辫触,浠诲姟{agvHoisterApplyDTO.ReceiveTaskID}");
+                    default:
+                        return agvResponse.Error($"鏈壘鍒板搴旇姹�,Request:{agvHoisterApplyDTO.Request}");
+                }
+            }
+            catch (Exception ex)
+            {
+                agvResponse.Error($"璇锋眰{agvHoisterApplyDTO.Request}澶辫触,閿欒{ex.Message},浠诲姟{agvHoisterApplyDTO.ReceiveTaskID}");
+            }
+            return agvResponse;
+        }
+        /// <summary>
         /// AGV浠诲姟鏇存柊/瀹屾垚
         /// </summary>
         /// <param name="agvUpdateModel"></param>

--
Gitblit v1.9.3