ningshuxia
2022-10-21 389d30bbdb7a43e46da71ce6fd7f12dba84014fe
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
using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Net.Http.Headers;
using Microsoft.Extensions.Hosting.Internal;
using Microsoft.AspNetCore.Http.Extensions;
using IStation.Untity;
using Furion.DynamicApiController;
using System.ComponentModel.DataAnnotations;
using Mapster;
using Microsoft.AspNetCore.Http;
using Furion.DependencyInjection;
using Microsoft.AspNetCore.Authorization;
using Furion.DataEncryption;
using AutoMapper;
using System.Text;
 
namespace IStation.Application
{
    /// <summary>
    /// 波形存储接口(城投的恩普特 市南泵站专用)
    /// </summary>
    [AllowAnonymous]
    [Route("smi/vibration/zept")]
    [ApiDescriptionSettings("Vibration", Name = "城投恩普特振动", Order = 1100)]
    public class Smi_Zept_VibrationController : IDynamicApiController
    {
 
 
        /// <summary>
        /// 单个添加 
        /// </summary>
        [Route("SingleInsert")]
        public bool SingleInsert([Required]AddSmiExpertVibrationRecordInput input)
        {
            //转化为内部使用对象
            var model = input.Adapt<AddSmiExpertVibrationRecordInput, Model.SmiExpertVibrationRecord>();
 
            //写redis缓存
            var redisHelper = new RedisCache.SmiExpertVibrationRecord();
            redisHelper.SetLastRecord(model);
 
            if (ConfigHelper.Smi_Expert_IsWriteLog)
            {
                LogHelper.Info($"恩普特写入Redis一条振动数据,ObjectId:{model.ObjectId}");
            }
 
            //获取配置
            var configure = new Service.DataDockingConfigure().GetByID(ConfigHelper.Smi_Expert_CorpID, ConfigHelper.Smi_Expert_ConfigureID);
            if (configure != null)
            {
                if (configure.Mappers != null && configure.Mappers.Count > 0)
                {
                    var mapper = configure.Mappers.Find(t => t.SignId == model.ObjectId);
                    if (mapper != null)
                    {
                        var monitor = new Service.MonitorPoint().GetExSignalWithSignalTypeByID(configure.CorpID, mapper.SysId);
                        if (monitor != null)
                        {
                            if (monitor.MonitorType == Model.eMonitorType.Vibration)
                            {
                                var receive = new Model.MonitorDataDockingReceiveRecord();
                                receive.SysId = monitor.ID;
                                receive.RecordType = monitor.MonitorType;
                                receive.SrcTime = model.SrcTime;
                                receive.DataStatus = model.DataStatus;
 
                                //子项列表
                                var receiveSubList = new List<Model.MonitorDataDockingReceiveSubRecord>();
 
                                //配置
                                var signal_config = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.配置));
                                if (signal_config != null)
                                {
                                    var config = model.Adapt<Model.SmiExpertVibrationRecord, Model.SmiExpertVibrationConfig>();
                                    var config_json = JsonHelper.Object2Json(config);
                                    var config_sub = new Model.MonitorDataDockingReceiveSubRecord();
                                    config_sub.SysId = signal_config.ID;
                                    config_sub.SrcValue = config_json;
                                    receiveSubList.Add(config_sub);
                                }
 
                                //转速
                                var signal_rpm = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.转速));
                                if (signal_rpm != null)
                                {
                                    var rpm_sub = new Model.MonitorDataDockingReceiveSubRecord();
                                    rpm_sub.SysId = signal_rpm.ID;
                                    rpm_sub.SrcValue = model.Rpm.ToString();
                                    receiveSubList.Add(rpm_sub);
                                }
 
                                //直流量
                                var signal_ic = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.直流量));
                                if (signal_ic != null)
                                {
                                    var ic_sub = new Model.MonitorDataDockingReceiveSubRecord();
                                    ic_sub.SysId = signal_ic.ID;
                                    ic_sub.SrcValue = model.DcValue.ToString();
                                    receiveSubList.Add(ic_sub);
                                }
 
