From a2f06e43a6f4ed3c613aefbb8bc0ccf3dd30ff8f Mon Sep 17 00:00:00 2001
From: xiazhengtongxue <133085197+xiazhengtongxue@users.noreply.github.com>
Date: 星期五, 26 十二月 2025 13:34:20 +0800
Subject: [PATCH] 1

---
 项目代码/WCSServices/WIDESEAWCS_Server/Controllers/PTLAPIController.cs |  155 +++++++++++++++++++++++++--------------------------
 1 files changed, 76 insertions(+), 79 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Controllers/PTLAPIController.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Controllers/PTLAPIController.cs"
index 29fa81e..bd9cf8e 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Controllers/PTLAPIController.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Controllers/PTLAPIController.cs"
@@ -1,13 +1,11 @@
 锘縰sing Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using RYB_PTL_API;
-using System.Security.Policy;
+using System.Collections.Generic;
+using System.Linq;
 using WIDESEAWCS_DTO;
 using WIDESEAWCS_DTO.TaskInfo;
-using WIDESEAWCS_IBasicInfoRepository;
-using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
-using WIDESEAWCS_QuartzJob.Repository;
 
 namespace WIDESEAWCS_Server.Controllers
 {
@@ -16,70 +14,75 @@
     public class PTLAPIController : ControllerBase
     {
         private readonly ITaskService _taskService;
-        //private bool _eventSubscribed = false;
+        private bool _eventSubscribed = false;
 
         public PTLAPIController(ITaskService taskService)
         {
             _taskService = taskService;
-            //SubscribeEvent();
+            SubscribeEvent();
         }
 
         /// <summary>
         /// 璁㈤槄PTL浜嬩欢
         /// </summary>
-        //private void SubscribeEvent()
-        //{
-        //    if (!_eventSubscribed)
-        //    {
-        //        RYB_PTL.UserResultAvailable += RYB_PTL_UserResultAvailable;
-        //        _eventSubscribed = true;
-        //    }
-        //}
+        private void SubscribeEvent()
+        {
+            if (!_eventSubscribed)
+            {
+                RYB_PTL.UserResultAvailable += new RYB_PTL.UserResultAvailableEventHandler(RYB_PTL_UserResultAvailable);
+                _eventSubscribed = true;
+            }
+        }
+        
+        /// <summary>
+        /// 鍙栨秷璁㈤槄PTL浜嬩欢
+        /// </summary>
+        private void UnsubscribeEvent()
+        {
+            if (_eventSubscribed)
+            {
+                RYB_PTL.UserResultAvailable -= new RYB_PTL.UserResultAvailableEventHandler(RYB_PTL_UserResultAvailable);
+                _eventSubscribed = false;
+            }
+        }
+        /// <summary>
+        /// PTL鍥炶皟浜嬩欢澶勭悊锛堝彧澶勭悊鎵嬫媿浜嬩欢锛�
+        /// </summary>
+        private void RYB_PTL_UserResultAvailable(RYB_PTL.RtnValueStruct rs)
+        {
+            try
+            {
+                if (rs.KeyCode == null)
+                {
+                    return;
+                }
+                // 鏋勫缓鍥炶皟鏁版嵁
+                var pTLCallBackDTO = new PTLCallBackDTO
+                {
+                    sIp = rs.Ip,
+                    sTagID = rs.Tagid,
+                    sValue = rs.Number,
+                    sKeyCode = rs.KeyCode,
+                    sLocator = rs.Locator
+                };
 
-        ///// <summary>
-        ///// 鍙栨秷璁㈤槄PTL浜嬩欢
-        ///// </summary>
-        //private void UnsubscribeEvent()
-        //{
-        //    if (_eventSubscribed)
-        //    {
-        //        RYB_PTL.UserResultAvailable -= RYB_PTL_UserResultAvailable;
-        //        _eventSubscribed = false;
-        //    }
-        //}
+                // 鏍规嵁涓氬姟闇�瑕佹瀯寤轰换鍔′俊鎭�
+                var taskBackLight = new TaskBackLight()
+                {
+                    TagNo = "B1", 
+                    TagCode = pTLCallBackDTO.sLocator,
+                };
 
-        ///// <summary>
-        ///// PTL鍥炶皟浜嬩欢澶勭悊
-        ///// </summary>
-        //private void RYB_PTL_UserResultAvailable(RYB_PTL.RtnValueStruct rs)
-        //{
-        //    try
-        //    {
-        //        var content = new EPLightContent();
-        //        var pTLCallBackDTO = new PTLCallBackDTO
-        //        {
-        //            sIp = rs.Ip,
-        //            sTagID = rs.Tagid,
-        //            sValue = rs.Number,
-        //            sKeyCode = rs.KeyCode,
-        //            sLocator = rs.Locator
-        //        };
-
-        //        var taskBackLight = new TaskBackLight()
-        //        {
-        //            TagNo = "B1",
-        //            TagCode = pTLCallBackDTO.sLocator,
-        //        };
-        //        // 璋冪敤鏈嶅姟澶勭悊
-        //        _taskService.WMSLightBack(new List<TaskBackLight> { taskBackLight });
-        //    }
-        //    catch (Exception ex)
-        //    {
-        //        // 璁板綍鏃ュ織鎴栧鐞嗗紓甯�
-        //        Console.WriteLine($"澶勭悊PTL鍥炶皟鏃跺嚭閿�: {ex.Message}");
-        //    }
-        //}
-
+                // 璋冪敤鏈嶅姟澶勭悊鎵嬫媿浜嬩欢
+                _taskService.WMSLightBack(new List<TaskBackLight> { taskBackLight });
+                UnsubscribeEvent();
+            }
+            catch (Exception ex)
+            {
+                // 璁板綍鏃ュ織鎴栧鐞嗗紓甯�
+                Console.WriteLine($"澶勭悊PTL鎵嬫媿鍥炶皟鏃跺嚭閿�: {ex.Message}");
+            }
+        }
         /// <summary>
         /// 鎾澧欎笅鍙�(涓�鏈�)
         /// </summary>
@@ -95,8 +98,6 @@
                     request.iNum,
                     request.iMode,
                     request.iColorIndex);
-
-
             }
             catch (Exception ex)
             {
@@ -104,8 +105,6 @@
             }
             return content;
         }
