tangxu
2022-11-03 e50aa0608755bb4fbb2729912850b6ba4a5c75bc
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Net.Http.Headers;
using Microsoft.Extensions.Hosting.Internal;
using Microsoft.AspNetCore.Http.Extensions;
using IStation.Untity;
using Furion.DynamicApiController;
using System.ComponentModel.DataAnnotations;
using Mapster;
using Microsoft.AspNetCore.Http;
using Furion.DependencyInjection;
using Microsoft.AspNetCore.Authorization;
using Furion.DataEncryption;
using Furion.FriendlyException;
 
namespace IStation.Application
{
    /// <summary>
    /// 监测
    /// </summary>
    [AllowAnonymous]
    [Route("LargeScreen/Demo/Monitor")]
    [ApiDescriptionSettings("LargeScreen", Name = "Demo(监测)", Order = 666)]
    public class DemoMonitor_Controller : IDynamicApiController, ITransient
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
 
        /// <summary>
        /// 
        /// </summary>
        public DemoMonitor_Controller(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }
 
 
 
        /// <summary>
        /// 通过 StationID 获取Master常规实时列表
        /// </summary>
        [Route("GetMasterGeneralRealMonitorPointListByStationID")]
        [HttpGet]
        public List<DemoMonitorPointExSignalListDto> GetMasterGeneralRealMonitorPointListByStationID([FromQuery][Required] StationIDUnderCorpInput input)
        {
            var corpId = input.CorpID;
            var belongType = IStation.ObjectType.Station;
            var belongId = input.StationID;
            var cacheKey = $"LargeScreen_Demo_Monitor_GetMasterGeneralRealMonitorPointListByStationID_{corpId}_{belongId}";
            var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
                var allGroupList = new Service.MonitorPointGroup().GetByBelongTypeAndBelongID(corpId, belongType, belongId);
                if (allGroupList == null || allGroupList.Count < 1)
                {
                    var monitorList = new Service.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongID(corpId, belongType, belongId);
                    var vmCacheList = monitorList?.Select(x => new DemoMonitorPointExSignalListDto(x)).ToList();
                    return vmCacheList;
                }
                else
                {
                    var groupList = allGroupList.Where(x => x.Flags != null && x.Flags.Contains(LogicFlags.总站)).ToList();
                    if (groupList == null || groupList.Count < 1)
                    {
                        var monitorList = new Service.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongID(corpId, belongType, belongId);
                        var vmCacheList = monitorList?.Select(x => new DemoMonitorPointExSignalListDto(x)).ToList();
                        return vmCacheList;
                    }
                    else
                    {
                        var monitorList = new Service.MonitorPoint().GetExSignalWithSignalTypeByGroupIds(corpId, groupList.Select(x => x.ID), Model.eMonitorType.General, Model.Monitor.eCronType.Real);
                        var vmCacheList = monitorList?.Select(x => new DemoMonitorPointExSignalListDto(x)).ToList();
                        return vmCacheList;
                    }
                }
 
 
            }, CacheHelper.CacheLevel3);
 
            return vm_list;
        }
 
        /// <summary>
        /// 通过 ProductID 获取常规实时测点列表
        /// </summary>
        [Route("GetGeneralRealMonitorPointListByProductID")]
        [HttpGet]
        public List<DemoMonitorPointExSignalListDto> GetGeneralRealMonitorPointListByProductID([FromQuery][Required] ProductIDUnderCorpInput input)
        {
            var corpId = input.CorpID;
            var productId = input.ProductID;
            var cacheKey = $"LargeScreen_Demo_Monitor_GetGeneralRealMonitorPointListByProductID_{corpId}_{productId}";
            var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
                var monitorMappingList = new Service.MonitorPointMapping().GetByObjectTypeAndObjectID(corpId, ObjectType.Product, productId);
                if (monitorMappingList == null || monitorMappingList.Count < 1)
                    return default;
                var monitorIds = monitorMappingList.Select(x => x.MonitorPointID).Distinct().ToList();
                var monitorList = new Service.MonitorPoint().GetExSignalWithSignalTypeByIds(corpId, monitorIds, Model.eMonitorType.General, Model.Monitor.eCronType.Real);
                var vmCacheList = monitorList?.Select(x => new DemoMonitorPointExSignalListDto(x)).ToList(); 
                return vmCacheList;
 
            }, CacheHelper.CacheLevel3);
            return vm_list;
        }
 
        /// <summary>
        /// 通过 BelongType 和 BelongID 获取常规实时列表
        /// </summary>
        [Route("GetGeneralRealMonitorPointListByStationID")]
        [HttpGet]
        public List<DemoMonitorPointExSignalListDto> GetGeneralRealMonitorPointListByStationID([FromQuery][Required] StationIDUnderCorpInput input)
        {
            var corpId = input.CorpID;
            var belongType = IStation.ObjectType.Station;
            var belongId = input.StationID;
            var cacheKey = $"LargeScreen_Demo_Monitor_GetGeneralRealMonitorPointListByStationID_{corpId}_{belongId}";
            var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
 
                var monitorList = new Service.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongID
                                            (corpId, belongType, belongId, Model.eMonitorType.General, Model.Monitor.eCronType.Real);
                var vmCacheList = monitorList?.Select(x => new DemoMonitorPointExSignalListDto(x)).ToList();
                return vmCacheList;
 
            }, CacheHelper.CacheLevel3);
 
            return vm_list;
        }
 
 
        /// <summary>
        /// 通过 BelongType 和 BelongID 获取常规测点逻辑树
        /// </summary>
        [Route("GetGeneralMonitorPointLogicalTreeByBelongTypeAndBelongID")]
        [HttpGet]
        public List<LogicalTreeItemDto> GetGeneralMonitorPointLogicalTreeByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input)
        {
            var corpId = input.CorpID;
            var belongType = input.BelongType;
            var belongId = input.BelongID;
 
            var cacheKey = $"LargeScreen_Demo_Monitor_GetGeneralMonitorPointLogicalTreeByBelongTypeAndBelongID_{corpId}_{belongType}_{belongId}";
            var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
 
                #region 监测点组
 
                var group_list = new Service.MonitorPointGroup().GetByBelongTypeAndBelongID(corpId, belongType, belongId);
                var vm_group_list = group_list?.Select(x => new DemoMonitorPointGroupDto(x)).ToList();
                var vm_cache_group_list = vm_group_list?.Select(x =>
                {
                    var vm_cache_group = new LogicalTreeItemDto();
                    vm_cache_group.ID = $"{ObjectType.MonitorPointGroup}_{x.ID}";
                    vm_cache_group.ParentID = $"{ObjectType.MonitorPointGroup}_{x.ParentID}";
                    vm_cache_group.LogicalName = x.Name;
                    vm_cache_group.LogicalType = ObjectType.MonitorPointGroup;
                    vm_cache_group.LogicalID = x.ID;
                    vm_cache_group.LogicalModel = x;
                    vm_cache_group.Children = new List<LogicalTreeItemDto>();
                    return vm_cache_group;
                }).ToList();
 
                #endregion
 
                #region 监测点
 
                var monitor_list = new Service.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongID(corpId, belongType, belongId, Model.eMonitorType.General);
                var vm_monitor_list = monitor_list?.Select(x => new DemoMonitorPointExSignalListDto(x)).ToList(); 
                var vm_cache_monitor_list = vm_monitor_list?.Select(x =>
                {
                    var vm_cache_monitor = new LogicalTreeItemDto();
                    vm_cache_monitor.ID = $"{ObjectType.MonitorPoint}_{x.ID}";
                    vm_cache_monitor.ParentID = $"{ObjectType.MonitorPointGroup}_{x.GroupID}";
                    vm_cache_monitor.LogicalName = x.Name;
                    vm_cache_monitor.LogicalType = ObjectType.MonitorPoint;
                    vm_cache_monitor.LogicalID = x.ID;
                    vm_cache_monitor.LogicalModel = x;
                    vm_cache_monitor.Children = null;
                    return vm_cache_monitor;
                }).ToList();
 
                #endregion
 
                #region 生成树
 
                var vm_cache_list = new List<LogicalTreeItemDto>();
 
                //遍历测点
                if (vm_cache_monitor_list != null && vm_cache_monitor_list.Count > 0)
                {
                    foreach (var vm_cache_monitor in vm_cache_monitor_list)
                    {
                        var vm_cache_monitor_parent = vm_cache_group_list?.Find(t => t.ID == vm_cache_monitor.ParentID);
                        if (vm_cache_monitor_parent == null)
                        {
                            vm_cache_list.Add(vm_cache_monitor);
                        }
                        else
                        {
                            vm_cache_monitor_parent.Children.Add(vm_cache_monitor);
                        }
                    }
                }
 
                //遍历测点组
                if (vm_cache_group_list != null && vm_cache_group_list.Count > 0)
                {
                    foreach (var vm_cache_group in vm_cache_group_list)
                    {
                        var vm_cahce_group_parent = vm_cache_group_list.Find(t => t.ID == vm_cache_group.ParentID);
                        if (vm_cahce_group_parent == null)
                        {
                            vm_cache_list.Add(vm_cache_group);
                        }
                        else
                        {
                            vm_cahce_group_parent.Children.Add(vm_cache_group);
                        }
                    }
                }
 
                return vm_cache_list;
 
                #endregion
 
            }, CacheHelper.CacheLevel2);
 
            return vm_list;
        }
 
        /// <summary>
        /// 通过 BelongType 和 BelongID 获取常规实时测点逻辑树
        /// </summary>
        [Route("GetGeneralRealMonitorPointLogicalTreeByBelongTypeAndBelongID")]
        [HttpGet]
        public List<LogicalTreeItemDto> GetGeneralRealMonitorPointLogicalTreeByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input)
        {
            var corpId = input.CorpID;
            var belongType = input.BelongType;
            var belongId = input.BelongID;
 
            var cacheKey = $"LargeScreen_Demo_Monitor_GetGeneralRealMonitorPointLogicalTreeByBelongTypeAndBelongID_{corpId}_{belongType}_{belongId}";
            var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
 
                #region 监测点组
 
                var group_list = new Service.MonitorPointGroup().GetByBelongTypeAndBelongID(corpId, belongType, belongId);
                var vm_group_list = group_list?.Select(x => new DemoMonitorPointGroupDto(x)).ToList();
                var vm_cache_group_list = vm_group_list?.Select(x =>
                {
                    var vm_cache_group = new LogicalTreeItemDto();
                    vm_cache_group.ID = $"{ObjectType.MonitorPointGroup}_{x.ID}";
                    vm_cache_group.ParentID = $"{ObjectType.MonitorPointGroup}_{x.ParentID}";
                    vm_cache_group.LogicalName = x.Name;
                    vm_cache_group.LogicalType = ObjectType.MonitorPointGroup;
                    vm_cache_group.LogicalID = x.ID;
                    vm_cache_group.LogicalModel = x;
                    vm_cache_group.Children = new List<LogicalTreeItemDto>();
                    return vm_cache_group;
                }).ToList();
 
                #endregion
 
                #region 监测点
 
                var monitor_list = new Service.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongID
                                                            (corpId, belongType, belongId, Model.eMonitorType.General, Model.Monitor.eCronType.Real);
                var vm_monitor_list = monitor_list?.Select(x => new DemoMonitorPointExSignalListDto(x)).ToList();
                var vm_cache_monitor_list = vm_monitor_list?.Select(x =>
                {
                    var vm_cache_monitor = new LogicalTreeItemDto();
                    vm_cache_monitor.ID = $"{ObjectType.MonitorPoint}_{x.ID}";
                    vm_cache_monitor.ParentID = $"{ObjectType.MonitorPointGroup}_{x.GroupID}";
                    vm_cache_monitor.LogicalName = x.Name;
                    vm_cache_monitor.LogicalType = ObjectType.MonitorPoint;
                    vm_cache_monitor.LogicalID = x.ID;
                    vm_cache_monitor.LogicalModel = x;
                    vm_cache_monitor.Children = null;
                    return vm_cache_monitor;
                }).ToList();
 
                #endregion
 
                #region 生成树
 
                var vm_cache_list = new List<LogicalTreeItemDto>();
 
                //遍历测点
                if (vm_cache_monitor_list != null && vm_cache_monitor_list.Count > 0)
                {
                    foreach (var vm_cache_monitor in vm_cache_monitor_list)
                    {
                        var vm_cache_monitor_parent = vm_cache_group_list?.Find(t => t.ID == vm_cache_monitor.ParentID);
                        if (vm_cache_monitor_parent == null)
                        {
                            vm_cache_list.Add(vm_cache_monitor);
                        }
                        else
                        {
                            vm_cache_monitor_parent.Children.Add(vm_cache_monitor);
                        }
                    }
                }
 
                //遍历测点组
                if (vm_cache_group_list != null && vm_cache_group_list.Count > 0)
                {
                    foreach (var vm_cache_group in vm_cache_group_list)
                    {
                        var vm_cahce_group_parent = vm_cache_group_list.Find(t => t.ID == vm_cache_group.ParentID);
                        if (vm_cahce_group_parent == null)
                        {
                            vm_cache_list.Add(vm_cache_group);
                        }
                        else
                        {
                            vm_cahce_group_parent.Children.Add(vm_cache_group);
                        }
                    }
                }
 
                return vm_cache_list;
 
                #endregion
 
            }, CacheHelper.CacheLevel2);
 
            return vm_list;
        }
 
    }
}