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
namespace IStation.Application
{
    /// <summary>
    /// PressMeterMap
    /// </summary>
    [Route("SZJT/Press/Meter/Map/Logic")]
    [ApiDescriptionSettings("SZJT", Name = "压力计地图(Logic)", Order = 3000)]
    public class PressMeterMap_LogicController : IDynamicApiController
    {
 
        /// <summary>
        /// 获取监测Kpi列表
        /// </summary>
        [Route("GetMonitorKpiList@V1.0")]
        [HttpGet]
        public List<PressMeterMapMonitorKpiInfoDto> GetMonitorKpiList([FromQuery][Required] BelongInput input)
        {
            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();
 
            var allMeterList = new Yw.Service.Equipment().GetByBelongTypeAndBelongID(input.BelongType, input.BelongID);
            allMeterList = allMeterList?.Where(x => catalogIds.Contains(x.CatalogID)).ToList();
            if (allMeterList == null || allMeterList.Count < 1)
            {
                return default;
            }
 
 
            var service_monitor_mapping = new Yw.Service.EquipmentMonitorMapping();
            var service_monitor = new Lazy<Yw.Service.MonitorPoint>(() => new Yw.Service.MonitorPoint());
            var service_monitor_record = new Lazy<Yw.Service.MonitorRealRecord>(() => new Yw.Service.MonitorRealRecord());
            var service_map = new Lazy<Yw.Service.MapInfo>(() => new Yw.Service.MapInfo());
 
            var vmList = new List<PressMeterMapMonitorKpiInfoDto>();
            foreach (var meter in allMeterList)
            {
                var vm = new PressMeterMapMonitorKpiInfoDto(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);
                }
 
                var monitor_mapping_list = service_monitor_mapping.GetByEquipmentID(meter.ID);
                if (monitor_mapping_list != null && monitor_mapping_list.Count > 0)
                {
                    var monitorIds = monitor_mapping_list.Select(x => x.MonitorPointID).Distinct().ToList();
                    var monitor_list = service_monitor.Value.GetExSignalWithSignalTypeByIds(monitorIds);
                    monitor_list = monitor_list?.Where(x => x.UseStatus == Yw.Model.eUseStatus.Enable).ToList();
                    monitor_list = monitor_list?.Where(x => x.CronType == Yw.Monitor.eCronType.Real).ToList();
                    if (monitor_list != null && monitor_list.Count > 0)
                    {
                        var monitorPr = monitor_list.Find(x => x.Flags.Contains(IStation.Flags.默认) && x.SignalList.Exists(t => t.SignalType.Code == Yw.Monitor.SignalType.压力));
                        if (monitorPr == null)
                        {
                            monitorPr = monitor_list.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 PressMeterMapMonitorKpiLastRecordDto(monitorPr, last_record));
                            }
                        }
                    }
                }
 
            }
 
            return vmList;
 
        }
 
 
 
 
 
 
 
 
 
 
    }
}