-
-
         /// <summary>
         /// 鍥炶皟涓婁紶
         /// </summary>
@@ -134,6 +133,7 @@
             }
             return content;
         }
+
         /// <summary>
         /// 鎾澧欏垵濮嬪寲(涓�鏈�)
         /// </summary>
@@ -144,16 +144,11 @@
             EPLightContent content = new EPLightContent();
             try
             {
-                bool isConnected;
+                //RYB_PTL.UserResultAvailable += new RYB_PTL.UserResultAvailableEventHandler(RYB_PTL_UserResultAvailable);
+                
 
-                if (request.iTimeOut.HasValue)
-                {
-                    isConnected = RYB_PTL.RYB_PTL_Connect(request.sIp, request.iPort, request.iTimeOut.Value);
-                }
-                else
-                {
-                    isConnected = RYB_PTL.RYB_PTL_Connect(request.sIp, request.iPort);
-                }
+                bool isCfg = RYB_PTL.RYB_PTL_InitialConfiguration(new string[,] { { "11.2.30.252", "0001-0016" },{ "11.2.30.252", "1-16" } });
+                bool isConnected = RYB_PTL.RYB_PTL_Connect(request.sIp, request.iPort);
             }
             catch (Exception ex)
             {
@@ -161,6 +156,7 @@
             }
             return content;
         }
+
         /// <summary>
         /// 鎾澧欑粨鏉熶綔涓�(涓�鏈�)
         /// </summary>
@@ -179,13 +175,14 @@
             }
             return content;
         }
-        ///// <summary>
-        ///// 璧勬簮閲婃斁
-        ///// </summary>
-        //public void Dispose()
-        //{
-        //    UnsubscribeEvent();
-        //}
-    }
 
-}
+        /// <summary>
+        /// 璧勬簮閲婃斁锛堟爣璁颁负涓嶆毚闇茬粰Swagger锛�
+        /// </summary>
+        [ApiExplorerSettings(IgnoreApi = true)]
+        public void Dispose()
+        {
+            UnsubscribeEvent();
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3