装置自检自检信息

This commit is contained in:
郭睿 2024-12-02 14:52:59 +08:00
parent 351c6a810b
commit a8cfc2bc80
13 changed files with 146 additions and 79 deletions

View File

@ -17,7 +17,6 @@ namespace YunDa.ISAS.DataTransferObject.EquipmentLiveData
public int ResultValue { get; set; } = ConstantModel.DegaultValue;
public bool IsSendSelfCheck { get; set; }
public virtual string ResultValueStr
{
get

View File

@ -5,6 +5,7 @@ using Newtonsoft.Json;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@ -24,6 +25,7 @@ using YunDa.ISAS.DataTransferObject.EquipmentLiveData;
using YunDa.ISAS.Entities.DataMonitoring;
using YunDa.ISAS.Redis.Entities.DataMonitorCategory;
using YunDa.ISAS.Redis.Repositories;
using YunDa.SOMS.DataTransferObject.GeneralInformation.SecondaryCircuitDto;
using YunDa.SOMS.DataTransferObject.MainStationMaintenanceInfo.OperationReport;
using Z.Expressions;
@ -174,7 +176,7 @@ namespace Yunda.ISAS.DataMonitoringServer.DataAnalysis.DataCollection
tasks.Add(SetEnvirmentTemp(ycData));
// 执行所有任务并等待完成
await Task.WhenAll(tasks);
//await Task.WhenAll(tasks);
}
catch (Exception ex)
{
@ -247,7 +249,7 @@ namespace Yunda.ISAS.DataMonitoringServer.DataAnalysis.DataCollection
tasks.Add(_alarmAnalysis.HandleTelesignalAlarmAsync(yxData));
// 等待所有任务完成
await Task.WhenAll(tasks);
//await Task.WhenAll(tasks);
}
catch (Exception ex)
{
@ -255,58 +257,84 @@ namespace Yunda.ISAS.DataMonitoringServer.DataAnalysis.DataCollection
MonitoringEventBus.LogHandler(ex.Message, "错误信息");
}
}
private async Task CheckSecondCuirtAlarm(string haskey)
private Task CheckSecondCuirtAlarm(string haskey)
{
if (_runningDataCache.SecondaryCircuitLogicExpressionDic.ContainsKey(haskey))
{
var listLogics = _runningDataCache.SecondaryCircuitLogicExpressionDic[haskey];
foreach (var listLogic in listLogics)
return Task.Run(() =>
{
// 示例字符串
// 正则表达式匹配花括号中的内容
string pattern = @"\{([^}]*)\}";
Regex regex = new Regex(pattern);
// 提取匹配内容
MatchCollection matches = regex.Matches(listLogic.LogicExpression);
List<string> extractedStrings = new List<string>();
foreach (Match match in matches)
lock (_runningDataCache.SecondaryCircuitLogicExpressionDic)
{
var logichasKey = match.Groups[1].Value;
string telemeteringredisKey = _redisDataRepository.TelemeteringModelListRediskey + "_" + _settingModel.GetDatacatgoryName(_settingModel.DataSourceCategoryName);
// 获取原始数据
var listLogics = _runningDataCache.SecondaryCircuitLogicExpressionDic[haskey];
var ycLiveData = _redisDataRepository.TelemeteringModelListRedis.HashSetGetOne(telemeteringredisKey, logichasKey);
if (ycLiveData != null)
{
listLogic.LogicExpression.Replace(logichasKey, ycLiveData.ResultValue.ToString());
}
string telesignalisationredisKey = _redisDataRepository.TelesignalisationModelListRediskey + "_" + _settingModel.GetDatacatgoryName(_settingModel.DataSourceCategoryName);
// 创建副本列表
var copiedLogics = listLogics
.Select(logic => new LogicExpressionTelesignalisation
{
LogicExpression = logic.LogicExpression,
TelesignalisationAddr = logic.TelesignalisationAddr
})
.ToList();
var yxLiveData = _redisDataRepository.TelesignalisationModelListRedis.HashSetGetOne(telesignalisationredisKey, logichasKey);
if (yxLiveData != null)
foreach (var listLogic in copiedLogics)
{
listLogic.LogicExpression.Replace(logichasKey, yxLiveData.ResultValue.ToString());
string pattern = @"\{([^}]*)\}";
Regex regex = new Regex(pattern);
// 提取匹配内容
MatchCollection matches = regex.Matches(listLogic.LogicExpression);
foreach (Match match in matches)
{
var logichasKey = match.Groups[1].Value;
string telemeteringredisKey = _redisDataRepository.TelemeteringModelListRediskey + "_" + _settingModel.GetDatacatgoryName(_settingModel.DataSourceCategoryName);
var ycLiveData = _redisDataRepository.TelemeteringModelListRedis.HashSetGetOne(telemeteringredisKey, logichasKey);
if (ycLiveData != null)
{
listLogic.LogicExpression = listLogic.LogicExpression.Replace(logichasKey, ycLiveData.ResultValue.ToString());
}
string telesignalisationredisKey = _redisDataRepository.TelesignalisationModelListRediskey + "_" + _settingModel.GetDatacatgoryName(_settingModel.DataSourceCategoryName);
var yxLiveData = _redisDataRepository.TelesignalisationModelListRedis.HashSetGetOne(telesignalisationredisKey, logichasKey);
if (yxLiveData != null)
{
if (yxLiveData.RemoteType == RemoteTypeEnum.DoublePoint)
{
yxLiveData.ResultValue = yxLiveData.ResultValue > 2 ? 0 : yxLiveData.ResultValue - 1;
}
else
{
yxLiveData.ResultValue = yxLiveData.ResultValue > 2 ? 0 : yxLiveData.ResultValue;
}
listLogic.LogicExpression = listLogic.LogicExpression.Replace(logichasKey, yxLiveData.ResultValue.ToString());
}
}
try
{
listLogic.LogicExpression = listLogic.LogicExpression.Replace("{", "").Replace("}", "");
var result = Eval.Execute<bool>(listLogic.LogicExpression);
if (result)
{
string telesignalisationredisKey = _redisDataRepository.TelesignalisationModelListRediskey + "_" + _settingModel.GetDatacatgoryName("无");
var yxData = _redisDataRepository.TelesignalisationModelListRedis.HashSetGetOne(telesignalisationredisKey, listLogic.TelesignalisationAddr);
yxData.ResultValue = yxData.RemoteType == RemoteTypeEnum.DoublePoint ? 2 : 1;
_webApiRequest.SendVisualYx(yxData);
}
MonitoringEventBus.LogHandler($"判定结果为{result} 判定表达式{listLogic.LogicExpression}", "二次回路遥信判定");
}
catch (Exception ex)
{
MonitoringEventBus.LogHandler(ex.Message, "错误信息");
}
}
}
try
{
var result = Eval.Execute<bool>(listLogic.LogicExpression);
if (result)
{
string telesignalisationredisKey = _redisDataRepository.TelesignalisationModelListRediskey + "_" + _settingModel.GetDatacatgoryName("无");
var yxData = _redisDataRepository.TelesignalisationModelListRedis.HashSetGetOne(telesignalisationredisKey, listLogic.TelesignalisationAddr);
yxData.ResultValue = yxData.RemoteType == RemoteTypeEnum.DoublePoint ? 2 : 1;
_webApiRequest.SendVisualYx(yxData);
}
}
catch (Exception ex)
{
MonitoringEventBus.LogHandler(ex.Message, "错误信息");
}
}
});
}
return default;
}
private Dictionary<TelesignalisationModel, DateTime> TelesignaleAlarmTempBuffDic = new Dictionary<TelesignalisationModel, DateTime>();
/// <summary>
/// 发送装置自检信息

