From f5e302847933cb5c09bca3bc5731556ae52d3a4a Mon Sep 17 00:00:00 2001
From: xiazhengtongxue <133085197+xiazhengtongxue@users.noreply.github.com>
Date: 星期三, 24 十二月 2025 09:59:41 +0800
Subject: [PATCH] 播种墙(一期)

---
 项目代码/WCSServices/WIDESEAWCS_DTO/PTLCallBackDTO.cs                             |   40 +++++
 项目代码/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs                    |  121 ++++++++++++++
 项目代码/WCSServices/WIDESEAWCS_Server/WIDESEAWCS_Server.csproj                   |    6 
 项目代码/WCSServices/WIDESEAWCS_DTO/ConnectDTO.cs                                 |   24 +++
 项目代码/WCSServices/WIDESEAWCS_Server/Controllers/PTLAPIController.cs            |  191 +++++++++++++++++++++++
 项目代码/WCSServices/WIDESEAWCS_Server/libs/RYB_PTL_API.dll                       |    0 
 项目代码/WCSServices/WIDESEAWCS_TaskInfoService/WIDESEAWCS_TaskInfoService.csproj |    6 
 项目代码/WCSServices/WIDESEAWCS_Common/APIEnum/APIEnum.cs                         |   11 +
 项目代码/WCSServices/WIDESEAWCS_DTO/CloseDigit5DTO.cs                             |   32 ++++
 9 files changed, 429 insertions(+), 2 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Common/APIEnum/APIEnum.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Common/APIEnum/APIEnum.cs"
index d9aef74..cb9060a 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Common/APIEnum/APIEnum.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Common/APIEnum/APIEnum.cs"
@@ -59,5 +59,16 @@
         /// </summary>
         [Description("浜屾湡鎾澧欎笅鍙�")]
         PickOrderInfoRequest,
