dengjunjie
2025-04-14 970d9c5c36d526a587138232ae9dae719dbcd16d
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
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("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 = item.DeviceName,
                                            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; }
        }
    }
}