lixiaojun
2024-11-18 a2059eaa7c6c2346f3a1a03ab214a6cd8dfc8b38
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
namespace IStation.DataDockingApi
{
    /// <summary>
    /// 
    /// </summary>
    public class HandleHelper : IHandleHelper
    {
 
        /// <summary>
        /// 
        /// </summary>
        public void HandleData(List<Yw.Model.DataDockingConfigureItemExSubList> items, Action<List<Yw.Model.MonitorHandleRecord>> receive)
        {
            if (items == null || items.Count < 1)
            {
                return;
            }
            var app_paras = AppParasHelper.Get();
            if (app_paras == null)
            {
                LogHelper.Error("苏州金庭仪表 Api 数据对接中,缺少对接配置文件");
            }
            var token = TokenHelper.Get();
            if (string.IsNullOrEmpty(token))
            {
                LogHelper.Error("苏州金庭仪表 Api 数据对接中,获取Token失败");
                return;
            }
 
            var history_url = app_paras.url.history;
            history_url = $"{history_url}?pageNumber=1&startTime={DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd")}&endTime={DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")}";
 
            var history_result = HttpRequestHelper.History(history_url, token);
            if (history_result == null)
            {
                LogHelper.Info("苏州金庭仪表 Api 数据对接中,获取实时数据失败");
                return;
            }
 
            if (history_result.status != "SUCCESS")
            {
                LogHelper.Info("苏州金庭仪表 Api 数据对接中,获取实时数据失败(status!= SUCCESS),可能是token被其他程序更新,正在重新获取");
                token = TokenHelper.GetAgain();
                history_result = HttpRequestHelper.History(history_url, token);
                if (history_result == null)
                {
                    LogHelper.Info("苏州金庭仪表 Api 数据对接中,获取实时数据失败");
                    return;
                }
                if (history_result.status != "SUCCESS")
                {
                    LogHelper.Info("苏州金庭仪表 Api 数据对接中,获取实时数据失败(status!= SUCCESS),重新获取依旧失败,请检查程序!");
                    return;
                }
            }
 
            if (history_result.content.result == null || history_result.content.result.Length < 1)
            {
                LogHelper.Info("苏州金庭仪表 Api 数据对接中,获取实时数据失败(数据为空)");
                return;
            }
 
            var result_group_list = history_result.content.result.OrderBy(x => x.collectedTime).GroupBy(x => x.collectedTime).ToList();
            foreach (var result_group in result_group_list)
            {
                var receive_list = new List<Yw.Model.MonitorHandleRecord>();
                var code_list = result_group.Select(x => x.meterCode).Distinct().ToList();
                foreach (var code in code_list)
                {
                    var record = result_group.FirstOrDefault(x => x.meterCode == code);
                    if (LastCollectHelper.SetLastTime(code, record.collectedTime))
                    {
                        if (record.instantFlow != null)
                        {
                            var signId = $"{code}_q";
                            var item_list = items.Where(x => x.TransferId == signId).ToList();
                            if (item_list != null && item_list.Count > 0)
                            {
                                foreach (var item in item_list)
                                {
                                    var item_sub = item.SubList.First();
 
                                    var receiveRecord = new Yw.Model.MonitorHandleRecord();
                                    receiveRecord.DataTime = record.collectedTime;
                                    receiveRecord.MonitorPointID = item.MonitorPointID;
 
                                    var srcValue = record.instantFlow.Value;
                                    var dataStatus = new List<string>();
                                    var dataValue = item_sub.Docking(srcValue.ToString(), ref dataStatus);
 
                                    var receiveSubRecord = new Yw.Model.MonitorHandleSubRecord();
                                    receiveSubRecord.SignalID = item_sub.SignalID;
                                    receiveSubRecord.SrcValue = srcValue.ToString();
                                    receiveSubRecord.DataValue = dataValue;
 
                                    receiveRecord.SubList.Add(receiveSubRecord);
 
                                    if (item.IsMeet(receiveRecord))
                                    {
                                        receive_list.Add(receiveRecord);
                                    }
                                }
                            }
                        }
                        if (record.cumulativeFlow != null)
                        {
                            var signId = $"{code}_ql";
                            var item_list = items.Where(x => x.TransferId == signId).ToList();
                            if (item_list != null && item_list.Count > 0)
                            {
                                foreach (var item in item_list)
                                {
                                    var item_sub = item.SubList.First();
 
                                    var receiveRecord = new Yw.Model.MonitorHandleRecord();
                                    receiveRecord.DataTime = record.collectedTime;
                                    receiveRecord.MonitorPointID = item.MonitorPointID;
 
                                    var srcValue = record.cumulativeFlow.Value;
                                    var dataStatus = new List<string>();
                                    var dataValue = item_sub.Docking(srcValue.ToString(), ref dataStatus);
 
                                    var receiveSubRecord = new Yw.Model.MonitorHandleSubRecord();
                                    receiveSubRecord.SignalID = item_sub.SignalID;
                                    receiveSubRecord.SrcValue = srcValue.ToString();
                                    receiveSubRecord.DataValue = dataValue;
 
                                    receiveRecord.SubList.Add(receiveSubRecord);
                                    if (item.IsMeet(receiveRecord))
                                    {
                                        receive_list.Add(receiveRecord);
                                    }
                                }
                            }
                        }
                        if (record.pressure != null)
                        {
                            var signId = $"{code}_pr";
                            var item_list = items.Where(x => x.TransferId == signId).ToList();
                            if (item_list != null && item_list.Count > 0)
                            {
                                foreach (var item in item_list)
                                {
                                    var item_sub = item.SubList.First();
 
                                    var receiveRecord = new Yw.Model.MonitorHandleRecord();
                                    receiveRecord.DataTime = record.collectedTime;
                                    receiveRecord.MonitorPointID = item.MonitorPointID;
 
                                    var srcValue = record.pressure.Value;
                                    var dataStatus = new List<string>();
                                    var dataValue = item_sub.Docking(srcValue.ToString(), ref dataStatus);
 
                                    var receiveSubRecord = new Yw.Model.MonitorHandleSubRecord();
                                    receiveSubRecord.SignalID = item_sub.SignalID;
                                    receiveSubRecord.SrcValue = srcValue.ToString();
                                    receiveSubRecord.DataValue = dataValue;
 
                                    receiveRecord.SubList.Add(receiveSubRecord);
                                    if (item.IsMeet(receiveRecord))
                                    {
                                        receive_list.Add(receiveRecord);
                                    }
                                }
                            }
                        }
                    }
                }
                if (receive_list.Count > 0)
                {
                    receive(receive_list);
                }
 
            }
 
 
        }
    }
 
}