lixiaojun
2024-11-19 a5b6334ae09f2be1a5c073169458b55df68b0b2e
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
namespace IStation.Application
{
    /// <summary>
    /// StationPanel
    /// </summary>
    [Route("SZJT/Station/Panel/Logic")]
    [ApiDescriptionSettings("SZJT", Name = "泵站面板(Logic)", Order = 8000)]
    public class StationPanel_LogicController : IDynamicApiController
    {
 
        /// <summary>
        /// 获取监测KPI列表
        /// </summary>
        [Route("GetMonitorKpiList@V1.0")]
        [HttpGet]
        public List<StationPanelMonitorKpiInfoDto> GetMonitorKpiList(int Count = 4)
        {
            #region 服务准备
 
            var service_logic_site = new Lazy<Yw.Service.LogicSite>(() => new Yw.Service.LogicSite());
            var service_equipment_group = new Lazy<Yw.Service.EquipmentGroup>(() => new Yw.Service.EquipmentGroup());
            var service_equipment = new Lazy<Yw.Service.Equipment>(() => new Yw.Service.Equipment());
            var service_monitor_group = new Lazy<Yw.Service.MonitorPointGroup>(() => new Yw.Service.MonitorPointGroup());
            var service_monitor = new Lazy<Yw.Service.MonitorPoint>(() => new Yw.Service.MonitorPoint());
            var service_signal = new Lazy<Yw.Service.Signal>(() => new Yw.Service.Signal());
            var service_monitor_record = new Lazy<Yw.Service.MonitorRealRecord>(() => new Yw.Service.MonitorRealRecord());
            var service_run_record = new Lazy<Yw.Service.RunRealRecord>(() => new Yw.Service.RunRealRecord());
 
            #endregion
 
            #region 获取所有泵站
 
            var allStationList = service_logic_site.Value.GetAll();
            if (allStationList == null || allStationList.Count < 1)
            {
                return default;
            }
 
            #endregion
 
            var vmList = new List<StationPanelMonitorKpiInfoDto>();
            foreach (var station in allStationList)
            {
                var vm = new StationPanelMonitorKpiInfoDto(station);
                vmList.Add(vm);
 
                var monitorList = service_monitor.Value.GetExSignalWithSignalTypeByBelongTypeAndBelongID(IStation.DataType.LogicSite, station.ID, Yw.Monitor.eCronType.Real);
                monitorList = monitorList?.Where(x => x.UseStatus == Yw.Model.eUseStatus.Enable).ToList();
                if (monitorList != null && monitorList.Count > 0)
                {
                    monitorList = monitorList.Where(x => x.Flags.Contains(Flags.KPI)).OrderByDescending(X => X.Importance).ToList();
                    if (monitorList.Count > 0)
                    {
                        monitorList = monitorList.Take(Count).ToList();
                        foreach (var monitor in monitorList)
                        {
                            var monitorRecord = service_monitor_record.Value.GetLastRecord(monitor.SignalList.First().ID);
                            vm.LastRecordList.Add(new StationPanelMonitorKpiLastRecordDto(monitor, monitorRecord));
                        }
                    }
                }
 
                var equipmentGroupList = service_equipment_group.Value.GetByBelongTypeAndBelongID(IStation.DataType.LogicSite, station.ID);
                if (equipmentGroupList != null && equipmentGroupList.Count > 0)
                {
                    var equipmentGroup = equipmentGroupList.Find(x => x.Flags.Contains(IStation.Flags.机组));
                    if (equipmentGroup != null)
                    {
                        var equipmentList = service_equipment.Value.GetByGroupID(equipmentGroup.ID);
                        equipmentList = equipmentList?.Where(x => x.ParentIds.Count < 1).ToList();
                        if (equipmentList != null && equipmentList.Count > 0)
                        {
                            foreach (var equipment in equipmentList)
                            {
                                var runRecord = service_run_record.Value.GetLastRecord(Yw.Assets.DataType.Equipment, equipment.ID);
                                vm.LastStatusList.Add(new StationPanelMonitorKpiLastStatusDto(equipment, runRecord));
                            }
                        }
                    }
                }
            }
            return vmList;
        }
 
 
 
 
 
 
 
 
    }
}