using IStation.Model;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.DataDockingApi
|
{
|
public class HandleHelper : IDataDockingApi.IHandleHelper
|
{
|
public void HandleData(List<DataDockingConfigure.Mapper> mappers, Action<List<Model.MonitorDataDockingReceiveRecord>> receive)
|
{
|
if (mappers == null || mappers.Count < 1)
|
return;
|
var appParas = AppParasHelper.Get();
|
if (appParas == null)
|
{
|
LogHelper.Error("宝山航务 Api 数据对接中,缺少对接配置文件");
|
return;
|
}
|
var token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MjcyNTMyOTYsInVzZXJuYW1lIjoiYmdqIn0.aj6nIng4R00QEiF5-HoA1qfBcQwXXZCmP0Dspl-1giw";
|
if (appParas.verify)
|
{
|
token = TokenHelper.Get();
|
if (string.IsNullOrEmpty(token))
|
{
|
LogHelper.Error("宝山航务 Api 数据对接中,获取Token失败");
|
return;
|
}
|
}
|
var responseText = HttpRequestHelper.Get(appParas.url.data, token);
|
var result = JsonHelper.Json2Object<Result<Record>>(responseText);
|
if (result.code != 0)
|
{
|
LogHelper.Info("宝山航务 Api 数据对接中,获取实时数据失败(code !=0)");
|
return;
|
}
|
var apiModel = GetData(result.data);
|
if (apiModel == null || apiModel.Count < 1)
|
{
|
LogHelper.Info("宝山航务 Api 数据对接中,获取实时数据失败(数据为空)");
|
return;
|
}
|
|
|
var record_receive_list = new List<Model.MonitorDataDockingReceiveRecord>();
|
foreach (var mapper in mappers)
|
{
|
var src = apiModel.Find(x => x.tagName == mapper.SignId);
|
if (src != null)
|
{
|
var record = new Model.MonitorDataDockingReceiveRecord();
|
record.SysId = mapper.SysId;
|
record.RecordType = eMonitorType.General;
|
record.SrcTime = src.time;
|
record.SrcValue = src.value.ToString();
|
record_receive_list.Add(record);
|
}
|
}
|
receive(record_receive_list);
|
|
if (appParas.src)
|
{
|
SrcHelper.Src(responseText);
|
}
|
if (appParas.debug)
|
{
|
DebugHelper.Debug(apiModel);
|
}
|
}
|
|
//获取数据
|
private List<BaseValue> GetData(Record data)
|
{
|
var list = new List<BaseValue>();
|
if (data.@base != null && data.@base.Count > 0)
|
list.AddRange(data.@base);
|
|
if (data.beng != null && data.beng.Count > 0)
|
foreach (var item in data.beng)
|
{
|
if (item.status != null)
|
list.Add(item.status);
|
if (item.dataList != null && item.dataList.Count > 0)
|
list.AddRange(item.dataList);
|
}
|
|
if (data.bianpin != null && data.bianpin.Count > 0)
|
foreach (var item in data.bianpin)
|
{
|
if (item.status != null)
|
list.Add(item.status);
|
if (item.dataList != null && item.dataList.Count > 0)
|
list.AddRange(item.dataList);
|
}
|
|
if (data.kongyuan != null && data.kongyuan.Count > 0)
|
foreach (var item in data.kongyuan)
|
if (item.dataList != null && item.dataList.Count > 0)
|
list.AddRange(item.dataList);
|
|
if (data.error != null && data.error.Count > 0)
|
list.AddRange(data.error);
|
|
if (data.other != null && data.other.Count > 0)
|
list.AddRange(data.other);
|
|
return list;
|
}
|
}
|
|
}
|