From e98b07c84a2a496da895ef6b523b29ccc75e004d Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期五, 23 八月 2024 11:27:01 +0800
Subject: [PATCH] 更新QuartzJob种子数据插入

---
 WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/RouterService.cs |   93 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 91 insertions(+), 2 deletions(-)

diff --git a/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/RouterService.cs b/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/RouterService.cs
index 39614ba..f5c3731 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/RouterService.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/RouterService.cs
@@ -4,7 +4,9 @@
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.BaseServices;
+using WIDESEAWCS_Core.Enums;
 using WIDESEAWCS_IBasicInfoRepository;
 using WIDESEAWCS_IBasicInfoService;
 using WIDESEAWCS_Model.Models;
@@ -17,7 +19,7 @@
         {
         }
 
-        public List<Dt_Router> QueryRoutes(string startPosi, string endPosi)
+        public List<Dt_Router> QueryNextRoutes(string startPosi, string endPosi)
         {
             List<Dt_Router> routers = new List<Dt_Router>();
             try
@@ -33,7 +35,7 @@
                         }
                         else
                         {
-                            List<Dt_Router> tempRouters = QueryRoutes(startPosi, item.StartPosi);
+                            List<Dt_Router> tempRouters = QueryNextRoutes(startPosi, item.StartPosi);
                             foreach (var router in tempRouters)
                             {
                                 if (router.StartPosi == startPosi && !routers.Any(x => x.Id == router.Id))
@@ -56,5 +58,92 @@
             }
             return routers;
         }
+
+
+        public List<string> QueryAllPositions(string deviceCode)
+        {
+            List<string> positions = new List<string>();
+            try
+            {
+                List<string> inRouterPositions = BaseDal.QueryData(x => x.ChildPosiDeviceCode == deviceCode && x.InOutType == RouterInOutType.In).GroupBy(x => x.StartPosi).Select(x => x.Key).ToList();
+
+                List<string> outRouterPositions = BaseDal.QueryData(x => x.ChildPosiDeviceCode == deviceCode && x.InOutType == RouterInOutType.Out).GroupBy(x => x.ChildPosi).Select(x => x.Key).ToList();
+
+                positions.AddRange(inRouterPositions);
+                positions.AddRange(outRouterPositions);
+                return positions.GroupBy(x => x).Select(x => x.Key).ToList();
+            }
+            catch
+            {
+
+            }
+            return positions;
+        }
+
+        public WebResponseContent GetAllWholeRouters()
+        {
+            WebResponseContent content = new();
+            try
+            {
+                List<object> data = new List<object>();
+                List<Dt_Router> dt_Routers = BaseDal.QueryData(x => x.IsEnd, new Dictionary<string, OrderByType> { { nameof(Dt_Router.IsEnd), OrderByType.Desc } });
+                
+                foreach (var item in dt_Routers)
+                {
+                    string routes = $"{item.ChildPosi},";
+                    string str = GetPreviousRoutes(item.StartPosi);
+                    if (!string.IsNullOrEmpty(str))
+                    {
+                        if (str.EndsWith(","))
+                            str = str.Substring(0, str.Length - 1);
+                        routes += str;
+                    }
+                    if (item.InOutType == RouterInOutType.In)
+                    {
+                        List<string> itemRouters = routes.Split(",").Reverse().ToList();
+                        object obj = new { type = RouterInOutType.In, routes = itemRouters };
+                        data.Add(obj);
+                    }
+                    else
+                    {
+                        List<string> itemRouters = routes.Split(",").Reverse().ToList();
+                        object obj = new { type = RouterInOutType.Out, routes = itemRouters };
+                        data.Add(obj);
+                    }
+                }
+
+                content = WebResponseContent.Instance.OK(data: data);
+            }
+            catch (Exception ex)
+            {
+
+            }
+            return content;
+        }
+
+        public string GetPreviousRoutes(string startPosi)
+        {
+            string routers = string.Empty;
+            if (!string.IsNullOrEmpty(startPosi))
+            {
+                if (!routers.EndsWith(","))
+                    routers += $"{startPosi},";
+                else
+                    routers += $"{startPosi}";
+            }
+            List<Dt_Router> preRouters = BaseDal.QueryData(x => x.NextPosi == startPosi, new Dictionary<string, OrderByType> { { nameof(Dt_Router.IsEnd), OrderByType.Desc } });
+            foreach (var item in preRouters)
+            {
+                string str = GetPreviousRoutes(item.StartPosi);
+                if (!string.IsNullOrEmpty(str))
+                {
+                    if (routers.EndsWith(","))
+                        routers += $"{str}";
+                    else
+                        routers += $"{str},";
+                }
+            }
+            return routers;
+        }
     }
 }

--
Gitblit v1.9.3