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);
|
}
|
|
}
|
|
|
}
|
}
|
|
}
|