lixiaojun
2022-12-01 160e45913a82ecdb40ab43f99fc8ae868fcd6b0e
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
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;
using IStation.Calculation;
 
namespace IStation.Application
{
    /// <summary>
    /// 标准数据对接
    /// </summary>
    [AllowAnonymous]
    [Route("Run/DataDocking/Standard")]
    [ApiDescriptionSettings("Run", Name = "标准数据对接", Order = 1100)]
    public class DataDocking_StandardController : IDynamicApiController
    {
        //配置列表
        private static List<Model.DataDockingConfigureExStandard> _standardConfigureList = null;
 
        /// <summary>
        /// 插入
        /// </summary>
        [Route("Insert@V1.0")]
        [HttpPost]
        public bool Insert([Required] DataDockingStandardInput input)
        {
            LogHelper.Info($"数据标准对接接口中,注册码:{input.RegisterCode},插入数据记录数量:{input.Records.Count}.");
 
            var corpIds = DataDockingCorpHelper.GetCorpIds();
            if (corpIds == null || corpIds.Count < 1)
            {
                throw new Exception("未检索到客户标识配置信息!");
            }
            if (_standardConfigureList == null)
            {
                var configureList = new Service.DataDockingConfigure().GetByCorpIds(corpIds);
                if (configureList == null || configureList.Count < 1)
                {
                    throw new Exception("未检索到数据对接配置信息!");
                }
                configureList = configureList.Where(x => x.DockingMode == Model.DataDockingConfigure.eDockingMode.Standard).ToList();
                if (configureList == null || configureList.Count < 1)
                {
                    throw new Exception("未检索到数据对接标准配置信息!");
                }
                _standardConfigureList = configureList.Select(x => new Model.DataDockingConfigureExStandard(x)).ToList();
            }
            var standardConfigure = _standardConfigureList.Find(x => x.ConfigureParas != null && x.ConfigureParas.RegisterCode == input.RegisterCode);
            if (standardConfigure == null)
            {
                throw new Exception("未检索到数据对接标准配置信息!");
            }
            if (standardConfigure.Mappers == null || standardConfigure.Mappers.Count < 1)
            {
                throw new Exception("数据对接标准配置信息中,未配置有效映射关系!");
            } 
 
            var records = new List<Model.MonitorDataDockingReceiveRecord>();
            var inputRecords = input.Records.OrderByDescending(x=>x.RecordTime).ToList();
            foreach (var mapper in standardConfigure.Mappers)
            {
                var inputRecord = inputRecords.Find(x => x.RecordId == mapper.SignId);
                if (inputRecord != null)
                {
                    var record = new Model.MonitorDataDockingReceiveRecord
                    {
                        SysId = mapper.SysId,
                        RecordType = inputRecord.RecordType,
                        SrcTime = inputRecord.RecordTime,
                        SrcValue = inputRecord.RecordValue,
                        DataStatus = new List<string>()
                    };
                    records.Add(record);
                }
            }
 
            if (records.Count < 1)
            {
                throw new Exception("未接收到有效数据记录!");
            }
 
            var queueHelper = new RabbitMqQueueHelper();
            var bol = queueHelper.Push(Settings.Queue.DataDockingQueueName, new Model.MonitorDataDockingCorpRecord()
            {
                CorpID = standardConfigure.CorpID,
                ConfigureID = standardConfigure.ID,
                Records = records
            });
            if (bol)
            {
                LogHelper.Info($"数据标准对接接口中,客户:{standardConfigure.CorpID},标准数据对接配置:{standardConfigure.ID},推入通道记录数量:{records.Count}.");
                return true;
            }
            return false;
        }
 
        /// <summary>
        /// 补录
        /// </summary>
        [Route("Supplement@V1.0")]
        [HttpPost]
        public bool Supplement([Required] DataDockingStandardInput input)
        {
            LogHelper.Info($"数据标准对接接口中,注册码:{input.RegisterCode},补录数据记录数量:{input.Records.Count}.");
 
            var corpIds = DataDockingCorpHelper.GetCorpIds();
            if (corpIds == null || corpIds.Count < 1)
            {
                throw new Exception("未检索到客户标识配置信息!");
            }
            if (_standardConfigureList == null)
            {
                var configureList = new Service.DataDockingConfigure().GetByCorpIds(corpIds);
                if (configureList == null || configureList.Count < 1)
                {
                    throw new Exception("未检索到数据对接配置信息!");
                }
                configureList = configureList.Where(x => x.DockingMode == Model.DataDockingConfigure.eDockingMode.Standard).ToList();
                if (configureList == null || configureList.Count < 1)
                {
                    throw new Exception("未检索到数据对接标准配置信息!");
                }
                _standardConfigureList = configureList.Select(x => new Model.DataDockingConfigureExStandard(x)).ToList();
            }
            var standardConfigure = _standardConfigureList.Find(x => x.ConfigureParas != null && x.ConfigureParas.RegisterCode == input.RegisterCode);
            if (standardConfigure == null)
            {
                throw new Exception("未检索到数据对接标准配置信息!");
            }
            if (standardConfigure.Mappers == null || standardConfigure.Mappers.Count < 1)
            {
                throw new Exception("数据对接标准配置信息中,未配置有效映射关系!");
            }
 
            //生成记录
            var recordList = new List<Model.MonitorBasicRecord>();
            foreach (var mapper in standardConfigure.Mappers)
            {
                var inputRecordList = input.Records.Where(t => t.RecordId == mapper.SignId).ToList();
                if (inputRecordList != null && inputRecordList.Count > 0)
                {
                    var inputGroupList = inputRecordList.GroupBy(x => new { x.RecordId, x.RecordTime }).ToList();
                    foreach (var inputGroup in inputGroupList)
                    {
                        var inputFirstRecord = inputGroup.First();
                        var monitor = new Service.MonitorPoint().GetExSignalWithSignalTypeByID(standardConfigure.CorpID, mapper.SysId);
                        if (monitor == null)
                        {
                            continue;
                        }
                        switch (inputFirstRecord.RecordType)
                        {
                            case Model.eMonitorType.General:
                                {
                                    var receiveRecord = new Model.MonitorDataDockingReceiveRecord();
                                    receiveRecord.SysId = mapper.SysId;
                                    receiveRecord.RecordType = inputFirstRecord.RecordType;
                                    receiveRecord.SrcTime = inputFirstRecord.RecordTime;
                                    receiveRecord.SrcValue = inputFirstRecord.RecordValue;
                                    var record = MonitorHandleHelper.HandleHistory(monitor, monitor.SignalList.First(),receiveRecord,inputFirstRecord.RecordTime);
                                    if (record != null)
                                    {
                                        recordList.Add(record);
                                    }
                                }
                                break;
                            case Model.eMonitorType.Vibration:
                                {
 
                                }
                                break;
                            default: break;
                        }
                    }
                }
            }
 
            if (recordList.Count < 1)
            {
                return false;
            }
            
            //临时          
            var bol = new Service.MonitorRealRecord().InsertsSupplement(recordList.Select(x=>x as Model.MonitorRealRecordPure).ToList());
            return bol;
 
        }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    }
}