View File

@ -173,7 +173,7 @@ namespace Yunda.ISAS.DataMonitoringServer.DataAnalysis
var list = _webApiRequest.GetSecondaryCircuitLogicExpressionList();
foreach (var item in list)
{
if (!ycCheckList.ContainsKey(item.TelemeteringConfigurationId.Value)|| yxSendList.ContainsKey(item.TelesignalisationConfigurationId.Value))
if (!ycCheckList.ContainsKey(item.TelemeteringConfigurationId.Value)|| !yxSendList.ContainsKey(item.TelesignalisationConfigurationId.Value))
{
Debug.WriteLine("错误,没有找到遥测/遥信");
continue;
@ -214,7 +214,7 @@ namespace Yunda.ISAS.DataMonitoringServer.DataAnalysis
string pattern1 = @"\{([^}]*)\}";
Regex regex1 = new Regex(pattern1);
// 提取匹配结果
MatchCollection matches = regex.Matches(item.LogicalExpression);
MatchCollection matches = regex1.Matches(item.LogicalExpression);
List<string> extractedValues = new List<string>();
var logicalExpression = $"({item.LogicalExpression})>={lowerLimit}&&({item.LogicalExpression})<={upperLimit}";
foreach (Match match in matches)

View File

@ -522,23 +522,27 @@ namespace Yunda.ISAS.DataMonitoringServer.DataAnalysis
/// <summary>
/// 初始遥信遥测redis列表
/// </summary>
public void InitYXYCRedisList(DataSourceCategoryEnum dataSourceCategory)
public async Task InitYXYCRedisList(DataSourceCategoryEnum dataSourceCategory)
{
try
{
var resObj = ToolLibrary
await _redisDataRepository.DeleCheckRedisCache();
await Task.Delay(10);
var resObj = ToolLibrary
.HttpHelper
.HttpGetRequest<JObject>
(ConstantModel
.RequestInitYXRedisListUri+ "?dataSourceCategory="+ (int)dataSourceCategory
);
await Task.Delay(10);
var resObj1 = ToolLibrary
.HttpHelper
.HttpGetRequest<JObject>
(ConstantModel
.RequestInitYCRedisListUri + "?dataSourceCategory=" + (int)dataSourceCategory
);
await Task.Delay(10);
var resObj2 = ToolLibrary
.HttpHelper
@ -546,13 +550,15 @@ namespace Yunda.ISAS.DataMonitoringServer.DataAnalysis
(ConstantModel
.RequestInitYCRedisListUri + "?dataSourceCategory=" + (int)DataSourceCategoryEnum.None
);
await Task.Delay(10);
var resObj3 = ToolLibrary
.HttpHelper
.HttpGetRequest<JObject>
(ConstantModel
.RequestInitYXRedisListUri + "?dataSourceCategory=" + (int)DataSourceCategoryEnum.None
);
await Task.Delay(200);
}
catch (Exception ex)
{

View File

@ -124,5 +124,21 @@ namespace Yunda.ISAS.DataMonitoringServer.DataCenter
var yxDatas = await TelesignalisationModelListRedis.HashSetGetAllAsync(redisKey);
return yxDatas;
}
public async Task DeleCheckRedisCache()
{
if (true)
{
string redisKey = TelemeteringModelListRediskey + "_" + _settingModel.GetDatacatgoryName("无"); ;
// 从 Redis 中批量获取所有遥测数据
await TelemeteringModelListRedis.DeleteKeyAsync(redisKey);
}
if (true)
{
string redisKey = TelesignalisationModelListRediskey + "_" + _settingModel.GetDatacatgoryName("无"); ;
// 从 Redis 中批量获取所有遥测数据
await TelesignalisationModelListRedis.DeleteKeyAsync(redisKey);
}
}
}
}

View File

@ -39,9 +39,9 @@ namespace Yunda.SOMS.DataMonitoringServer.FTPHandle
/// <param name="fileName">要下载的文件名</param>
/// <param name="localDirectory">本地保存路径</param>
/// <returns>返回下载的文件路径或上次保存的文件路径</returns>
public string GetFileFromFtp(string ftpHost, string fileapth, string fileName, string username = "root", string password = "root")
public string GetFileFromFtp(string ftpHost, string fileapth, string fileName, string deviceAddr,string username = "root", string password = "root")
{
string localFilePath = Path.Combine(localDirectory, fileName); // 本地保存文件的完整路径
string localFilePath = Path.Combine(localDirectory, deviceAddr, fileName); // 本地保存文件的完整路径
string remoteFilePath = Path.Combine(fileapth, fileName); // 远程FTP文件的路径
using (var client = new FtpClient(ftpHost, username, password))
{

View File

@ -115,7 +115,7 @@ namespace Yunda.SOMS.DataMonitoringServer.ProtectionDeviceHandle
string fileName = Path.GetFileName(result);
// 获取路径
string directoryPath = Path.GetDirectoryName(result);
var localFile = _ftpFile.GetFileFromFtp(device.GatewayIP1, directoryPath, fileName);
var localFile = _ftpFile.GetFileFromFtp(device.GatewayIP1, directoryPath, fileName, address.ToString());
if (File.Exists(localFile))
{

View File

@ -61,7 +61,7 @@ namespace Yunda.SOMS.DataMonitoringServer.ProtectionDeviceHandle
if (_commCount == 0)
{
var device = _devices.FirstOrDefault(t => t.DeviceAddr == address);
var localFile = _ftpFile.GetFileFromFtp(device.GatewayIP1, "/nor/root/status/", "status.txt");
var localFile = _ftpFile.GetFileFromFtp(device.GatewayIP1, "/nor/root/status/", "status.txt",address.ToString());
if (File.Exists(localFile))
{
var data = ParseDeviceStatus(localFile);

View File

@ -3,6 +3,7 @@ using DotNetty.Transport.Channels;
using MySqlX.XDevAPI;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
@ -25,7 +26,7 @@ namespace Yunda.SOMS.DataMonitoringServer.TcpSocket.Server
private IChannelHandlerContext _context;
// 定义事件,事件处理程序包含消息和功能描述
private readonly Dictionary<byte, IChannelHandlerContext> _connections;
private readonly ConcurrentDictionary<byte, IChannelHandlerContext> _connections;
private readonly Action<byte, byte[], byte> _onMessageReceived;
private readonly Action<byte> _onDeviceConnection;
@ -34,7 +35,7 @@ namespace Yunda.SOMS.DataMonitoringServer.TcpSocket.Server
Dictionary<byte, int[]> _deviceBoardStates = new Dictionary<byte, int[]>(); //0-离线 1-在线
public DotNettyServerHandler(Dictionary<byte, IChannelHandlerContext> connections,
public DotNettyServerHandler(ConcurrentDictionary<byte, IChannelHandlerContext> connections,
Action<byte, byte[], byte> onMessageReceived, Action<Dictionary<byte, int[]>> deviceBoardStatesAction)
{
_connections = connections;
@ -88,17 +89,20 @@ namespace Yunda.SOMS.DataMonitoringServer.TcpSocket.Server
_deviceBoardStates[deviceAddress][0] = 0;
MonitoringEventBus.LogHandler($"[{DateTime.Now}] {deviceAddress} 判定为离线(连续离线状态)", "定值错误信息");
await _connections[deviceAddress].CloseAsync();
_connections.Remove(deviceAddress);
_connections.TryRemove(deviceAddress, out IChannelHandlerContext channelHandlerContext);
continue;
}
// 检查是否超过10秒未更新
if ((DateTime.Now - device.LastUpdate).TotalSeconds > 10)
{
_deviceBoardStates[deviceAddress][0] = 0;
MonitoringEventBus.LogHandler($"[{DateTime.Now}] {deviceAddress} 判定为离线超过10秒未更新", "定值错误信息");
await _connections[deviceAddress].CloseAsync();
_connections.Remove(deviceAddress);
if (_connections.ContainsKey(deviceAddress))
{
_deviceBoardStates[deviceAddress][0] = 0;
MonitoringEventBus.LogHandler($"[{DateTime.Now}] {deviceAddress} 判定为离线超过10秒未更新", "定值错误信息");
await _connections[deviceAddress].CloseAsync();
_connections.TryRemove(deviceAddress, out IChannelHandlerContext channelHandlerContext);
}
continue;
}
_deviceBoardStates[deviceAddress][0] = 1;
@ -236,7 +240,7 @@ namespace Yunda.SOMS.DataMonitoringServer.TcpSocket.Server
else
{
_connections.Add(address, ctx);
_connections.TryAdd(address, ctx);
for (byte i = 1; i < 6; i++)
{
await SendCustomMessageAsync(ctx, address, 0, 5, i);

View File

@ -15,12 +15,13 @@ using System.Diagnostics;
using System.Windows.Media.Animation;
using YunDa.ISAS.Entities.System;
using Yunda.ISAS.DataMonitoringServer.DataAnalysis;
using System.Collections.Concurrent;
namespace Yunda.SOMS.DataMonitoringServer.TcpSocket.Server
{
public class DotNettyTcpServer : ISingletonDependency
{
private readonly Dictionary<byte, IChannelHandlerContext> connections = new Dictionary<byte, IChannelHandlerContext>();
private readonly ConcurrentDictionary<byte, IChannelHandlerContext> connections = new ConcurrentDictionary<byte, IChannelHandlerContext>();
// 定义 MessageReceived 事件
public event Action< byte, byte[], byte> MessageReceived; // 装置地址,功能码,消息
@ -137,7 +138,7 @@ namespace Yunda.SOMS.DataMonitoringServer.TcpSocket.Server
if (connections.TryGetValue(addr, out IChannelHandlerContext context))
{
context.CloseAsync(); // 关闭连接
connections.Remove(addr); // 从字典中移除该连接
connections.TryRemove(addr,out IChannelHandlerContext channelHandlerContext); // 从字典中移除该连接
Debug.WriteLine($"断开 地址 为 {addr} 的连接");
}
else

View File

@ -260,7 +260,7 @@ namespace Yunda.SOMS.DataMonitoringServer.WPF.View
string filepath = "/nor/root/commcpu/cfg/";
// 调用函数并传入文件名
string fileName = "iodb_tp1.sql3"; // 传入的文件名
string localFile = _ftpFile. GetFileFromFtp(ftpBaseUrl, ftpUsername, ftpPassword, filepath, fileName);
string localFile = _ftpFile. GetFileFromFtp(ftpBaseUrl, ftpUsername, ftpPassword, "1000",filepath, fileName);
IODataHandle commDataHandle = new IODataHandle();
var data = commDataHandle.GetIODataDic(localFile);
//DisplayData(dictionary: data.Item2 );

View File

@ -245,7 +245,7 @@ namespace Yunda.ISAS.DataMonitoringServer.WPF.ViewModel
try
{
_showMsgActionBlock.Post(new Recoder() { MsgType = "启动信息", Msg = "开始连接远动机,请不要重复点击开始按钮,请稍等....", DateTime = DateTime.Now });
_webApiRequest.UpdateMonitorServerAddressById();
Task.Run(()=> _webApiRequest.UpdateMonitorServerAddressById()) ;
_webApiRequest.InitYXYCRedisList((DataSourceCategoryEnum)SettingModel.GetDatacatgoryValue(SettingModel.DataSourceCategoryName));
monitoringDataService.DataServiceStart(settingModel);
IsRunning = true;

View File

@ -45,19 +45,8 @@ class Subscriber
// 解析 JSON 消息
var entity = MessagePackSerializer.Deserialize<Dictionary<string, object>>(message, MessagePack.Resolvers.ContractlessStandardResolver.Options);
try
{
Console.WriteLine("解析到的键值对:");
foreach (var kvp in entity)
{
Console.WriteLine($"{kvp.Key}: {kvp.Value}");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
ProcessDictionary(entity);
});
@ -66,7 +55,31 @@ class Subscriber
conmper.Dispose();
}
static void ProcessDictionary(Dictionary<string, object> dictionary)
{
foreach (var kvp in dictionary)
{
Console.Write($"{kvp.Key}: ");
if (kvp.Value is byte[] nestedMessagePack)
{
try
{
// 进一步解析嵌套的 MessagePack 数据
var nestedDict = MessagePackSerializer.Deserialize<Dictionary<string, object>>(nestedMessagePack, MessagePack.Resolvers.ContractlessStandardResolver.Options);
Console.WriteLine();
ProcessDictionary(nestedDict); // 递归解析
}
catch
{
Console.WriteLine("(嵌套内容无法解析)");
}
}
else
{
Console.WriteLine(kvp.Value);
}
}
}
public class Message
{
public string name { get; set; }