From a6ea79849f0142b5280f0c5d4b15ecc83f0d015a Mon Sep 17 00:00:00 2001
From: 刘磊 <1161824510@qq.com>
Date: 星期六, 21 十二月 2024 09:52:27 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/HuaYiZhongHeng/BaiBuLiKu

---
 Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs |   89 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 87 insertions(+), 2 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..a60279f 100644
--- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs
+++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs
@@ -30,12 +30,74 @@
         /// <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
             {
+                // 鏋勫缓涓�涓敮涓�鏍囪瘑褰撳墠璧风偣鍜岀粓鐐圭粍鍚堢殑瀛楃涓�
+                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, new Dictionary<string, OrderByType> { { nameof(Dt_Router.IsEnd), OrderByType.Desc } });
                 if (dt_Routers.Count > 0)
                 {
@@ -47,7 +109,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 +127,7 @@
             }
             catch (Exception ex)
             {
+                // 杩欓噷鍙互鏍规嵁瀹為檯闇�姹傛洿濂藉湴澶勭悊寮傚父锛屾瘮濡傝褰曟棩蹇楃瓑锛岀洰鍓嶅彧鏄敞閲婃帀浜嗙洿鎺ユ姏鍑哄紓甯�
                 //throw new Exception(ex.Message);
                 //璁板綍閿欒淇℃伅
             }
@@ -238,5 +301,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