tangxu
2024-02-27 707a73304e0406b865548645c7cd1880a3651cc4
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.BLL
{
    /// <summary>
    /// 监测数据集
    /// </summary>
    public class MonitorDataSet
    {
        private readonly DAL.MonitorDataSet _dal = new DAL.MonitorDataSet();
 
        #region Query
 
        #region MonitorDataSet
 
        /// <summary>
        /// 查询监测数据集
        /// </summary> 
        public List<Model.MonitorDataSet> GetMonitorDataSet()
        {
            return _dal.GetMonitorDataSet();
        }
 
        /// <summary>
        ///  查询监测数据集
        /// </summary>
        public List<Model.MonitorDataSet> GetMonitorDataSet(long monitorPointId)
        {
            if (monitorPointId < 1)
                return default;
            return _dal.GetMonitorDataSet(monitorPointId);
        }
 
        /// <summary>
        ///  查询监测数据集
        /// </summary>
        public Model.MonitorDataSet GetMonitorDataSet(long monitorPointId, int year, int month)
        {
            if (monitorPointId < 1)
                return default;
            return _dal.GetMonitorDataSet(monitorPointId, year, month);
        }
 
        #endregion
 
        #region SignalRecordPacket
 
        /// <summary>
        ///  查询信号记录包
        /// </summary>
        public List<Model.SignalRecordPacket> GetSignalRecordPacket(List<long> signalIds, int year, int month)
        {
            if (signalIds == null || !signalIds.Any())
                return default;
            return _dal.GetSignalRecordPacket(signalIds, year, month);
        }
 
        /// <summary>
        ///  查询信号记录包
        /// </summary>
        public Model.SignalRecordPacket GetSignalRecordPacket(long monitorPointId, long signalId)
        {
            if (monitorPointId < 1)
                return default;
            if (signalId < 1)
                return default;
 
            return _dal.GetSignalRecordPacket(monitorPointId, signalId);
        }
 
        /// <summary>
        ///  查询信号记录包
        /// </summary>
        public Model.SignalRecordPacket GetSignalRecordPacket(long monitorPointId, long signalId, int year, int month)
        {
            if (monitorPointId < 1)
                return default;
            if (signalId < 1)
                return default;
 
            return _dal.GetSignalRecordPacket(monitorPointId, signalId, year, month);
        }
 
        #endregion
 
        #region SignalRecord
 
        /// <summary>
        ///  查询信号记录
        /// </summary>
        public List<Model.SignalRecord> GetSignalRecord(long monitorPointId, long signalId, int year, int month)
        {
            if (monitorPointId < 1)
                return default;
            if (signalId < 1)
                return default;
 
            return _dal.GetSignalRecord(monitorPointId, signalId, year, month);
        }
 
        #endregion
 
        #endregion
 
        #region Save
 
        /// <summary>
        /// 保存
        /// </summary>
        public bool Save(IEnumerable<Model.MonitorDataSet> list)
        {
            if (list == null || list.Count() < 1)
                return default;
            return _dal.Save(list);
        }
 
        /// <summary>
        /// 保存
        /// </summary>
        public bool Save(Model.MonitorDataSet rhs)
        {
            if (rhs == null)
                return default;
            if (rhs.PacketList == null || rhs.PacketList.Count < 1)
                return default;
            return _dal.Save(rhs);
        }
 
        /// <summary>
        /// 保存
        /// </summary>
        public bool Save(long monitorPointId, long signalId, List<Model.SignalRecord> signalRecords, int year, int month)
        {
            if (monitorPointId < 1)
                return default;
            if (signalId < 1)
                return default;
            if (signalRecords == null || signalRecords.Count < 1)
                return default;
 
            return _dal.Save(monitorPointId, signalId, signalRecords, year, month);
        }
        #endregion
 
        /// <summary>
        /// 删除(临时)
        /// </summary>
        public bool SetAbnormal(long monitorPointId, long signalId, IEnumerable<DateTime> dataTimeList, double err)
        {
            if (dataTimeList == null || dataTimeList.Count() < 1)
                return false;
            var dataSet = _dal.GetMonitorDataSet(monitorPointId);
            if (dataSet == null || dataSet.Count < 1)
                return false;
            foreach (var data in dataSet)
            {
                var packet = data.PacketList?.Find(x => x.SignalID == signalId);
                if (packet != null && packet.RecordList != null)
                    for (int i = 0; i < packet.RecordList.Count; i++)
                    {
                        var record = packet.RecordList[i];
                        if (dataTimeList.Contains(record.Time))
                        {
                            packet.RecordList[i] = new Model.SignalRecord(record.Time, err);
                        }
                    }
            }
            return _dal.Save(dataSet);
        }
 
    }
}