                                //频率
                                var signal_hz = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.频率));
                                if (signal_hz != null)
                                {
                                    var hz_sub = new Model.MonitorDataDockingReceiveSubRecord();
                                    hz_sub.SysId = signal_hz.ID;
                                    hz_sub.SrcValue = model.Frequency.ToString();
                                    receiveSubList.Add(hz_sub);
                                }
 
                                //波形
                                var signal_wave = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.波形));
                                if (signal_wave != null)
                                {
                                    var wave_sub = new Model.MonitorDataDockingReceiveSubRecord();
                                    wave_sub.SysId = signal_wave.ID;
                                    wave_sub.SrcValue = model.Wave;
                                    receiveSubList.Add(wave_sub);
                                }
 
                                receive.SrcValue = Model.MonitorDataDockingReceiveSubRecord.ToJson(receiveSubList);
 
                                var queueHelper = new RabbitMqQueueHelper();
                                var bol = queueHelper.Push(ConfigHelper.DataDockingQueueName, new Model.MonitorDataDockingCorpRecord()
                                {
                                    CorpID = configure.CorpID,
                                    ConfigureID = configure.ID,
                                    Records = new List<Model.MonitorDataDockingReceiveRecord>() { receive }
                                });
                                if (bol)
                                {
                                    if (ConfigHelper.Smi_Expert_IsWriteLog)
                                    {
                                        LogHelper.Info($"恩普特推入通道一条振动数据,ObjectId:{model.ObjectId},SysId:{monitor.ID}");
                                    }
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
            return false;
        }
 
        /// <summary>
        /// 批量添加
        /// </summary>
        [Route("BulkInsert")]
        public bool BulkInsert([Required]List<AddSmiExpertVibrationRecordInput> inputList)
        {
            if (inputList == null || inputList.Count < 1)
                return false;
            //转化为内部使用对象
            var modelList = inputList.Select(x => x.Adapt<AddSmiExpertVibrationRecordInput, Model.SmiExpertVibrationRecord>()).ToList();
 
            //写redis缓存
            var redisHelper = new RedisCache.SmiExpertVibrationRecord();
            redisHelper.SetLastRecord(modelList);
 
            if (ConfigHelper.Smi_HangTian_IsWriteLog)
            {
                LogHelper.Info($"恩普特写入Redis {modelList.Count} 条振动数据");
            }
 
            //获取配置
            var configure = new Service.DataDockingConfigure().GetByID(ConfigHelper.Smi_Expert_CorpID, ConfigHelper.Smi_Expert_ConfigureID);
            if (configure != null)
            {
                if (configure.Mappers != null && configure.Mappers.Count > 0)
                {
                    var receiveList = new List<Model.MonitorDataDockingReceiveRecord>();
                    foreach (var model in modelList)
                    {
                        var mapper = configure.Mappers.Find(t => t.SignId == model.ObjectId);
                        if (mapper != null)
                        {
                            var monitor = new Service.MonitorPoint().GetExSignalWithSignalTypeByID(configure.CorpID, mapper.SysId);
                            if (monitor != null)
                            {
                                if (monitor.MonitorType == Model.eMonitorType.Vibration)
                                {
                                    var receive = new Model.MonitorDataDockingReceiveRecord();
                                    receive.SysId = monitor.ID;
                                    receive.RecordType = monitor.MonitorType;
                                    receive.SrcTime = model.SrcTime;
                                    receive.DataStatus = model.DataStatus;
 
                                    //子项列表
                                    var receiveSubList = new List<Model.MonitorDataDockingReceiveSubRecord>();
 
                                    //配置
                                    var signal_config = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.配置));
                                    if (signal_config != null)
                                    {
                                        var config = model.Adapt<Model.SmiExpertVibrationRecord, Model.SmiExpertVibrationConfig>();
                                        var config_json = JsonHelper.Object2Json(config);
                                        var config_sub = new Model.MonitorDataDockingReceiveSubRecord();
                                        config_sub.SysId = signal_config.ID;
                                        config_sub.SrcValue = config_json;
                                        receiveSubList.Add(config_sub);
                                    }
 
                                    //转速
                                    var signal_rpm = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.转速));
                                    if (signal_rpm != null)
                                    {
                                        var rpm_sub = new Model.MonitorDataDockingReceiveSubRecord();
                                        rpm_sub.SysId = signal_rpm.ID;
                                        rpm_sub.SrcValue = model.Rpm.ToString();
                                        receiveSubList.Add(rpm_sub);
                                    }
 
                                    //直流量
                                    var signal_ic = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.直流量));
                                    if (signal_ic != null)
                                    {
                                        var ic_sub = new Model.MonitorDataDockingReceiveSubRecord();
                                        ic_sub.SysId = signal_ic.ID;
                                        ic_sub.SrcValue = model.DcValue.ToString();
                                        receiveSubList.Add(ic_sub);
                                    }
 
                                    //频率
                                    var signal_hz = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.频率));
                                    if (signal_hz != null)
                                    {
                                        var hz_sub = new Model.MonitorDataDockingReceiveSubRecord();
                                        hz_sub.SysId = signal_hz.ID;
                                        hz_sub.SrcValue = model.Frequency.ToString();
                                        receiveSubList.Add(hz_sub);
                                    }
 
                                    //波形
                                    var signal_wave = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.波形));
                                    if (signal_wave != null)
                                    {
                                        var wave_sub = new Model.MonitorDataDockingReceiveSubRecord();
                                        wave_sub.SysId = signal_wave.ID;
                                        wave_sub.SrcValue = model.Wave;
                                        receiveSubList.Add(wave_sub);
                                    }
 
                                    receive.SrcValue = Model.MonitorDataDockingReceiveSubRecord.ToJson(receiveSubList);
                                    receiveList.Add(receive);
                                }
                            }
                        }
                    }
                    if (receiveList.Count > 0)
                    {
                        var queueHelper = new RabbitMqQueueHelper();
                        var bol = queueHelper.Push(ConfigHelper.DataDockingQueueName, new Model.MonitorDataDockingCorpRecord()
                        {
                            CorpID = configure.CorpID,
                            ConfigureID = configure.ID,
                            Records = receiveList
                        });
                        if (bol)
                        {
                            if (ConfigHelper.Smi_Expert_IsWriteLog)
                            {
                                LogHelper.Info($"恩普特推入通道 {receiveList.Count} 条振动数据");
                            }
                            return true;
                        }
                    }
                }
            }
 
            return false;
        }
 
        /// <summary>
        /// 通过 ObjectId 查询最近(已过时)
        /// </summary>
        [Route("QueryLastRecordByObjectId")]
        [HttpGet]
        public List<SmiExpertVibrationRecordDto> QueryLastRecordByObjectId(string ProductId, string ObjectId)
        {
            if (string.IsNullOrEmpty(ObjectId))
            {
                return default;
            }
            var objectIds = ObjectId.Split(',');
            if (objectIds == null || objectIds.Count() < 1)
            {
                return default;
            }
            var redisHelper = new RedisCache.SmiExpertVibrationRecord();
            var modelList = redisHelper.GetLastRecord(objectIds);
            if (ConfigHelper.Smi_Expert_IsWriteLog)
            {
                LogHelper.Info($"恩普特通过ObjectId: {ObjectId} 获取 {(modelList == null ? 0 : modelList.Count)} 条");
            }
            var dtoList = modelList?.Select(x => x.Adapt<Model.SmiExpertVibrationRecord, SmiExpertVibrationRecordDto>()).ToList();
            return dtoList;
        }
 
        /// <summary>
        /// 通过 ProductId 查询最近
        /// </summary>
        [Route("QueryLastRecordByProductId")]
        [HttpGet]
        public List<SmiExpertVibrationRecordDto> QueryLastRecordByProductId(string ProductId)
        {
            if (string.IsNullOrEmpty(ProductId))
            {
                return default;
            }
 
            var redisHelper = new RedisCache.SmiExpertVibrationRecord();
            var modelList = redisHelper.GetLastRecordStartWith(ProductId);
            if (ConfigHelper.Smi_Expert_IsWriteLog)
            {
                LogHelper.Info($"恩普特通过ProductId: {ProductId} 获取 {(modelList == null ? 0 : modelList.Count)} 条");
            }
            var dtoList = modelList?.Select(x => x.Adapt<Model.SmiExpertVibrationRecord, SmiExpertVibrationRecordDto>()).ToList();
            return dtoList;
        }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    }
}