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;
|
|
namespace IStation.Application
|
{
|
/// <summary>
|
/// 波形存储接口(城投的航天 市南泵站专用)
|
/// </summary>
|
[AllowAnonymous]
|
[Route("smi/vibration/hangtian")]
|
[ApiDescriptionSettings("Vibration", Name = "城投航天振动", Order = 1000)]
|
public class Smi_HangTian_VibrationController : IDynamicApiController
|
{
|
|
/// <summary>
|
/// 单个添加
|
/// </summary>
|
[Route("SingleInsert")]
|
[HttpPost]
|
public bool SingleInsert([Required]AddSmiHangTianVibartionRecordInput input)
|
{
|
//转化为内部使用对象
|
var model = input.Adapt<AddSmiHangTianVibartionRecordInput, Model.SmiHangTianVibrationRecord>();
|
|
//写redis缓存
|
var redisHelper = new RedisCache.SmiHangTianVibrationRecord();
|
redisHelper.SetLastRecord(model);
|
|
if (ConfigHelper.Smi_HangTian_IsWriteLog)
|
{
|
LogHelper.Info($"航天写入Redis一条振动数据,ObjectId:{model.ObjectId}");
|
}
|
|
//获取配置
|
var configure = new Service.DataDockingConfigure().GetByID(ConfigHelper.Smi_HangTian_CorpID, ConfigHelper.Smi_HangTian_ConfigureID);
|
if (configure != null)
|
{
|
if (configure.Mappers != null && configure.Mappers.Count > 0)
|
{
|
var mapper = configure.Mappers.Find(t=>t.SignId== model.ObjectId);
|
if (mapper != null)
|
{
|
var monitor = new Service.MonitorPoint().GetExSignalWithSignalTypeByID(configure.CorpID, mapper.SysId);
|
if (monitor != null)
|
{
|
if (monitor.MonitorType == Model.eMonitorType.Vibration)
|
{
|
var receive = new Model.MonitorDataDockingReceiveRecord();
|
receive.SysId = monitor.ID;
|
receive.RecordType = monitor.MonitorType;
|
receive.SrcTime = model.SrcTime;
|
receive.DataStatus = model.DataStatus;
|
|
//子项列表
|
var receiveSubList = new List<Model.MonitorDataDockingReceiveSubRecord>();
|
|
//配置
|
var signal_config = monitor.SignalList.Find(t=>t.Flags!=null&&t.Flags.Contains(LogicFlags.配置));
|
if (signal_config != null)
|
{
|
var config = model.Adapt<Model.SmiHangTianVibrationRecord, Model.SmiHangTianVibrationConfig>();
|
var config_json = JsonHelper.Object2Json(config);
|
var config_sub = new Model.MonitorDataDockingReceiveSubRecord();
|
config_sub.SysId = signal_config.ID;
|
config_sub.SrcValue= config_json;
|
receiveSubList.Add(config_sub);
|
}
|
|
//转速
|
var signal_rpm = monitor.SignalList.Find(t=>t.Flags!=null&&t.Flags.Contains(LogicFlags.转速));
|
if (signal_rpm != null)
|
{
|
var rpm_sub = new Model.MonitorDataDockingReceiveSubRecord();
|
rpm_sub.SysId= signal_rpm.ID;
|
rpm_sub.SrcValue = model.Speed.ToString();
|
receiveSubList.Add(rpm_sub);
|
}
|
|
//间歇电压
|
var signal_u = monitor.SignalList.Find(t=>t.Flags!=null&&t.Flags.Contains(LogicFlags.间歇电压));
|
if (signal_u != null)
|
{
|
var u_sub = new Model.MonitorDataDockingReceiveSubRecord();
|
u_sub.SysId = signal_u.ID;
|
u_sub.SrcValue = model.GapValue.ToString();
|
receiveSubList.Add(u_sub);
|
}
|
|
//通频值
|
var signal_tp = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.通频值));
|
if (signal_tp != null)
|
{
|
var tp_sub = new Model.MonitorDataDockingReceiveSubRecord();
|
tp_sub.SysId = signal_tp.ID;
|
tp_sub.SrcValue = model.OverValue.ToString();
|
receiveSubList.Add(tp_sub);
|
}
|
|
//波形
|
var signal_wave= monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.波形));
|
if (signal_wave != null)
|
{
|
var wave_sub = new Model.MonitorDataDockingReceiveSubRecord();
|
wave_sub.SysId = signal_wave.ID;
|
wave_sub.SrcValue = model.Wave;
|
receiveSubList.Add(wave_sub);
|
}
|
|
receive.SrcValue = Model.MonitorDataDockingReceiveSubRecord.ToJson(receiveSubList);
|
|
var queueHelper = new RabbitMqQueueHelper();
|
var bol= queueHelper.Push(ConfigHelper.DataDockingQueueName,new Model.MonitorDataDockingCorpRecord() {
|
CorpID=configure.CorpID,
|
ConfigureID=configure.ID,
|
Records=new List<Model.MonitorDataDockingReceiveRecord>() { receive}
|
});
|
if (bol)
|
{
|
if (ConfigHelper.Smi_HangTian_IsWriteLog)
|
{
|
LogHelper.Info($"航天推入通道一条振动数据,ObjectId:{model.ObjectId},SysId:{monitor.ID}");
|
}
|
return true;
|
}
|
}
|
}
|
}
|
}
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 批量添加
|
/// </summary>
|
[Route("BulkInsert")]
|
[HttpPost]
|
public bool BulkInsert([Required]List<AddSmiHangTianVibartionRecordInput> inputList)
|
{
|
if (inputList == null || inputList.Count < 1)
|
return false;
|
//转化为内部使用对象
|
var modelList = inputList.Select(x => x.Adapt<AddSmiHangTianVibartionRecordInput, Model.SmiHangTianVibrationRecord>()).ToList();
|
|
//写redis缓存
|
var redisHelper = new RedisCache.SmiHangTianVibrationRecord();
|
redisHelper.SetLastRecord(modelList);
|
|
if (ConfigHelper.Smi_HangTian_IsWriteLog)
|
{
|
LogHelper.Info($"航天写入Redis {modelList.Count} 条振动数据");
|
}
|
|
//获取配置
|
var configure = new Service.DataDockingConfigure().GetByID(ConfigHelper.Smi_HangTian_CorpID, ConfigHelper.Smi_HangTian_ConfigureID);
|
if (configure != null)
|
{
|
if (configure.Mappers != null && configure.Mappers.Count > 0)
|
{
|
var receiveList = new List<Model.MonitorDataDockingReceiveRecord>();
|
foreach (var model in modelList)
|
{
|
var mapper = configure.Mappers.Find(t => t.SignId == model.ObjectId);
|
if (mapper != null)
|
{
|
var monitor = new Service.MonitorPoint().GetExSignalWithSignalTypeByID(configure.CorpID, mapper.SysId);
|
if (monitor != null)
|
{
|
if (monitor.MonitorType == Model.eMonitorType.Vibration)
|
{
|
var receive = new Model.MonitorDataDockingReceiveRecord();
|
receive.SysId = monitor.ID;
|
receive.RecordType = monitor.MonitorType;
|
receive.SrcTime = model.SrcTime;
|
receive.DataStatus = model.DataStatus;
|
|
//子项列表
|
var receiveSubList = new List<Model.MonitorDataDockingReceiveSubRecord>();
|
|
//配置
|
var signal_config = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.配置));
|
if (signal_config != null)
|
{
|
var config = model.Adapt<Model.SmiHangTianVibrationRecord, Model.SmiHangTianVibrationConfig>();
|
var config_json = JsonHelper.Object2Json(config);
|
var config_sub = new Model.MonitorDataDockingReceiveSubRecord();
|
config_sub.SysId = signal_config.ID;
|
config_sub.SrcValue = config_json;
|
receiveSubList.Add(config_sub);
|
}
|
|
//转速
|
var signal_rpm = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.转速));
|
if (signal_rpm != null)
|
{
|
var rpm_sub = new Model.MonitorDataDockingReceiveSubRecord();
|
rpm_sub.SysId = signal_rpm.ID;
|
rpm_sub.SrcValue = model.Speed.ToString();
|
receiveSubList.Add(rpm_sub);
|
}
|
|
//间歇电压
|
var signal_u = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.间歇电压));
|
if (signal_u != null)
|
{
|
var u_sub = new Model.MonitorDataDockingReceiveSubRecord();
|
u_sub.SysId = signal_u.ID;
|
u_sub.SrcValue = model.GapValue.ToString();
|
receiveSubList.Add(u_sub);
|
}
|
|
//通频值
|
var signal_tp = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.通频值));
|
if (signal_tp != null)
|
{
|
var tp_sub = new Model.MonitorDataDockingReceiveSubRecord();
|
tp_sub.SysId = signal_tp.ID;
|
tp_sub.SrcValue = model.OverValue.ToString();
|
receiveSubList.Add(tp_sub);
|
}
|
|
//波形
|
var signal_wave = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.波形));
|
if (signal_wave != null)
|
{
|
var wave_sub = new Model.MonitorDataDockingReceiveSubRecord();
|
wave_sub.SysId = signal_wave.ID;
|
wave_sub.SrcValue = model.Wave;
|
receiveSubList.Add(wave_sub);
|
}
|
|
receive.SrcValue = Model.MonitorDataDockingReceiveSubRecord.ToJson(receiveSubList);
|
receiveList.Add(receive);
|
}
|
}
|
}
|
}
|
if (receiveList.Count > 0)
|
{
|
var queueHelper = new RabbitMqQueueHelper();
|
var bol = queueHelper.Push(ConfigHelper.DataDockingQueueName, new Model.MonitorDataDockingCorpRecord()
|
{
|
CorpID = configure.CorpID,
|
ConfigureID = configure.ID,
|
Records = receiveList
|
});
|
if (bol)
|
{
|
if (ConfigHelper.Smi_HangTian_IsWriteLog)
|
{
|
LogHelper.Info($"航天推入通道 {receiveList.Count} 条振动数据");
|
}
|
return true;
|
}
|
}
|
}
|
}
|
|
return false;
|
|
}
|
|
/// <summary>
|
/// 通过 ObjectId 查询最近一条记录
|
/// </summary>
|
[Route("QueryLastRecordByObjectId")]
|
[HttpGet]
|
public SmiHangTianVibrationRecordDto QueryLastRecordByObjectId([Required, DataValidation(AllowEmptyStrings = false)] string ObjectId)
|
{
|
var redisCacheHelper = new RedisCache.SmiHangTianVibrationRecord();
|
var model = redisCacheHelper.GetLastRecord(ObjectId);
|
if (ConfigHelper.Smi_HangTian_IsWriteLog)
|
{
|
LogHelper.Info($"航天通过ObjectId: {ObjectId} 获取 {(model == null ? 0:1)} 条");
|
}
|
var dto = model?.Adapt<Model.SmiHangTianVibrationRecord, SmiHangTianVibrationRecordDto>();
|
return dto;
|
}
|
|
/// <summary>
|
/// 通过 ObjectId 查询最近
|
/// </summary>
|
[Route("QueryLastRecordByObjectIds")]
|
[HttpGet]
|
public List<SmiHangTianVibrationRecordDto> QueryLastRecordByObjectIds(string ObjectIds)
|
{
|
var ids = StringListHelper.ToList(ObjectIds);
|
if (ids == null || ids.Count() < 1)
|
{
|
return default;
|
}
|
var redisCacheHelper = new RedisCache.SmiHangTianVibrationRecord();
|
var modelList = redisCacheHelper.GetLastRecord(ids);
|
if (ConfigHelper.Smi_HangTian_IsWriteLog)
|
{
|
LogHelper.Info($"航天通过ObjectId: {ObjectIds} 获取 {(modelList == null ? 0 : modelList.Count)} 条");
|
}
|
var dtoList = modelList?.Select(x => x.Adapt<Model.SmiHangTianVibrationRecord, SmiHangTianVibrationRecordDto>()).ToList();
|
return dtoList;
|
}
|
|
/// <summary>
|
/// 通过 ObjectId 查询最近
|
/// </summary>
|
[Route("QueryLastRecordStartWith")]
|
[HttpGet]
|
public List<SmiHangTianVibrationRecordDto> QueryLastRecordStartWith([Required, DataValidation(AllowEmptyStrings = false)] string ObjectId)
|
{
|
var redisCacheHelper = new RedisCache.SmiHangTianVibrationRecord();
|
var modelList = redisCacheHelper.GetLastRecordStartWith(ObjectId);
|
if (ConfigHelper.Smi_HangTian_IsWriteLog)
|
{
|
LogHelper.Info($"航天通过ObjectId: {ObjectId} 获取 {(modelList == null ? 0 : modelList.Count)} 条");
|
}
|
var dtoList = modelList?.Select(x => x.Adapt<Model.SmiHangTianVibrationRecord, SmiHangTianVibrationRecordDto>()).ToList();
|
return dtoList;
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
}
|