+        connect,
+        /// <summary>
+        /// 涓�鏈熸挱绉嶅缁撴潫浣滀笟
+        /// </summary>
+        [Description("涓�鏈熸挱绉嶅缁撴潫浣滀笟")]
+        disconnect,
+        /// <summary>
+        /// 涓�鏈熸挱绉嶅涓嬪彂
+        /// </summary>
+        [Description("涓�鏈熸挱绉嶅涓嬪彂")]
+        Phase1PickOrderInfoRequest,
     }
 }
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_DTO/CloseDigit5DTO.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_DTO/CloseDigit5DTO.cs"
new file mode 100644
index 0000000..d552098
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_DTO/CloseDigit5DTO.cs"
@@ -0,0 +1,32 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WIDESEAWCS_DTO
+{
+    public class CloseDigit5DTO
+    {
+        /// <summary>
+        /// 鎺у埗鍣↖P鍦板潃
+        /// </summary>
+        public string sIP { get; set; }
+        /// <summary>
+        /// 鎾澧欐爣绛綢D
+        /// </summary>
+        public string sTagID { get; set; }
+        /// <summary>
+        /// 鏁伴噺
+        /// </summary>
+        public int iNum { get; set; }
+        /// <summary>
+        /// 浜紝1 浠h〃闈欐�佹樉绀猴紝2~7 浠h〃鏍囩闂儊鏄剧ず锛屼紶鍏ュ�艰秺澶э紝闂儊瓒婂揩
+        /// </summary>
+        public int iMode { get; set; }
+        /// <summary>
+        ///  1锛氱孩鑹诧紝2锛氱豢鑹诧紝3锛氳摑鑹诧紝4锛氶粍鑹诧紝5锛氱矇锛�6锛氶潚锛�7锛氱櫧
+        /// </summary>
+        public int iColorIndex { get; set; }
+    }
+}
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_DTO/ConnectDTO.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_DTO/ConnectDTO.cs"
new file mode 100644
index 0000000..2fd434e
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_DTO/ConnectDTO.cs"
@@ -0,0 +1,24 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WIDESEAWCS_DTO
+{
+    public class ConnectDTO
+    {
+        /// <summary>
+        /// 鎺у埗鍣↖P鍦板潃
+        /// </summary>
+        public string sIp { get; set; }
+        /// <summary>
+        /// 绔彛鍙烽粯璁ゅ��6020
+        /// </summary>
+        public int iPort { get; set; } = 6020;
+        /// <summary>
+        /// 鍙�夌殑瓒呮椂鍙傛暟
+        /// </summary>
+        public int? iTimeOut { get; set; }
+    }
+}
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_DTO/PTLCallBackDTO.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_DTO/PTLCallBackDTO.cs"
new file mode 100644
index 0000000..c68b4eb
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_DTO/PTLCallBackDTO.cs"
@@ -0,0 +1,40 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WIDESEAWCS_DTO
+{
+    public class PTLCallBackDTO
+    {
+        /// <summary>
+        /// 鎺у埗鍣↖P鍦板潃
+        /// </summary>
+        public string sIp { get; set; }
+
+        /// <summary>
+        /// 鏍囩鐨処D鍊�
+        /// </summary>
+        public string sTagID { get; set; }
+
+        /// <summary>
+        /// 鏄剧ず鐨勬暟閲忓�硷紙鎷嶇伃鏃朵紶鍏ョ殑鏁伴噺锛�
+        /// </summary>
+        public string sValue { get; set; }
+
+        /// <summary>
+        /// 妯″紡+棰滆壊浠g爜锛堜緥濡� "15" 琛ㄧず妯″紡1棰滆壊5锛�
+        /// 鐗规畩鍊艰鏄庯細
+        /// 90 - 鏍囩鑷鎴愬姛
+        /// 85 - 鎺у埗鍣ㄦ帀绾�
+        /// 87 - 鎺у埗鍣ㄩ噸鏂拌繛鎺ユ垚鍔�
+        /// </summary>
+        public string sKeyCode { get; set; }
+
+        /// <summary>
+        /// 璐т綅浠g爜锛堝彲閫夛級
+        /// </summary>
+        public string sLocator { get; set; }
+    }
+}
\ No newline at end of file
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"
new file mode 100644
index 0000000..29fa81e
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Controllers/PTLAPIController.cs"
@@ -0,0 +1,191 @@
+锘縰sing Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using RYB_PTL_API;
+using System.Security.Policy;
+using WIDESEAWCS_DTO;
+using WIDESEAWCS_DTO.TaskInfo;
+using WIDESEAWCS_IBasicInfoRepository;
+using WIDESEAWCS_ITaskInfoRepository;
+using WIDESEAWCS_ITaskInfoService;
+using WIDESEAWCS_QuartzJob.Repository;
+
+namespace WIDESEAWCS_Server.Controllers
+{
+    [Route("PTL")]
+    [ApiController]
+    public class PTLAPIController : ControllerBase
+    {
+        private readonly ITaskService _taskService;
+        //private bool _eventSubscribed = false;
+
+        public PTLAPIController(ITaskService taskService)
+        {
+            _taskService = taskService;
+            //SubscribeEvent();
+        }
+
+        /// <summary>
+        /// 璁㈤槄PTL浜嬩欢
+        /// </summary>
+        //private void SubscribeEvent()
+        //{
+        //    if (!_eventSubscribed)
+        //    {
+        //        RYB_PTL.UserResultAvailable += RYB_PTL_UserResultAvailable;
+        //        _eventSubscribed = true;
+        //    }
+        //}
+
+        ///// <summary>
+        ///// 鍙栨秷璁㈤槄PTL浜嬩欢
+        ///// </summary>
+        //private void UnsubscribeEvent()
+        //{
+        //    if (_eventSubscribed)
+        //    {
+        //        RYB_PTL.UserResultAvailable -= RYB_PTL_UserResultAvailable;
+        //        _eventSubscribed = false;
+        //    }
+        //}
+
+        ///// <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}");
+        //    }
+        //}
+
+        /// <summary>
+        /// 鎾澧欎笅鍙�(涓�鏈�)
+        /// </summary>
+        [HttpPost, Route("RYB_PTL_CloseDigit5"), AllowAnonymous]
+        public EPLightContent RYB_PTL_CloseDigit5([FromBody] CloseDigit5DTO request)
+        {
+            var content = new EPLightContent();
+            try
+            {
+                bool isConnected = RYB_PTL.RYB_PTL_DspDigit5(
+                    request.sIP,
+                    request.sTagID,
+                    request.iNum,
+                    request.iMode,
+                    request.iColorIndex);
+
+
+            }
+            catch (Exception ex)
+            {
+                return content.Error(ex.Message);
+            }
+            return content;
+        }
+
+
+        /// <summary>
+        /// 鍥炶皟涓婁紶
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost, Route("RYB_PTL_UserResultAvailable"), AllowAnonymous]
+        public EPLightContent? RYB_PTL_UserResultAvailable([FromBody] List<PTLCallBackDTO> pTLCallBackDTOs)
+        {
+            EPLightContent content = new EPLightContent();
+            try
+            {
+                if (pTLCallBackDTOs == null)
+                {
+                    return content.Error("浼犲叆涓嶈兘涓虹┖");
+                }
+
+                List<TaskBackLight> taskBackLights = pTLCallBackDTOs.Select(x => new TaskBackLight()
+                {
+                    TagNo = "B1",
+                    TagCode = x.sLocator,
+                }).ToList();
+                content = _taskService.WMSLightBack(taskBackLights);
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 鎾澧欏垵濮嬪寲(涓�鏈�)
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost, Route("RYB_PTL_Connect"), AllowAnonymous]
+        public EPLightContent RYB_PTL_Connect([FromBody] ConnectDTO request)
+        {
+            EPLightContent content = new EPLightContent();
+            try
+            {
+                bool isConnected;
+
+                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);
+                }
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 鎾澧欑粨鏉熶綔涓�(涓�鏈�)
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost, Route("RYB_PTL_Disconnect"), AllowAnonymous]
+        public EPLightContent RYB_PTL_Disconnect()
+        {
+            EPLightContent content = new EPLightContent();
+            try
+            {
+                bool isDisconnected = RYB_PTL.RYB_PTL_Disconnect();
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        ///// <summary>
+        ///// 璧勬簮閲婃斁
+        ///// </summary>
+        //public void Dispose()
+        //{
+        //    UnsubscribeEvent();
+        //}
+    }
+
+}
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/WIDESEAWCS_Server.csproj" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/WIDESEAWCS_Server.csproj"
index e4876fe..a9b781d 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/WIDESEAWCS_Server.csproj"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/WIDESEAWCS_Server.csproj"
@@ -90,4 +90,10 @@
 	  <Folder Include="Log\" />
 	</ItemGroup>
 
+	<ItemGroup>
+	  <Reference Include="RYB_PTL_API">
+	    <HintPath>libs\RYB_PTL_API.dll</HintPath>
+	  </Reference>
+	</ItemGroup>
+
 </Project>
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/libs/RYB_PTL_API.dll" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/libs/RYB_PTL_API.dll"
new file mode 100644
index 0000000..dd30c2c
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/libs/RYB_PTL_API.dll"
Binary files differ
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs"
index 4010c1c..f270d4a 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs"
@@ -20,12 +20,14 @@
 using NPOI.SS.Formula.Functions;
 using NPOI.SS.UserModel;
 using NPOI.XSSF.UserModel;
+using RYB_PTL_API;
 using SqlSugar;
 using System.Diagnostics.CodeAnalysis;
 using System.DirectoryServices.Protocols;
 using System.Linq;
 using System.Net.Http.Headers;
 using System.Security.Policy;
+using System.Text;
 using System.Threading.Tasks;
 using WIDESEA_DTO.Agv;
 using WIDESEA_External.Model;
@@ -295,6 +297,96 @@
             return content;
         }
         /// <summary>
