From 2cc4dfef234b47bef364edf798b5051a25f33217 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期五, 30 八月 2024 10:58:56 +0800
Subject: [PATCH] 1

---
 WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/BasicInfo/RouterController.cs |   99 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 94 insertions(+), 5 deletions(-)

diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/BasicInfo/RouterController.cs b/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/BasicInfo/RouterController.cs
index fbc6441..c76f27c 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/BasicInfo/RouterController.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/BasicInfo/RouterController.cs
@@ -1,24 +1,113 @@
 锘縰sing Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.DataProtection.KeyManagement;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
+using Quartz.Util;
+using SqlSugar;
+using System.ComponentModel;
+using System.Reflection;
+using WIDESEAWCS_Common;
+using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.BaseController;
-using WIDESEAWCS_IBasicInfoService;
+using WIDESEAWCS_Core.Enums;
+using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_DTO.BasicInfo;
 using WIDESEAWCS_Model.Models;
+using WIDESEAWCS_QuartzJob.Models;
+using WIDESEAWCS_QuartzJob.Repository;
+using WIDESEAWCS_QuartzJob.Service;
 
 namespace WIDESEAWCS_Server.Controllers.BasicInfo
 {
-    [Route("api/router")]
+    [Route("api/Router")]
     [ApiController]
     public class RouterController : ApiBaseController<IRouterService, Dt_Router>
     {
-        public RouterController(IRouterService service) : base(service)
+        private readonly IDeviceInfoRepository _deviceInfoRepository;
+        private readonly IDeviceProtocolRepository _deviceProtocolRepository;
+        public RouterController(IRouterService service, IDeviceInfoRepository deviceInfoRepository, IDeviceProtocolRepository deviceProtocolRepository) : base(service)
         {
+            _deviceInfoRepository = deviceInfoRepository;
+            _deviceProtocolRepository = deviceProtocolRepository;
         }
 
-        [HttpPost, Route("queryRoutes"), AllowAnonymous]
+        [HttpPost, Route("QueryRoutes"), AllowAnonymous]
         public List<Dt_Router> QueryRoutes(string startPosi, string endPosi)
         {
-            return Service.QueryRoutes(startPosi, endPosi);
+            return Service.QueryNextRoutes(startPosi, endPosi);
+        }
+
+        [HttpPost, Route("QueryAllPositions"), AllowAnonymous]
+        public List<string> QueryAllPositions(string deviceCode)
+        {
+            return Service.QueryAllPositions(deviceCode);
+        }
+
+        [HttpPost, Route("GetAllWholeRouters"), AllowAnonymous]
+        public WebResponseContent GetAllWholeRouters()
+        {
+            WebResponseContent content = new();
+            try
+            {
+                List<dynamic> dynamics = Service.GetAllWholeRouters();
+
+                content = WebResponseContent.Instance.OK(data: dynamics);
+            }
+            catch (Exception ex)
+            {
+                content = WebResponseContent.Instance.Error(ex.Message);
+            }
+            return content;        }
+
+        [HttpPost, Route("GetBaseRouterInfo"), AllowAnonymous]
+        public WebResponseContent GetBaseRouterInfo()
+        {
+            try
+            {
+                #region 鑾峰彇璺敱绫诲瀷
+                List<object> routerTypes = new List<object>();
+                Type routerType = typeof(RouterInOutType);
+                List<int> routerIndexs = Enum.GetValues(typeof(RouterInOutType)).Cast<int>().ToList();
+                int routerIndex = 0;
+                foreach (var item in routerIndexs)
+                {
+                    FieldInfo? fieldInfo = routerType.GetField(((RouterInOutType)item).ToString());
+                    DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                    if (description != null)
+                    {
+                        routerTypes.Add(new { key = item.ToString(), value = description.Description });
+                    }
+                    else
+                    {
+                        routerTypes.Add(new { key = item.ToString(), value = item.ToString() });
+                    }
+                    routerIndex++;
+                }
+                #endregion
+
+                #region 鑾峰彇璁惧缂栧彿
+                object deviceCodes = _deviceProtocolRepository.QueryData(x => true).GroupBy(x => x.DeviceChildCode).Select(x => new { key = x.Key, value = x.Key }).ToList();
+
+                object areaInfos = Enum.GetNames(typeof(AreaInfo)).Select(x => new { key = x, value = x }).ToList();
+
+
+                #endregion
+
+                return WebResponseContent.Instance.OK(data: new { routerTypes, deviceCodes, areaInfos });
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+
+        }
+
+        [HttpPost, Route("AddRouters"), AllowAnonymous]
+        public WebResponseContent AddRouters([FromBody] List<RoutersAddDTO> routersAddDTOs, int routerType)
+        {
+            return Service.AddRouters(routersAddDTOs, routerType);
         }
     }
 }

--
Gitblit v1.9.3