1、每10分钟,主动判断一下遥信全体 2、程序启动时,提取遥测遥信全体命令,每个命令闹间隔1秒 3、提取遥测遥信全体命令完成后(10分钟超时),再执行巡检和定位发送提取遥测信息 4、每30秒请求一次虚点 5、其他一系列修改
138 lines
4.5 KiB
C#
138 lines
4.5 KiB
C#
using Google.Protobuf.WellKnownTypes;
|
||
using Microsoft.Extensions.Logging;
|
||
using Newtonsoft.Json;
|
||
using Newtonsoft.Json.Linq;
|
||
using Org.BouncyCastle.Utilities;
|
||
using Quartz;
|
||
using System;
|
||
using System.Collections.Concurrent;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text.Json.Serialization;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using YunDa.Server.ISMSTcp.Models;
|
||
using YunDa.SOMS.DataTransferObject.MaintenanceAndOperations.SecondaryEquipment;
|
||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||
|
||
namespace YunDa.Server.ISMSTcp.Services
|
||
{
|
||
public class GwErrorRatioService
|
||
{
|
||
private readonly ILogger<AlarmService> _logger;
|
||
private readonly ZzDataCacheContainerInit _zzDataCacheContainerInit;
|
||
|
||
//数据缓冲队列
|
||
|
||
private ZzDataCacheContainer _cacheContainer = new ZzDataCacheContainer(ZzDataCacheContainerDataType.eGW, 2 * 60 + 1);//保留2小时的数据,多1分钟,兼容发送送数据发送延迟情况(每1小时发送一次)
|
||
|
||
public GwErrorRatioService(ILogger<AlarmService> logger, ZzDataCacheContainerInit zzDataCacheContainerInit)
|
||
{
|
||
_logger = logger;
|
||
_zzDataCacheContainerInit = zzDataCacheContainerInit;
|
||
_zzDataCacheContainerInit.InitGateWayBaseInfo(_cacheContainer);
|
||
|
||
|
||
ZzDataCache.SetDataCache(ZzDataCacheContainerDataType.eGW, _cacheContainer);
|
||
}
|
||
|
||
//解析数据
|
||
public async Task<Models.ProcessResult> TranselateData(JToken contentToken)
|
||
{
|
||
try
|
||
{
|
||
// 输入验证
|
||
if (contentToken == null)
|
||
{
|
||
_logger.LogWarning("GwErrorRatio message content is null");
|
||
return Models.ProcessResult.Error("GwErrorRatio message content is null");
|
||
}
|
||
|
||
// 批量处理网关通信数据
|
||
List<GwErrorRatioDataModel> gatewayDatas;
|
||
|
||
gatewayDatas = contentToken.ToObject<List<GwErrorRatioDataModel>>();
|
||
|
||
if (gatewayDatas == null || gatewayDatas.Count == 0)
|
||
{
|
||
_logger.LogWarning("GwErrorRatio message contains no valid alert data");
|
||
}
|
||
else
|
||
{
|
||
ProcessData(gatewayDatas);
|
||
}
|
||
|
||
|
||
return Models.ProcessResult.Success(contentToken, "GWERRORRATIO");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error processing GwErrorRatio message");
|
||
return Models.ProcessResult.Error($"GwErrorRatio processing error: {ex.Message}");
|
||
}
|
||
}
|
||
|
||
//处理数据
|
||
private void ProcessData(List<GwErrorRatioDataModel> gatewayDatas)
|
||
{
|
||
foreach (var data in gatewayDatas)
|
||
{
|
||
data.DataTimeStamp = DateTime.Now;
|
||
SaveDataToCache(data);
|
||
}
|
||
}
|
||
|
||
//缓存数据到内存
|
||
private void SaveDataToCache(GwErrorRatioDataModel data)
|
||
{
|
||
_cacheContainer.Write(data.GatewayID, data.ErrorRatio, data.DataTimeStamp, "", data.ErrorRatio.ToString("P2"));
|
||
}
|
||
|
||
//查询数据
|
||
public async Task<List<ZzDataResultModel>> GetDataByIds(List<string> ids, int seconds, CancellationToken cancellationToken)
|
||
{
|
||
try
|
||
{
|
||
if (seconds < 60 * 60)
|
||
{
|
||
seconds = 60 * 60 + 60; //多60秒,兼容发送送数据发送延迟情况(每1小时发送一次)
|
||
}
|
||
else if (seconds < 2 * 60 * 60)
|
||
{
|
||
seconds = 2 * 60 * 60 + 60;
|
||
}
|
||
|
||
return await _cacheContainer.Read(ids, seconds, 0, cancellationToken);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
_logger.LogError(ex, "GwErrorRatioService: GetDataByIds 出错");
|
||
return new List<ZzDataResultModel>();
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
|
||
public class GwErrorRatioDataModel
|
||
{
|
||
public string GatewayID { get; set; } = string.Empty; //网关Id
|
||
|
||
public double ErrorRatio { get; set; } //每小时的错误率
|
||
|
||
public DateTime DataTimeStamp { get; set; }
|
||
}
|
||
|
||
|
||
public class ErrorRatioDataByIdRequestModel
|
||
{
|
||
public List<string> Id { get; set; }
|
||
public int Times { get; set; }
|
||
public int TimeWindowType { get; set; }
|
||
}
|
||
|
||
|
||
|
||
}
|