From c9a1df9c19a64844d05d120ff171f523d77e7823 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期六, 25 四月 2026 22:15:36 +0800
Subject: [PATCH] Merge branch 'xiaoyang' into dev

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineTargetAddressSelector.cs |  165 ++++++++++++++++++++++++------------------------------
 1 files changed, 73 insertions(+), 92 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineTargetAddressSelector.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineTargetAddressSelector.cs
index 16f7735..e003d18 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineTargetAddressSelector.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/ConveyorLineTargetAddressSelector.cs
@@ -1,113 +1,94 @@
-锘縰sing WIDESEAWCS_QuartzJob;
+using Serilog;
+using WIDESEAWCS_QuartzJob;
+
 namespace WIDESEAWCS_Tasks
 {
     /// <summary>
-    /// 杈撻�佺嚎璁惧璇锋眰澶勭悊鍣細澶勭悊鎷樻潫鏈�/鎻掓嫈閽夋満涓婁笅灞傝姹傘��
+    /// 杈撻�佺嚎鐩爣鍦板潃閫夋嫨鍣�
     /// </summary>
+    /// <remarks>
+    /// </remarks>
     public class ConveyorLineTargetAddressSelector
     {
-        private const string ConstraintMachineName = "鎷樻潫鏈�";
-        private const string PinMachineName = "鎻掓嫈閽夋満";
+        /// <summary>
+        /// 鏃ュ織璁板綍鍣�
+        /// </summary>
+        /// <remarks>
+        /// 閫氳繃 Microsoft.Extensions.Logging 鎺ュ彛娉ㄥ叆锛岀敤浜庣粨鏋勫寲鏃ュ織杈撳嚭銆�
+        /// </remarks>
+        private readonly ILogger _logger;
 
-        // 鎷樻潫鏈虹偣浣�
-        private static readonly List<string> ConstraintMachineCodes = new List<string> { "10180", "20090" };
-        // 鎻掓嫈閽夋満鐐逛綅
-        private static readonly List<string> PinMachineCodes = new List<string> { "10190", "20100" };
-
-        public void HandleInboundNextAddress(CommonConveyorLine conveyorLine, string nextAddress, string childDeviceCode)
+        /// <summary>
+        /// 鏋勯�犲嚱鏁�
+        /// </summary>
+        /// <param name="logger">鏃ュ織璁板綍鍣紝鐢变緷璧栨敞鍏ュ鍣ㄨ嚜鍔ㄦ敞鍏�</param>
+        public ConveyorLineTargetAddressSelector(ILogger logger)
         {
-            HandleDeviceRequest(conveyorLine, nextAddress, childDeviceCode, isUpper: true);
+            _logger = logger; // 淇濆瓨鏃ュ織璁板綍鍣ㄥ疄渚嬶紝渚涘悗缁柟娉曚娇鐢�
         }
 
-        public void HandleOutboundNextAddress(CommonConveyorLine conveyorLine, string nextAddress, string childDeviceCode)
+        /// <summary>
+        /// 澶勭悊鍏ュ簱鍦烘櫙鐨勪笅涓�鍦板潃璇锋眰
+        /// </summary>
+        /// <remarks>
+        /// 鍏ュ簱浠诲姟鍒拌揪鏌愪釜浣嶇疆鏃惰皟鐢ㄦ鏂规硶锛屽垽鏂洰鏍囪澶囨槸鍚﹂渶瑕佺墿鏂欍��
+        /// 鍏ュ簱瀵瑰簲涓婂眰宸ヤ綅锛圠ayer.Upper锛夛紝鍥犱负鐗╂枡浠庝笂灞傝繘鍏ヤ粨搴撱��
+        /// </remarks>
+        /// <param name="conveyorLine">杈撻�佺嚎璁惧瀵硅薄锛岀敤浜庡啓鍏ョ洰鏍囧湴鍧�鍜� ACK 淇″彿</param>
+        /// <param name="nextAddress">涓嬩竴鍦板潃/鐩爣璁惧缂栫爜锛岀敤浜庤瘑鍒洰鏍囪澶囩被鍨�</param>
+        /// <param name="childDeviceCode">褰撳墠瀛愯澶囩紪鐮侊紝鐢ㄤ簬绮剧‘瀹氫綅鍐欏叆鍝釜瀛愯澶�</param>
+        public bool HandleInboundNextAddress(CommonConveyorLine conveyorLine, string nextAddress, string childDeviceCode)
         {
-            HandleDeviceRequest(conveyorLine, nextAddress, childDeviceCode, isUpper: false);
+            // 璁板綍鍏ュ簱鍦烘櫙鐨勮皟璇曟棩蹇楋紝鍖呭惈瀛愯澶囧拰鐩爣鍦板潃淇℃伅
+            WriteDebug(conveyorLine, "鍏ュ簱涓嬩竴鍦板潃", childDeviceCode, nextAddress);
+
+            var cvState = conveyorLine.GetValue<ConveyorLineDBNameNew, byte>(ConveyorLineDBNameNew.CV_State, nextAddress);
+            bool isAvailable = cvState == 2;
+            if (isAvailable)
+            {
+                return conveyorLine.SetValue(ConveyorLineDBNameNew.Target, Convert.ToInt16(nextAddress), childDeviceCode);
+            }
+            return false;
         }
 
-        private void HandleDeviceRequest(CommonConveyorLine conveyorLine, string nextAddress, string childDeviceCode, bool isUpper)
+        /// <summary>
+        /// 澶勭悊鍑哄簱鍦烘櫙鐨勪笅涓�鍦板潃璇锋眰
+        /// </summary>
+        /// <remarks>
+        /// 鍑哄簱浠诲姟鍒拌揪鏌愪釜浣嶇疆鏃惰皟鐢ㄦ鏂规硶锛屽垽鏂洰鏍囪澶囨槸鍚﹂渶瑕佸嚭鏂欍��
+        /// 鍑哄簱瀵瑰簲涓嬪眰宸ヤ綅锛圠ayer.Lower锛夛紝鍥犱负鐗╂枡浠庝笅灞傜寮�浠撳簱銆�
+        /// </remarks>
+        /// <param name="conveyorLine">杈撻�佺嚎璁惧瀵硅薄锛岀敤浜庡啓鍏ョ洰鏍囧湴鍧�鍜� ACK 淇″彿</param>
+        /// <param name="nextAddress">涓嬩竴鍦板潃/鐩爣璁惧缂栫爜锛岀敤浜庤瘑鍒洰鏍囪澶囩被鍨�</param>
+        /// <param name="childDeviceCode">褰撳墠瀛愯澶囩紪鐮侊紝鐢ㄤ簬绮剧‘瀹氫綅鍐欏叆鍝釜瀛愯澶�</param>
+        public bool HandleOutboundNextAddress(CommonConveyorLine conveyorLine, string nextAddress, string childDeviceCode)
         {
-            var devices = Storage.Devices;
+            // 璁板綍鍑哄簱鍦烘櫙鐨勮皟璇曟棩蹇楋紝鍖呭惈瀛愯澶囧拰鐩爣鍦板潃淇℃伅
+            WriteDebug(conveyorLine, "鍑哄簱涓嬩竴鍦板潃", childDeviceCode, nextAddress);
 
-            if (ConstraintMachineCodes.Contains(nextAddress))
+            var cvState = conveyorLine.GetValue<ConveyorLineDBNameNew, byte>(ConveyorLineDBNameNew.CV_State, nextAddress);
+            bool isAvailable = cvState == 2;
+            if (isAvailable)
             {
-                ConstraintMachine? constraint = devices.OfType<ConstraintMachine>().FirstOrDefault(d => d.DeviceName == ConstraintMachineName);
-                if (constraint == null)
-                {
-                    return;
-                }
-
-                ProcessDeviceRequest(
-                    conveyorLine,
-                    childDeviceCode,
-                    getMaterialRequest: () => isUpper
-                        ? constraint.GetValue<ConstraintMachineDBName, short>(ConstraintMachineDBName.MaterialRequestUpper) != 0
-                        : constraint.GetValue<ConstraintMachineDBName, short>(ConstraintMachineDBName.MaterialRequestLower) != 0,
-                    getOutputRequest: () => isUpper
-                        ? constraint.GetValue<ConstraintMachineDBName, short>(ConstraintMachineDBName.OutputRequestUpper) != 0
-                        : constraint.GetValue<ConstraintMachineDBName, short>(ConstraintMachineDBName.OutputRequestLower) != 0,
-                    setOutputReady: outputReq =>
-                    {
-                        if (isUpper)
-                        {
-                            constraint.SetValue(ConstraintMachineDBName.ConstraintTrayOutputReadyUpper, outputReq ? 1 : 0);
-                        }
-                        else
-                        {
-                            constraint.SetValue(ConstraintMachineDBName.ConstraintTrayOutputReadyLower, outputReq ? 1 : 0);
-                        }
-                    });
+                return conveyorLine.SetValue(ConveyorLineDBNameNew.Target, Convert.ToInt16(nextAddress), childDeviceCode);
             }
-            else if (PinMachineCodes.Contains(nextAddress))
-            {
-                PinMachine? pinMachine = devices.OfType<PinMachine>().FirstOrDefault(d => d.DeviceName == PinMachineName);
-                if (pinMachine == null)
-                {
-                    return;
-                }
-
-                ProcessDeviceRequest(
-                    conveyorLine,
-                    childDeviceCode,
-                    getMaterialRequest: () => isUpper
-                        ? pinMachine.GetValue<PinMachineDBName, short>(PinMachineDBName.MaterialRequestUpper) != 0
-                        : pinMachine.GetValue<PinMachineDBName, short>(PinMachineDBName.MaterialRequestLower) != 0,
-                    getOutputRequest: () => isUpper
-                        ? pinMachine.GetValue<PinMachineDBName, short>(PinMachineDBName.OutputRequestUpper) != 0
-                        : pinMachine.GetValue<PinMachineDBName, short>(PinMachineDBName.OutputRequestLower) != 0,
-                    setOutputReady: outputReq =>
-                    {
-                        if (isUpper)
-                        {
-                            pinMachine.SetValue(PinMachineDBName.PlugPinTrayOutputReadyUpper, outputReq ? 1 : 0);
-                        }
-                        else
-                        {
-                            pinMachine.SetValue(PinMachineDBName.PlugPinTrayOutputReadyLower, outputReq ? 1 : 0);
-                        }
-                    });
-            }
+            return false;
         }
-
-        private static void ProcessDeviceRequest(
-            CommonConveyorLine conveyorLine,
-            string childDeviceCode,
-            Func<bool> getMaterialRequest,
-            Func<bool> getOutputRequest,
-            Action<bool> setOutputReady)
+        /// <summary>
+        /// 鍐欏叆璋冭瘯鏃ュ織锛堝悓鏃惰緭鍑哄埌涓や釜鏃ュ織绯荤粺锛�
+        /// </summary>
+        /// <remarks>
+        /// 缁熶竴鍏ュ彛鐐规棩蹇楁牸寮忥紝鍚屾椂鍚� Microsoft.Extensions.Logging 鍜� QuartzLogger 鍐欏叆锛�
+        /// 淇濊瘉鏃ュ織鏃㈣兘鍦ㄦ帶鍒跺彴鏌ョ湅涔熻兘鍦ㄦ枃浠朵腑杩芥函銆�
+        /// </remarks>
+        /// <param name="conveyorLine">杈撻�佺嚎璁惧瀵硅薄锛岀敤浜庤幏鍙栬澶囩紪鐮佸啓鍏� QuartzLogger</param>
+        /// <param name="scenario">鍦烘櫙鎻忚堪锛屽"鍏ュ簱涓嬩竴鍦板潃"鎴�"鍑哄簱涓嬩竴鍦板潃"</param>
+        /// <param name="childDeviceCode">瀛愯澶囩紪鐮�</param>
+        /// <param name="nextAddress">鐩爣璁惧缂栫爜</param>
+        private void WriteDebug(CommonConveyorLine conveyorLine, string scenario, string childDeviceCode, string nextAddress)
         {
-            bool materialReq = getMaterialRequest();
-            bool outputReq = getOutputRequest();
-
-            if (materialReq)
-            {
-                conveyorLine.SetValue(ConveyorLineDBNameNew.Target, 1, childDeviceCode);
-                conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 1, childDeviceCode);
-            }
-            else
-            {
-                setOutputReady(outputReq);
-            }
+            // 鍐欏叆缁撴瀯鍖栨棩蹇楋紙鍙 Serilog 绛夋棩蹇楁鏋舵崟鑾凤級
+            QuartzLogHelper.LogDebug(_logger, "Handle{Scenario}锛氬瓙璁惧: {ChildDeviceCode}锛岀洰鏍囧湴鍧�: {NextAddress}", $"Handle{scenario}锛氬瓙璁惧: {childDeviceCode}锛岀洰鏍囧湴鍧�: {nextAddress}", conveyorLine.DeviceCode, scenario, childDeviceCode, nextAddress);
         }
     }
-}
-
+}
\ No newline at end of file

--
Gitblit v1.9.3