+        /// 涓�鏈熸挱绉嶅涓嬪彂
+        /// </summary>
+        /// <returns></returns>
+        public EPLightContent Phase1PickOrderInfoRequest(List<EPLightSendDTO> lightSendDTOs)
+        {
+            EPLightContent content = new EPLightContent();
+
+            try
+            {
+                string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.Phase1PickOrderInfoRequest.ToString())?.ApiAddress;
+                if (string.IsNullOrEmpty(url))
+                {
+                    return content.Error("鏈壘鍒版挱绉嶅涓嬪彂鎺ュ彛锛岃妫�鏌ユ帴鍙i厤缃�");
+                }
+
+                bool allSuccess = true;
+                StringBuilder errorMessages = new StringBuilder();
+
+                foreach (EPLightSendDTO lightSendDTO in lightSendDTOs)
+                {
+                    try
+                    {
+                        bool operationResult;
+
+                        // 澶勭悊鐏厜绫诲瀷杞崲
+                        if (!int.TryParse(lightSendDTO.LIGHTTYPE, out int lightType))
+                        {
+                            allSuccess = false;
+                            errorMessages.AppendLine($"浣嶇疆 {lightSendDTO.LOCATION} 閿欒: 鏃犳晥鐨勭伅鍏夌被鍨� '{lightSendDTO.LIGHTTYPE}'");
+                            continue;
+                        }
+
+                        // 澶勭悊鍏抽棴鐏厜璇锋眰
+                        if (lightType == 2)
+                        {
+                            operationResult = RYB_PTL.RYB_PTL_CloseDigit5(url, lightSendDTO.LOCATION);
+                            // TODO: 鍏抽棴鐏厜鍥炶皟澶勭悊
+                            List<EPLightBackDTO> lightBackDTOs = new List<EPLightBackDTO>();
+                            List<TaskBackLight> taskBackLights = lightBackDTOs.Select(x => new TaskBackLight()
+                            {
+                                TagNo = "B1",
+                                TagCode = x.LOCATION,
+                            }).ToList();
+                            content = WMSLightBack(taskBackLights);
+                        }
+                        // 澶勭悊鏄剧ず鐏厜璇锋眰
+                        else
+                        {
+                            // 澶勭悊鐏厜棰滆壊杞崲
+                            if (!int.TryParse(lightSendDTO.LIGHTCOLOR, out int lightColor))
+                            {
+                                allSuccess = false;
+                                errorMessages.AppendLine($"浣嶇疆 {lightSendDTO.LOCATION} 閿欒: 鏃犳晥鐨勭伅鍏夐鑹� '{lightSendDTO.LIGHTCOLOR}'");
+                                continue;
+                            }
+
+                            operationResult = RYB_PTL.RYB_PTL_DspDigit5(
+                                url,
+
+                                lightSendDTO.LOCATION,
+                                lightSendDTO.QUANTITY,
+                                lightType,
+                                lightColor);
+                        }
+
+                        if (!operationResult)
+                        {
+                            allSuccess = false;
+                            errorMessages.AppendLine($"浣嶇疆 {lightSendDTO.LOCATION} 鎿嶄綔澶辫触");
+                        }
+                    }
+
+                    catch (Exception ex)
+                    {
+                        allSuccess = false;
+                        errorMessages.AppendLine($"浣嶇疆 {lightSendDTO.LOCATION} 澶勭悊寮傚父: {ex.Message}");
+                    }
+                }
+
+                return allSuccess
+                    ? content.OK("鎵�鏈夋挱绉嶅涓嬪彂鎿嶄綔鎴愬姛")
+                    : content.Error(errorMessages.ToString());
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
         /// 鎾澧欎寒鐏�
         /// </summary>
         /// <returns></returns>
@@ -303,7 +395,32 @@
             WebResponseContent content = new WebResponseContent();
             try
             {
-                if (taskSendLight.TagNo=="B2")
+                if (taskSendLight.TagNo == "B1")
+                {
+                    List<EPLightSendDTO> lightSendDTOs = new List<EPLightSendDTO>()
+                    {
+                        new EPLightSendDTO
+                        {
+                            DOCNO = taskSendLight.DocNo,
+                            TASKNO= taskSendLight.TaskNo,
+                            LOCATION=taskSendLight.TagCode,
+                            QUANTITY=taskSendLight.TagQunity,
+                            LIGHTCOLOR=taskSendLight.Color switch
+                            {
+                                "Blue" => "1",
+                                "Green" => "2",
+                                "Red" => "4",
+                                _ => throw new Exception($"鏈壘鍒伴鑹插畾涔�")
+                            },
+                            ORDERTYPE="1",
+                            LIGHTTYPE=taskSendLight.Mode.ToString(),
+                        }
+                    };
+                    EPLightContent pLightContent = Phase1PickOrderInfoRequest(lightSendDTOs);
+                    if (pLightContent.Result != "0") throw new Exception($"{pLightContent.Msg}");
+                    content.OK();
+                }
+                else if (taskSendLight.TagNo == "B2")
                 {
                     List<EPLightSendDTO> lightSendDTOs = new List<EPLightSendDTO>()
                     {
@@ -332,7 +449,7 @@
                 {
                     content.OK();
                 }
-                
+
             }
             catch (Exception ex)
             {
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/WIDESEAWCS_TaskInfoService.csproj" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/WIDESEAWCS_TaskInfoService.csproj"
index 9d5c54d..4a22ba7 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/WIDESEAWCS_TaskInfoService.csproj"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/WIDESEAWCS_TaskInfoService.csproj"
@@ -24,4 +24,10 @@
 	  <AdditionalDesignTimeBuildInput Remove="FakesAssemblies\**" />
 	</ItemGroup>
 
+	<ItemGroup>
+	  <Reference Include="RYB_PTL_API">
+	    <HintPath>..\WIDESEAWCS_Server\libs\RYB_PTL_API.dll</HintPath>
+	  </Reference>
+	</ItemGroup>
+
 </Project>

--
Gitblit v1.9.3