dengjunjie
2025-04-19 9e579eda4601ed7b492b9d19a24e8146f6ebdf8d
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Information;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_Tasks.ShuttleCarJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
 
namespace WIDESEAWCS_Server.Controllers
{
    [Route("api/LargeScreen")]
    [ApiController, AllowAnonymous]
    public class LargeScreenController : Controller
    {
        private readonly IDeviceInfoRepository _deviceInfoRepository;
        private readonly IRouterService _routerService;
        private readonly ICacheService _cacheService;
        public LargeScreenController(ICacheService cacheService, IRouterService routerService, IDeviceInfoRepository deviceInfoRepository)
        {
            _deviceInfoRepository = deviceInfoRepository;
            _routerService = routerService;
            _cacheService = cacheService;
        }
 
        /// <summary>
        /// 获取穿梭车电量
        /// </summary>
        /// <returns></returns>
        [HttpPost, Route("GetShuttleCarInfos")]
        public WebResponseContent GetShuttleCarInfos()
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            int ElectricQuantity1 = 0;
            int ElectricQuantity2 = 0;
            try
            {
                var Device = _cacheService.Get(typeof(ShuttleCarTaskCommandR), "RGV01");
                if (Device != null)
                {
                    ShuttleCarTaskCommandR? shuttleCar = Device as ShuttleCarTaskCommandR;
                    if (shuttleCar != null) ElectricQuantity1 = shuttleCar.ElectricQuantity;
                }
                Device = _cacheService.Get(typeof(ShuttleCarTaskCommandR), "RGV02");
                if (Device != null)
                {
                    ShuttleCarTaskCommandR? shuttleCar = Device as ShuttleCarTaskCommandR;
                    if (shuttleCar != null) ElectricQuantity2 = shuttleCar.ElectricQuantity;
                }
            }
            catch (Exception ex)
            {
                webResponseContent.Error(ex.Message);
            }
            return webResponseContent.OK(data: new
            {
                ElectricQuantity1,
                ElectricQuantity2
            });
        }
        /// <summary>
        /// 获取设备信息
        /// </summary>
        /// <returns></returns>
        [HttpPost, Route("GetDeviceInfos")]
        public WebResponseContent GetDeviceInfos()
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            try
            {
                List<DeviceInfo> devices = new List<DeviceInfo>();
                var DeviceInfos = _deviceInfoRepository.QueryData(x => x.DeviceStatus == "1").ToList();
                foreach (var item in DeviceInfos)
                {
                    switch (item.DeviceType)
                    {
                        case "SpeStackerCrane"://堆垛机
                            {
                                var Device = _cacheService.Get(typeof(StackerCraneTaskCommandR), item.DeviceCode);
                                if (Device != null)
                                {
                                    DeviceInfo deviceInfo = new DeviceInfo()
                                    {
                                        DeviceName = item.DeviceName,
                                        Deviceinfo = Device
                                    };
                                    devices.Add(deviceInfo);
                                }
                            }
                            break;
                        case "CommonConveyorLine"://输送线
                            {
                                List<string> childDeviceCodes = _routerService.QueryAllPositions(item.DeviceCode);
                                foreach (var childDeviceCode in childDeviceCodes)
                                {
                                    var Device = _cacheService.Get(typeof(ConveyorLineTaskCommandR), childDeviceCode);
                                    if (Device != null)
                                    {
                                        DeviceInfo deviceInfo = new DeviceInfo()
                                        {
                                            DeviceName = childDeviceCode,
                                            Deviceinfo = Device
                                        };
                                        devices.Add(deviceInfo);
                                    }
                                }
                            }
                            break;
                        case "ShuttleCar"://穿梭车
                            {
                                var Device = _cacheService.Get(typeof(ShuttleCarTaskCommandR), item.DeviceCode);
                                if (Device != null)
                                {
                                    DeviceInfo deviceInfo = new DeviceInfo()
                                    {
                                        DeviceName = item.DeviceName,
                                        Deviceinfo = Device
                                    };
                                    devices.Add(deviceInfo);
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
                webResponseContent.OK(data: new
                {
                    devices
                });
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
            return webResponseContent;
        }
        public class DeviceInfo
        {
            //public string DeviceCode { get; set; }
            public string DeviceName { get; set; }
            public object Deviceinfo { get; set; }
        }
    }
}