From 58a5a9af83492c5bbb4fba88b4443f08fa4becfc Mon Sep 17 00:00:00 2001
From: 刘磊 <1161824510@qq.com>
Date: 星期二, 17 十二月 2024 19:53:14 +0800
Subject: [PATCH] 解决冲突

---
 Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/RouterService.cs |   67 ++++++++++++++++++++++++++++++++-
 1 files changed, 65 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 a656551..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);
                 //璁板綍閿欒淇℃伅
             }

--
Gitblit v1.9.3