tangxu
2024-01-09 ddc2780231ea76be74fadb7486401a3d0d17b101
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
namespace Yw.Application
{
    /// <summary>
    /// HealthQuotaEvaluationHandOnline
    /// </summary>
    [Route("Health/Quota/Evaluation/Online/Logic")]
    [ApiDescriptionSettings("Health", Name = "指标在线评价(业务)", Order = 900)]
    public class HealthQuotaEvaluationHandOnline_LogicController : IDynamicApiController
    {
 
        /// <summary>
        /// 通过 EquipmentID 获取
        /// </summary>
        [Route("GetByEquipmentID@V1.0")]
        [HttpGet]
        public List<MonitorPointOnlineLogicDto> GetByEquipmentID([FromQuery][Required] EquipmentIDInput input)
        {
            var equipmentId = input.EquipmentID;
 
            #region 获取所有设备
 
            var serviceEquipment = new Service.Equipment();
            var allEquipmentList = serviceEquipment.GetChildAndSelfByID(equipmentId);
            if (allEquipmentList == null || allEquipmentList.Count < 1)
            {
                throw Oops.Oh(ErrorCodes.D001, $"EquipmentID:{equipmentId}");
            }
 
            #endregion
 
            #region 获取设备测点映射
 
            var allEquipmentIds = allEquipmentList.Select(x => x.ID).Distinct().ToList();
            var serviceMonitorMapping = new Service.EquipmentMonitorMapping();
            var allMonitorMappingList = serviceMonitorMapping.GetByEquipmentIds(allEquipmentIds);
            if (allMonitorMappingList == null || allMonitorMappingList.Count < 1)
            {
                return default;
            }
 
            #endregion
 
            #region 获取所有测点
 
            var allMonitorIds = allMonitorMappingList.Select(x => x.MonitorPointID).Distinct().ToList();
            var serviceMonitor = new Service.MonitorPoint();
            var allMonitorList = serviceMonitor.GetExSignalWithSignalTypeByIds(allMonitorIds);
            if (allMonitorList == null || allMonitorList.Count < 1)
            {
                return default;
            }
 
            #endregion
 
            #region 获取所有测点组
 
            var allGroupIds = allMonitorList.Select(x => x.GroupID).Distinct().ToList();
            var serviceMonitorGroup = new Service.MonitorPointGroup();
            var allGroupList = serviceMonitorGroup.GetByIds(allGroupIds);
            if (allGroupList == null || allGroupList.Count < 1)
            {
                return default;
            }
 
            #endregion
 
            #region 获取所有绑定
 
            var allSignalIds = allMonitorList.SelectMany(x => x.SignalList.Select(t => t.ID)).ToList();
            var allBindingList = new Service.HealthQuotaEvaluationModelBinding().GetValidBySignalIds(allSignalIds);
            if (allBindingList == null || allBindingList.Count < 1)
            {
                return default;
            }
 
            #endregion
 
            #region 获取所有绑定模型
 
            var allModelIds = allBindingList.Select(x => x.ModelID).Distinct().ToList();
            var allModelList = new Yw.Service.HealthQuotaEvaluationModel().GetByIds(allModelIds);
            if (allModelList == null || allModelList.Count < 1)
            {
                return default;
            }
 
            #endregion
 
            #region 遍历构造
 
            var serviceMonitorRecord = new Lazy<Service.MonitorRecord>(() => new Service.MonitorRecord());
            var serviceEvaluateRecord = new Lazy<Service.HealthQuotaEvaluationRecord>(() => new Service.HealthQuotaEvaluationRecord());
            var vmList = new List<MonitorPointOnlineLogicDto>();
            foreach (var group in allGroupList)
            {
                var monitorList = allMonitorList.Where(x => x.GroupID == group.ID).OrderBy(x => x.SortCode).ToList();
                if (monitorList == null || monitorList.Count < 1)
                    continue;
                foreach (var monitor in monitorList)
                {
                    var vm = new MonitorPointOnlineLogicDto(monitor);
                    foreach (var signal in monitor.SignalList)
                    {
                        var binding = allBindingList.Find(x => x.SignalID == signal.ID);
                        if (binding != null)
                        {
                            var model = allModelList.Find(x => x.ID == binding.ModelID);
                            if (model != null)
                            {
                                if (model.Way == eEvaluateWay.Hand)
                                {
                                    var lastRecord = serviceMonitorRecord.Value.GetLastRecord(signal.ID);
                                    if (lastRecord != null)
                                    {
                                        var lastEvaluateRecord = serviceEvaluateRecord.Value.GetLastRecord(signal.ID);
                                        var vmSignal = new SignalOnlineLogicDto(signal, lastRecord, model, lastEvaluateRecord);
                                        vm.SignalList.Add(vmSignal);
                                    }
                                }
                            }
                        }
                    }
                    if (vm.SignalList.Count > 0)
                    {
                        vmList.Add(vm);
                    }
                }
            }
 
            return vmList;
            #endregion
 
 
 
 
        }
 
 
 
 
 
 
 
 
    }
}