From d4cae5c48af02e109b1febce8c7c21e560cd6525 Mon Sep 17 00:00:00 2001
From: xxyy <cathay_xy@163.com>
Date: 星期二, 18 三月 2025 14:23:55 +0800
Subject: [PATCH] 更新配置和代码逻辑,优化查询及日志

---
 Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs |  100 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 95 insertions(+), 5 deletions(-)

diff --git a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs
index b389354..2d7637b 100644
--- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs
+++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs
@@ -1,4 +1,5 @@
-锘縰sing SqlSugar;
+锘縰sing Masuit.Tools;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -30,13 +31,79 @@
         /// <param name="startPosi">璧风偣/褰撳墠浣嶇疆銆�</param>
         /// <param name="endPosi">缁堢偣銆�</param>
         /// <returns>杩斿洖璺敱瀹炰綋闆嗗悎銆�</returns>
+        //public List<Dt_Router> QueryNextRoutes(string startPosi, string endPosi)
+        //{
+        //    //todo 鏂规硶闇�浼樺寲
+        //    List<Dt_Router> routers = new List<Dt_Router>();
+        //    try
+        //    {
+        //        List<Dt_Router> dt_Routers = BaseDal.QueryData(x => x.NextPosi == endPosi || x.ChildPosi == endPosi, new Dictionary<string, OrderByType> { { nameof(Dt_Router.IsEnd), OrderByType.Desc } });
+        //        if (dt_Routers.Count > 0)
+        //        {
+        //            foreach (var item in dt_Routers)
+        //            {
+        //                if (item.StartPosi == startPosi && !routers.Any(x => x.Id == item.Id))
+        //                {
+        //                    routers.Add(item);
+        //                }
+        //                else
+        //                {
+        //                    List<Dt_Router> tempRouters = QueryNextRoutes(startPosi, item.StartPosi);
+        //                    foreach (var router in tempRouters)
+        //                    {
+        //                        if (router.StartPosi == startPosi && !routers.Any(x => x.Id == router.Id))
+        //                        {
+        //                            routers.Add(router);
+        //                        }
+        //                    }
+        //                }
+        //            }
+        //        }
+        //        else
+        //        {
+        //            throw new Exception($"璇ヨ矾寰勬湭閰嶇疆鎴栭厤缃敊璇�,璇锋鏌ヨ澶囪矾鐢变俊鎭�,璧风偣:銆恵startPosi}銆�,缁堢偣:銆恵endPosi}銆�");
+        //        }
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        //throw new Exception(ex.Message);
+        //        //璁板綍閿欒淇℃伅
+        //    }
+        //    return routers;
+        //}
+
+        /// <summary>
+        /// 鏍规嵁璧风偣/褰撳墠浣嶇疆銆佺粓鐐硅幏鍙栦笅涓�涓瓙鑺傜偣銆�
+        /// </summary>
+        /// <param name="startPosi">璧风偣/褰撳墠浣嶇疆銆�</param>
+        /// <param name="endPosi">缁堢偣銆�</param>
+        /// <returns>杩斿洖璺敱瀹炰綋闆嗗悎銆�</returns>
         public List<Dt_Router> QueryNextRoutes(string startPosi, string endPosi)
         {
-            //todo 鏂规硶闇�浼樺寲
+            // 鐢ㄤ簬璁板綍宸茬粡璁块棶杩囩殑璧风偣鍜岀粓鐐圭粍鍚堬紝閬垮厤閲嶅璁块棶杩涘叆姝诲惊鐜�
+            HashSet<string> visitedRoutes = new HashSet<string>();
+            return QueryNextRoutesInternal(startPosi, endPosi, visitedRoutes);
+        }
+
+        private List<Dt_Router> QueryNextRoutesInternal(string startPosi, string endPosi, HashSet<string> visitedRoutes)
+        {
             List<Dt_Router> routers = new List<Dt_Router>();
             try
             {
-                List<Dt_Router> dt_Routers = BaseDal.QueryData(x => x.NextPosi == endPosi || x.ChildPosi == endPosi, new Dictionary<string, OrderByType> { { nameof(Dt_Router.IsEnd), OrderByType.Desc } });
+                // 鏋勫缓涓�涓敮涓�鏍囪瘑褰撳墠璧风偣鍜岀粓鐐圭粍鍚堢殑瀛楃涓�
+                string routeKey = $"{startPosi}_{endPosi}";
+                if (visitedRoutes.Contains(routeKey))
+                {
+                    // 濡傛灉宸茬粡璁块棶杩囷紝鐩存帴杩斿洖绌哄垪琛紝閬垮厤閲嶅杩涘叆鐩稿悓鐨勯�掑綊鍒嗘敮
+                    return routers;
+                }
+                visitedRoutes.Add(routeKey);
+
+                List<Dt_Router> dt_Routers = BaseDal.QueryData(x => (x.NextPosi == endPosi || x.ChildPosi == endPosi) && x.StartPosi == startPosi, new Dictionary<string, OrderByType> { { nameof(Dt_Router.IsEnd), OrderByType.Desc } });
+                if (dt_Routers.IsNullOrEmpty())
+                {
+                    dt_Routers = BaseDal.QueryData(x => x.NextPosi == endPosi || x.ChildPosi == endPosi, new Dictionary<string, OrderByType> { { nameof(Dt_Router.IsEnd), OrderByType.Desc } });
+                }
                 if (dt_Routers.Count > 0)
                 {
                     foreach (var item in dt_Routers)
@@ -47,7 +114,7 @@
                         }
                         else
                         {
-                            List<Dt_Router> tempRouters = QueryNextRoutes(startPosi, item.StartPosi);
+                            List<Dt_Router> tempRouters = QueryNextRoutesInternal(startPosi, item.StartPosi, visitedRoutes);
                             foreach (var router in tempRouters)
                             {
                                 if (router.StartPosi == startPosi && !routers.Any(x => x.Id == router.Id))
@@ -65,6 +132,7 @@
             }
             catch (Exception ex)
             {
+                // 杩欓噷鍙互鏍规嵁瀹為檯闇�姹傛洿濂藉湴澶勭悊寮傚父锛屾瘮濡傝褰曟棩蹇楃瓑锛岀洰鍓嶅彧鏄敞閲婃帀浜嗙洿鎺ユ姏鍑哄紓甯�
                 //throw new Exception(ex.Message);
                 //璁板綍閿欒淇℃伅
             }
@@ -201,7 +269,7 @@
                     {
                         if (routerType == (int)RouterInOutType.Out)
                             router.ChildPosi = routersAddDTOs[i + 1].ChildPositionCode;
-                         router.IsEnd = true;
+                        router.IsEnd = true;
                     }
                     routers.Add(router);
                 }
@@ -238,5 +306,27 @@
             }
             return content;
         }
+
+        /// <summary>
+        /// 鏍规嵁璁惧缂栧彿鑾峰彇鍑哄簱璺敱鐐逛綅
+        /// </summary>
+        /// <param name="deviceCode"></param>
+        /// <returns></returns>
+        public List<string> QueryOutDeviceCodes(string deviceCode)
+        {
+            List<string> positions = new List<string>();
+            try
+            {
+                List<string> outRouterPositions = BaseDal.QueryData(x => x.ChildPosiDeviceCode == deviceCode && x.InOutType == RouterInOutType.Out).GroupBy(x => x.ChildPosi).Select(x => x.Key).ToList();
+
+                positions.AddRange(outRouterPositions);
+                return positions.GroupBy(x => x).Select(x => x.Key).ToList();
+            }
+            catch
+            {
+
+            }
+            return positions;
+        }
     }
 }

--
Gitblit v1.9.3