lixiaojun
2024-09-09 c0f3c3f170846197d8d3f74ac123e0ac93a6dd67
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
namespace IStation.Application
{
    /// <summary>
    /// Map
    /// </summary>
    [Route("SZJT/Map/Mobile")]
    [ApiDescriptionSettings("SZJT", Name = "地图(手机)", Order = 1600)]
    public class Map_MobileController : IDynamicApiController
    {
 
        /// <summary>
        /// 获取泵站列表
        /// </summary>
        [Route("GetStationList@V1.0")]
        [HttpGet]
        public List<StationMapMobileDto> GetStationList()
        {
            var keyContent = $"SZJT_Map_Mobile_GetStationList";
            var cacheKey = MemoryCacheKeyHelper.GetKey(MemoryCacheKey.WebApiLevel, MemoryCacheKey.Module, keyContent);
 
            var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
                var allList = new Yw.Service.LogicSite().GetAll();
                Yw.Service.LogicSite.PublishCache(cacheKey);
                if (allList == null || allList.Count < 1)
                {
                    return default;
                }
 
                var serviceMap = new Yw.Service.MapInfo();
                var vmList = new List<StationMapMobileDto>();
                foreach (var station in allList)
                {
                    var vm = new StationMapMobileDto(station);
                    vmList.Add(vm);
                    var map = serviceMap.Get(IStation.DataType.LogicSite, station.ID, Yw.Map.Kind.Gaodei, Yw.Map.Purpose.Location);
                    if (map != null)
                    {
                        var position = Yw.Model.Map.Marker.ToModel(map.Position);
                        vm.Position = position;
                    }
                }
                return vmList;
 
            }, Yw.Service.ConfigHelper.CacheLevel3);
            return vm_list;
        }
 
        /// <summary>
        /// 通过 StationID 获取监测Kpi信息
        /// </summary>
        [Route("GetMonitorKpiInfoByStationID@V1.0")]
        [HttpGet]
        public StationMapMonitorKpiInfoMobileDto GetMonitorKpiInfoByStationID([FromQuery][Required] StationIDInput input)
        {
            var station = new Yw.Service.LogicSite().GetByID(input.StationID);
            if (station == null)
            {
                throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"StationID:{input.StationID} 数据不存在");
            }
            var vm = new StationMapMonitorKpiInfoMobileDto(station);
 
            var allMonitorList = new Yw.Service.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongID(IStation.DataType.LogicSite, station.ID);
            allMonitorList = allMonitorList?.Where(x => x.UseStatus == Yw.Model.eUseStatus.Enable).ToList();
            allMonitorList = allMonitorList?.Where(x => x.CronType == Yw.Monitor.eCronType.Real).ToList();
            if (allMonitorList != null && allMonitorList.Count > 0)
            {
                allMonitorList = allMonitorList.Where(x => x.Flags.Contains(Flags.KPI)).OrderByDescending(X => X.Importance).ToList();
                if (allMonitorList.Count > 0)
                {
                    var service_monitor_record = new Yw.Service.MonitorRealRecord();
                    allMonitorList = allMonitorList.Take(4).ToList();
                    foreach (var monitor in allMonitorList)
                    {
                        var monitorRecord = service_monitor_record.GetLastRecord(monitor.SignalList.First().ID);
                        vm.LastRecordList.Add(new StationMapMonitorKpiLastRecordMobileDto(monitor, monitorRecord));
                    }
                }
            }
 
            var allEquipmentList = new Yw.Service.Equipment().GetByBelongTypeAndBelongID(IStation.DataType.LogicSite, station.ID);
            allEquipmentList = allEquipmentList?.Where(x => x.ParentIds.Count < 1).ToList();
            if (allEquipmentList != null && allEquipmentList.Count > 0)
            {
                var service_run_record = new Yw.Service.RunRealRecord();
                foreach (var equipment in allEquipmentList)
                {
                    var runRecord = service_run_record.GetLastRecord(Yw.Assets.DataType.Equipment, equipment.ID);
                    vm.LastStatusList.Add(new StationMapMonitorKpiLastStatusMobileDto(equipment, runRecord));
                }
            }
 
            return vm;
        }
 
        /// <summary>
        /// 获取流量计列表
        /// </summary>
        [Route("GetFlowMeterList@V1.0")]
        [HttpGet]
        public List<FlowMeterMapMobileDto> GetFlowMeterList()
        {
            var keyContent = $"SZJT_Map_Mobile_GetFlowMeterList";
            var cacheKey = MemoryCacheKeyHelper.GetKey(MemoryCacheKey.WebApiLevel, MemoryCacheKey.Module, keyContent);
 
            var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
                var catalogList = new Yw.Service.SysCatalog().GetChildAndSelfByCode(IStation.Catalog.FlowMeter);
                Yw.Service.SysCatalog.PublishCache(cacheKey);
                if (catalogList == null || catalogList.Count < 1)
                {
                    throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, "流量计分类编码验证失败");
                }
                var catalogIds = catalogList.Select(x => x.ID).Distinct().ToList();
 
                var allMeterList = new Yw.Service.Equipment().GetByBelongTypeAndBelongID(IStation.DataType.LogicDma, 1);
                Yw.Service.Equipment.PublishCache(cacheKey);
                allMeterList = allMeterList?.Where(x => catalogIds.Contains(x.CatalogID)).ToList();
                if (allMeterList == null || allMeterList.Count < 1)
                {
                    return default;
                }
 
                var service_map = new Lazy<Yw.Service.MapInfo>(() => new Yw.Service.MapInfo());
 
                var vmList = new List<FlowMeterMapMobileDto>();
                foreach (var meter in allMeterList)
                {
                    var vm = new FlowMeterMapMobileDto(meter);
                    vmList.Add(vm);
 
                    var mapInfo = service_map.Value.Get(Yw.Assets.DataType.Equipment, meter.ID, Yw.Map.Kind.Gaodei, Yw.Map.Purpose.Location);
                    if (mapInfo != null)
                    {
                        vm.Position = Yw.Model.Map.Marker.ToModel(mapInfo.Position);
                    }
 
                }
 
                return vmList;
 
            }, Yw.Service.ConfigHelper.CacheLevel3);
            return vm_list;
        }
 
        /// <summary>
        /// 通过 FlowMeterID 获取监测Kpi信息
        /// </summary>
        [Route("GetMonitorKpiInfoByFlowMeterID@V1.0")]
        [HttpGet]
        public FlowMeterMapMonitorKpiInfoMobileDto GetMonitorKpiInfoByFlowMeterID([FromQuery][Required] FlowMeterIDInput input)
        {
            var equipment = new Yw.Service.Equipment().GetByID(input.FlowMeterID);
            if (equipment == null)
            {
                throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"FlowMeterID:{input.FlowMeterID} 数据不存在");
            }
            var catalogList = new Yw.Service.SysCatalog().GetChildAndSelfByCode(IStation.Catalog.FlowMeter);
            if (catalogList == null || catalogList.Count < 1)
            {
                throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, "流量计分类编码验证失败");
            }
            var catalogIds = catalogList.Select(x => x.ID).Distinct().ToList();
            if (!catalogIds.Contains(equipment.CatalogID))
            {
                throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"FlowMeterID:{input.FlowMeterID} 请输入正确流量计id");
            }
 
            var vm = new FlowMeterMapMonitorKpiInfoMobileDto();
            vm.FlowMeterID = input.FlowMeterID;
            vm.Name = equipment.Name;
            vm.LastRecordList = new List<FlowMeterMapMonitorKpiLastRecordMobileDto>();
 
            var service_monitor_mapping = new Yw.Service.EquipmentMonitorMapping();
            var mappingList = new Yw.Service.EquipmentMonitorMapping().GetByEquipmentID(input.FlowMeterID);
            if (mappingList != null && mappingList.Count > 0)
            {
                var monitorIds = mappingList.Select(x => x.MonitorPointID).Distinct().ToList();
                var monitorList = new Yw.Service.MonitorPoint().GetExSignalWithSignalTypeByIds(monitorIds);
                monitorList = monitorList?.Where(x => x.UseStatus == Yw.Model.eUseStatus.Enable).ToList();
                monitorList = monitorList?.Where(x => x.CronType == Yw.Monitor.eCronType.Real).ToList();
                if (monitorList != null && monitorList.Count > 0)
                {
                    var service_monitor_record = new Lazy<Yw.Service.MonitorRealRecord>(() => new Yw.Service.MonitorRealRecord());
                    var monitorQ = monitorList.Find(x => x.Flags.Contains(IStation.Flags.默认) && x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.瞬时流量));
                    if (monitorQ == null)
                    {
                        monitorQ = monitorList.Find(x => x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.瞬时流量));
                    }
                    if (monitorQ != null)
                    {
                        var signalQ = monitorQ.SignalList.First();
                        var last_record = service_monitor_record.Value.GetLastRecord(signalQ.ID);
                        if (last_record != null)
                        {
                            vm.LastRecordList.Add(new FlowMeterMapMonitorKpiLastRecordMobileDto(monitorQ, last_record));
                        }
                    }
 
                    var monitorQl = monitorList.Find(x => x.Flags.Contains(IStation.Flags.默认) && x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.累积流量));
                    if (monitorQl == null)
                    {
                        monitorQl = monitorList.Find(x => x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.累积流量));
                    }
                    if (monitorQl != null)
                    {
                        var signalQl = monitorQl.SignalList.First();
                        var last_record = service_monitor_record.Value.GetLastRecord(signalQl.ID);
                        if (last_record != null)
                        {
                            vm.LastRecordList.Add(new FlowMeterMapMonitorKpiLastRecordMobileDto(monitorQl, last_record));
                        }
                    }
 
                }
            }
 
            return vm;
 
        }
 
        /// <summary>
        /// 获取压力计列表
        /// </summary>
        [Route("GetPressMeterList@V1.0")]
        [HttpGet]
        public List<FlowMeterMapMobileDto> GetPressMeterList()
        {
            var keyContent = $"SZJT_Map_Mobile_GetPressMeterList";
            var cacheKey = MemoryCacheKeyHelper.GetKey(MemoryCacheKey.WebApiLevel, MemoryCacheKey.Module, keyContent);
 
            var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
                var catalogList = new Yw.Service.SysCatalog().GetChildAndSelfByCode(IStation.Catalog.PressMeter);
                Yw.Service.SysCatalog.PublishCache(cacheKey);
                if (catalogList == null || catalogList.Count < 1)
                {
                    throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, "压力计分类编码验证失败");
                }
                var catalogIds = catalogList.Select(x => x.ID).Distinct().ToList();
 
                var allMeterList = new Yw.Service.Equipment().GetByBelongTypeAndBelongID(IStation.DataType.LogicDma, 1);
                Yw.Service.Equipment.PublishCache(cacheKey);
                allMeterList = allMeterList?.Where(x => catalogIds.Contains(x.CatalogID)).ToList();
                if (allMeterList == null || allMeterList.Count < 1)
                {
                    return default;
                }
 
                var service_map = new Lazy<Yw.Service.MapInfo>(() => new Yw.Service.MapInfo());
 
                var vmList = new List<FlowMeterMapMobileDto>();
                foreach (var meter in allMeterList)
                {
                    var vm = new FlowMeterMapMobileDto(meter);
                    vmList.Add(vm);
 
                    var mapInfo = service_map.Value.Get(Yw.Assets.DataType.Equipment, meter.ID, Yw.Map.Kind.Gaodei, Yw.Map.Purpose.Location);
                    if (mapInfo != null)
                    {
                        vm.Position = Yw.Model.Map.Marker.ToModel(mapInfo.Position);
                    }
 
                }
 
                return vmList;
 
            }, Yw.Service.ConfigHelper.CacheLevel3);
            return vm_list;
        }
 
        /// <summary>
        /// 通过 PressMeterID 获取监测Kpi信息
        /// </summary>
        [Route("GetMonitorKpiInfoByPressMeterID@V1.0")]
        [HttpGet]
        public PressMeterMapMonitorKpiInfoMobileDto GetMonitorKpiInfoByPressMeterID([FromQuery][Required] PressMeterIDInput input)
        {
            var equipment = new Yw.Service.Equipment().GetByID(input.PressMeterID);
            if (equipment == null)
            {
                throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"PressMeterID:{input.PressMeterID} 数据不存在");
            }
            var catalogList = new Yw.Service.SysCatalog().GetChildAndSelfByCode(IStation.Catalog.PressMeter);
            if (catalogList == null || catalogList.Count < 1)
            {
                throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, "压力计分类编码验证失败");
            }
            var catalogIds = catalogList.Select(x => x.ID).Distinct().ToList();
            if (!catalogIds.Contains(equipment.CatalogID))
            {
                throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"PressMeterID:{input.PressMeterID} 请输入正确压力计id");
            }
 
            var vm = new PressMeterMapMonitorKpiInfoMobileDto();
            vm.PressMeterID = input.PressMeterID;
            vm.Name = equipment.Name;
            vm.LastRecordList = new List<PressMeterMapMonitorKpiLastRecordMobileDto>();
 
            var service_monitor_mapping = new Yw.Service.EquipmentMonitorMapping();
            var mappingList = new Yw.Service.EquipmentMonitorMapping().GetByEquipmentID(input.PressMeterID);
            if (mappingList != null && mappingList.Count > 0)
            {
                var monitorIds = mappingList.Select(x => x.MonitorPointID).Distinct().ToList();
                var monitorList = new Yw.Service.MonitorPoint().GetExSignalWithSignalTypeByIds(monitorIds);
                monitorList = monitorList?.Where(x => x.UseStatus == Yw.Model.eUseStatus.Enable).ToList();
                monitorList = monitorList?.Where(x => x.CronType == Yw.Monitor.eCronType.Real).ToList();
                if (monitorList != null && monitorList.Count > 0)
                {
                    var service_monitor_record = new Lazy<Yw.Service.MonitorRealRecord>(() => new Yw.Service.MonitorRealRecord());
                    var monitorPr = monitorList.Find(x => x.Flags.Contains(IStation.Flags.默认) && x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.压力));
                    if (monitorPr == null)
                    {
                        monitorPr = monitorList.Find(x => x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.压力));
                    }
                    if (monitorPr != null)
                    {
                        var signalPr = monitorPr.SignalList.First();
                        var last_record = service_monitor_record.Value.GetLastRecord(signalPr.ID);
                        if (last_record != null)
                        {
                            vm.LastRecordList.Add(new PressMeterMapMonitorKpiLastRecordMobileDto(monitorPr, last_record));
                        }
                    }
 
                }
            }
 
            return vm;
 
        }
 
        /// <summary>
        /// 获取工单列表
        /// </summary>
        [Route("GetRepairList@V1.0")]
        [HttpGet]
        public List<RepairMapMobileDto> GetRepairList()
        {
            var vmList = new List<RepairMapMobileDto>();
            var requestList = new Yw.Service.RepairRequestForm().GetPendingList();
            if (requestList != null && requestList.Count > 0)
            {
                foreach (var request in requestList)
                {
                    var vmRequest = new RepairMapMobileDto(request, Yw.Map.Kind.Gaodei);
                    vmList.Add(vmRequest);
                }
            }
            var taskList = new Yw.Service.RepairTaskForm().GetUnCheckedList();
            if (taskList != null && taskList.Count > 0)
            {
                foreach (var task in taskList)
                {
                    var vmTask = new RepairMapMobileDto(task, Yw.Map.Kind.Gaodei);
                    vmList.Add(vmTask);
                }
            }
            return vmList;
        }
 
        /// <summary>
        /// 获取工单状态信息
        /// </summary>
        [Route("GetRepairStatusInfo@V1.0")]
        [HttpGet]
        public RepairMapStatusMobileDto GetRepairStatusInfo
            (
                [Required]
                string FormType,
                [Required]
                long FormID
            )
        {
            if (FormType == Yw.Repair.DataType.RepairRequestForm)
            {
                var request = new Yw.Service.RepairRequestForm().GetByID(FormID);
                if (request == null)
                {
                    throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"FormID:{FormID} 数据不存在");
                }
                return new RepairMapStatusMobileDto(request);
            }
            else if (FormType == Yw.Repair.DataType.RepairTaskForm)
            {
                var task = new Yw.Service.RepairTaskForm().GetByID(FormID);
                if (task == null)
                {
                    throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"FormID:{FormID} 数据不存在");
                }
                return new RepairMapStatusMobileDto(task);
            }
 
            throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"FormType 参数错误");
 
        }
 
        /// <summary>
        /// 获取Dma分区列表
        /// </summary>
        [Route("GetDmaAreaList@V1.0")]
        [HttpGet]
        public List<DmaAreaMapMobileDto> GetDmaAreaList()
        {
            var keyContent = $"SZJT_Map_Mobile_GetDmaAreaList";
            var cacheKey = MemoryCacheKeyHelper.GetKey(MemoryCacheKey.WebApiLevel, MemoryCacheKey.Module, keyContent);
 
            var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
                var allAreaList = new Yw.Service.DmaArea().GetByBelongTypeAndBelongID(IStation.DataType.LogicDma, 1);
                Yw.Service.DmaArea.PublishCache(cacheKey);
                if (allAreaList == null || allAreaList.Count < 1)
                {
                    return default;
                }
 
                var serviceMapInfo = new Yw.Service.MapInfo();
 
                var vm_list = new List<DmaAreaMapMobileDto>();
                foreach (var area in allAreaList)
                {
                    var vm = new DmaAreaMapMobileDto(area);
                    vm_list.Add(vm);
 
                    var area_map_info = serviceMapInfo.Get(Yw.DMA.DataType.DmaArea, area.ID, Yw.Map.Kind.Gaodei, Yw.Map.Purpose.Location);
                    if (area_map_info != null)
                    {
                        vm.Position = Yw.Model.Map.Polygon.ToModel(area_map_info.Position);
                    }
                }
 
                return vm_list;
            }, Yw.Service.ConfigHelper.CacheLevel3);
            return vm_list;
        }
 
 
    }
}