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("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] DataDockingStandardCorpRecordInput 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();
|
record.SysId = mapper.SysId;
|
record.RecordType = inputRecord.RecordType;
|
record.SrcTime = inputRecord.RecordTime;
|
record.SrcValue = inputRecord.RecordValue;
|
record.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("InsertsSupplement@V1.0")]
|
//[HttpPost]
|
//public bool InsertsSupplement([Required] List<SupplementMonitorRealRecordInput> list)
|
//{
|
// var corpIds = list.Select(x => x.CorpID).Distinct().ToList();
|
// if (corpIds.Count > 1)
|
// {
|
// return false;
|
// }
|
|
// var record_list = new List<Model.MonitorRealRecordPure>();
|
// foreach (var item in list)
|
// {
|
// var monitor = new Service.MonitorPoint().GetExSignalWithSignalTypeByID(item.CorpID, item.MonitorPointID);
|
// if (monitor == null)
|
// {
|
// continue;
|
// }
|
// if (monitor.CronType != Model.Monitor.eCronType.Real)
|
// {
|
// continue;
|
// }
|
// switch (monitor.MonitorType)
|
// {
|
// case Model.eMonitorType.General:
|
// {
|
// var signal = monitor.SignalList?.FirstOrDefault();
|
// if (signal != null)
|
// {
|
// var data_status = new List<string>();
|
// var data_value = MonitorHandleHelper.Handle(monitor, signal, lastRecord: null, item.SrcTime, item.SrcValue, data_status);
|
// if (!string.IsNullOrEmpty(data_value))
|
// {
|
// var record = new Model.MonitorRealRecordPure();
|
// record.CorpID = item.CorpID;
|
// record.MonitorPointID = item.MonitorPointID;
|
// record.SignalID = signal.ID;
|
// record.RecordType = monitor.MonitorType;
|
// record.SrcTime = item.SrcTime;
|
// record.SrcValue = item.SrcValue;
|
// record.DataTime = item.DataTime;
|
// record.DataValue = data_value;
|
// record.DataStatus = data_status;
|
// record_list.Add(record);
|
// }
|
// }
|
// }
|
// break;
|
// case Model.eMonitorType.Vibration:
|
// {
|
// var sub_record_list = AddMonitorSubRecordInput.ToList(item.SrcValue);
|
// if (sub_record_list != null && sub_record_list.Count > 0)
|
// {
|
// foreach (var sub_record in sub_record_list)
|
// {
|
// var signal = monitor.SignalList?.FirstOrDefault(x => x.ID == sub_record.SignalID);
|
// if (signal == null)
|
// continue;
|
// var data_status = new List<string>();
|
// var data_value = MonitorHandleHelper.Handle(monitor, signal, lastRecord: null, item.SrcTime, sub_record.SrcValue, data_status);
|
// if (string.IsNullOrEmpty(data_value))
|
// continue;
|
// var record = new Model.MonitorRealRecordPure();
|
// record.CorpID = item.CorpID;
|
// record.MonitorPointID = item.MonitorPointID;
|
// record.SignalID = signal.ID;
|
// record.RecordType = monitor.MonitorType;
|
// record.SrcTime = item.SrcTime;
|
// record.SrcValue = item.SrcValue;
|
// record.DataTime = item.DataTime;
|
// record.DataValue = data_value;
|
// record.DataStatus = data_status;
|
// record_list.Add(record);
|
// }
|
// }
|
// }
|
// break;
|
// default: break;
|
// }
|
// }
|
|
// if (record_list.Count < 1)
|
// {
|
// return false;
|
// }
|
// var bol = _service.InsertsSupplement(record_list);
|
// return bol;
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
}
|