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("smi/vibration/zept")]
|
[ApiDescriptionSettings("Vibration", Name = "城投恩普特振动", Order = 1100)]
|
public class Smi_Zept_VibrationController : IDynamicApiController
|
{
|
|
|
/// <summary>
|
/// 单个添加
|
/// </summary>
|
[Route("SingleInsert")]
|
public bool SingleInsert([Required]AddSmiExpertVibrationRecordInput input)
|
{
|
//转化为内部使用对象
|
var model = input.Adapt<AddSmiExpertVibrationRecordInput, Model.SmiExpertVibrationRecord>();
|
|
//写redis缓存
|
var redisHelper = new RedisCache.SmiExpertVibrationRecord();
|
redisHelper.SetLastRecord(model);
|
|
if (ConfigHelper.Smi_Expert_IsWriteLog)
|
{
|
LogHelper.Info($"恩普特写入Redis一条振动数据,ObjectId:{model.ObjectId}");
|
}
|
|
//获取配置
|
var configure = new Service.DataDockingConfigure().GetByID(ConfigHelper.Smi_Expert_CorpID, ConfigHelper.Smi_Expert_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.SmiExpertVibrationRecord, Model.SmiExpertVibrationConfig>();
|
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.Rpm.ToString();
|
receiveSubList.Add(rpm_sub);
|
}
|
|
//直流量
|
var signal_ic = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.直流量));
|
if (signal_ic != null)
|
{
|
var ic_sub = new Model.MonitorDataDockingReceiveSubRecord();
|
ic_sub.SysId = signal_ic.ID;
|
ic_sub.SrcValue = model.DcValue.ToString();
|
receiveSubList.Add(ic_sub);
|
}
|
|
//频率
|
var signal_hz = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.频率));
|
if (signal_hz != null)
|
{
|
var hz_sub = new Model.MonitorDataDockingReceiveSubRecord();
|
hz_sub.SysId = signal_hz.ID;
|
hz_sub.SrcValue = model.Frequency.ToString();
|
receiveSubList.Add(hz_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_Expert_IsWriteLog)
|
{
|
LogHelper.Info($"恩普特推入通道一条振动数据,ObjectId:{model.ObjectId},SysId:{monitor.ID}");
|
}
|
return true;
|
}
|
}
|
}
|
}
|
}
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 批量添加
|
/// </summary>
|
[Route("BulkInsert")]
|
public bool BulkInsert([Required]List<AddSmiExpertVibrationRecordInput> inputList)
|
{
|
if (inputList == null || inputList.Count < 1)
|
return false;
|
//转化为内部使用对象
|
var modelList = inputList.Select(x => x.Adapt<AddSmiExpertVibrationRecordInput, Model.SmiExpertVibrationRecord>()).ToList();
|
|
//写redis缓存
|
var redisHelper = new RedisCache.SmiExpertVibrationRecord();
|
redisHelper.SetLastRecord(modelList);
|
|
if (ConfigHelper.Smi_HangTian_IsWriteLog)
|
{
|
LogHelper.Info($"恩普特写入Redis {modelList.Count} 条振动数据");
|
}
|
|
//获取配置
|
var configure = new Service.DataDockingConfigure().GetByID(ConfigHelper.Smi_Expert_CorpID, ConfigHelper.Smi_Expert_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.SmiExpertVibrationRecord, Model.SmiExpertVibrationConfig>();
|
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.Rpm.ToString();
|
receiveSubList.Add(rpm_sub);
|
}
|
|
//直流量
|
var signal_ic = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.直流量));
|
if (signal_ic != null)
|
{
|
var ic_sub = new Model.MonitorDataDockingReceiveSubRecord();
|
ic_sub.SysId = signal_ic.ID;
|
ic_sub.SrcValue = model.DcValue.ToString();
|
receiveSubList.Add(ic_sub);
|
}
|
|
//频率
|
var signal_hz = monitor.SignalList.Find(t => t.Flags != null && t.Flags.Contains(LogicFlags.频率));
|
if (signal_hz != null)
|
{
|
var hz_sub = new Model.MonitorDataDockingReceiveSubRecord();
|
hz_sub.SysId = signal_hz.ID;
|
hz_sub.SrcValue = model.Frequency.ToString();
|
receiveSubList.Add(hz_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_Expert_IsWriteLog)
|
{
|
LogHelper.Info($"恩普特推入通道 {receiveList.Count} 条振动数据");
|
}
|
return true;
|
}
|
}
|
}
|
}
|
|
return false;
|
}
|
|
/// <summary>
|
/// 通过 ObjectId 查询最近(已过时)
|
/// </summary>
|
[Route("QueryLastRecordByObjectId")]
|
[HttpGet]
|
public List<SmiExpertVibrationRecordDto> QueryLastRecordByObjectId(string ProductId, string ObjectId)
|
{
|
if (string.IsNullOrEmpty(ObjectId))
|
{
|
return default;
|
}
|
var objectIds = ObjectId.Split(',');
|
if (objectIds == null || objectIds.Count() < 1)
|
{
|
return default;
|
}
|
var redisHelper = new RedisCache.SmiExpertVibrationRecord();
|
var modelList = redisHelper.GetLastRecord(objectIds);
|
if (ConfigHelper.Smi_Expert_IsWriteLog)
|
{
|
LogHelper.Info($"恩普特通过ObjectId: {ObjectId} 获取 {(modelList == null ? 0 : modelList.Count)} 条");
|
}
|
var dtoList = modelList?.Select(x => x.Adapt<Model.SmiExpertVibrationRecord, SmiExpertVibrationRecordDto>()).ToList();
|
return dtoList;
|
}
|
|
/// <summary>
|
/// 通过 ProductId 查询最近
|
/// </summary>
|
[Route("QueryLastRecordByProductId")]
|
[HttpGet]
|
public List<SmiExpertVibrationRecordDto> QueryLastRecordByProductId(string ProductId)
|
{
|
if (string.IsNullOrEmpty(ProductId))
|
{
|
return default;
|
}
|
|
var redisHelper = new RedisCache.SmiExpertVibrationRecord();
|
var modelList = redisHelper.GetLastRecordStartWith(ProductId);
|
if (ConfigHelper.Smi_Expert_IsWriteLog)
|
{
|
LogHelper.Info($"恩普特通过ProductId: {ProductId} 获取 {(modelList == null ? 0 : modelList.Count)} 条");
|
}
|
var dtoList = modelList?.Select(x => x.Adapt<Model.SmiExpertVibrationRecord, SmiExpertVibrationRecordDto>()).ToList();
|
return dtoList;
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
}
|