hutongqing
2024-11-20 0845150c79d1ebd664753931933e786ed8bd06c4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using 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_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")]
    [ApiController]
    public class RouterController : ApiBaseController<IRouterService, Dt_Router>
    {
        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]
        public List<Dt_Router> QueryRoutes(string startPosi, string 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);
        }
    }
}