1、巡检结果时间不

2、与二维状态不对
3、发送遥测命令太长
This commit is contained in:
qsp89 2025-11-21 18:07:07 +08:00
parent 43dd5a32e4
commit 01fed80784
6 changed files with 111 additions and 11 deletions

View File

@ -1236,6 +1236,12 @@
</summary>
<returns></returns>
</member>
<member name="M:YunDa.SOMS.MongoDB.Application.Inspection.InspectionItemResultAppService.TestGetAlarmMessage(System.String,System.String,System.String)">
<summary>
测试报警api
</summary>
<returns></returns>
</member>
<member name="M:YunDa.SOMS.MongoDB.Application.Inspection.InspectionItemResultAppService.GetAlarmMessage(System.Nullable{System.Guid},System.Int32,System.String)">
<summary>
获取报警信息

View File

@ -255,6 +255,49 @@ namespace YunDa.Server.ISMSTcp.Controllers
return StatusCode(500, $"服务器内部错误: {ex.Message}");
}
private List<string> GetValidZzCmd(string cmdName, List<string> ids)
{
const int maxLength = 250;
var cmds = new List<string>();
// 开始构建
string prefix = cmdName + "|"; // 固定前缀
int prefixLength = prefix.Length;
var currentIds = new List<string>();
int currentLength = prefixLength; // 当前命令的长度(含前缀)
foreach (var id in ids)
{
// 如果添加这个ID会超长则先生成一个命令
int idLength = (currentIds.Count == 0 ? id.Length : (1 + id.Length)); // 第一个ID不需要 '#'
if (currentLength + idLength > maxLength)
{
// 将当前批次加入 cmds
cmds.Add(prefix + string.Join("#", currentIds));
// 清空并重建
currentIds.Clear();
currentLength = prefixLength;
}
// 添加新的 ID
currentIds.Add(id);
currentLength += idLength;
}
// 收尾:如果还有剩余 IDs生成最后一个命令
if (currentIds.Count > 0)
{
cmds.Add(prefix + string.Join("#", currentIds));
}
return cmds;
}
/// <summary>
/// 根据数据ID召唤遥测数据
/// </summary>
@ -282,9 +325,11 @@ namespace YunDa.Server.ISMSTcp.Controllers
id.RemoveAll(string.IsNullOrWhiteSpace);
string cmd = string.Format("CallYCByDataID|{0}", string.Join("#", id));
//string cmd = string.Format("CallYCByDataID|{0}", string.Join("#", id));
System.Console.WriteLine($"发送遥测命令:{cmd}");
//System.Console.WriteLine($"发送遥测命令:{cmd}");
var cmds = GetValidZzCmd("CallYCByDataID", id);
try
{
@ -299,7 +344,7 @@ namespace YunDa.Server.ISMSTcp.Controllers
});
}
_logger.LogInformation("收到遥测数据召唤请求 - cmd: {cmd}", cmd);
_logger.LogInformation("收到遥测数据召唤请求 - cmd: {cmd}", string.Join("#", id));
// 发送TCP消息
DateTime cmdTime = DateTime.Now;
@ -310,8 +355,23 @@ namespace YunDa.Server.ISMSTcp.Controllers
{
for (int i = 0; i < times; i++)
{
var sendResult = await SendTcpMessageAsync(cmd, cancellationToken);
if (sendResult.Success)
bool isSuccess = true;
foreach (var cmd in cmds)
{
var sendResult = await SendTcpMessageAsync(cmd, cancellationToken);
isSuccess &= sendResult.Success;
if (!isSuccess)
{
break;
}
else
{
await Task.Delay(5);
}
}
if (isSuccess)
{
sucessCount++;
}
@ -375,7 +435,7 @@ namespace YunDa.Server.ISMSTcp.Controllers
}
catch (OperationCanceledException)
{
_logger.LogWarning("遥测数据召唤请求被取消 - cmd: {cmd}", cmd);
_logger.LogWarning("遥测数据召唤请求被取消 - cmd: {cmd}", string.Join("#", id));
return StatusCode(504, new
{
success = false,
@ -385,7 +445,7 @@ namespace YunDa.Server.ISMSTcp.Controllers
}
catch (Exception ex)
{
_logger.LogError(ex, "处理遥测数据召唤请求时发生异常 - cmd: {cmd}", cmd);
_logger.LogError(ex, "处理遥测数据召唤请求时发生异常 - cmd: {cmd}", string.Join("#", id));
return StatusCode(500, new
{
success = false,

View File

@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -919,6 +920,19 @@ namespace YunDa.Server.ISMSTcp.Domain
var result = ExtractDataFromAbpResponse<List<OpticalFiberConfigModel>>(response);
//List<string> ids = new List<string>();
//foreach(var item in result)
//{
// ids.AddRange(item.VirtualPointCodes);
// ids.AddRange(item.LinkageDatas);
// ids.AddRange(item.LogicalExpressions);
//}
// var ids2 = ids.Where(id => id.Contains("YXB")).ToList().Distinct().ToList();
//Debug.WriteLine(string.Join("#", ids2));
return result;
}
}
@ -945,6 +959,18 @@ namespace YunDa.Server.ISMSTcp.Domain
var result = ExtractDataFromAbpResponse<List<OpticalFiberConfigModel>>(response);
//List<string> ids = new List<string>();
//foreach (var item in result)
//{
// ids.AddRange(item.VirtualPointCodes);
// ids.AddRange(item.LinkageDatas);
// ids.AddRange(item.LogicalExpressions);
//}
//var ids2 = ids.Where(id => id.Contains("YXB")).ToList().Distinct().ToList();
//Debug.WriteLine(string.Join("#", ids2));
return result;
}
}

View File

@ -133,7 +133,7 @@ namespace YunDa.Server.ISMSTcp.Services
public string SecondaryCircuitInspectionItemId { get; set; } = string.Empty;
public string InspectionPlanId { get; set; } = string.Empty;
public DateTime ExecutionTime { get; set; } = DateTime.Now;
public string ExecutionTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
public long ExecutionDurationMs { get; set; }

View File

@ -140,6 +140,7 @@ namespace YunDa.Server.ISMSTcp.Services
// 这里使用模型中的地址信息
string haskey = $"{model.DeviceAddress}_0_{model.DispatcherAddress}_0";
if (_yxIdToHashKeyMapping.TryAdd(model.ismsbaseYXId, haskey))
{
mappingCount++;

View File

@ -805,6 +805,13 @@ namespace YunDa.Server.ISMSTcp.Services
/******************网线、光纤、光缆*****************/
private static bool IsYxValueAlarm(string valStr)
{
string[] err = { "分", "未同步", "告警", "异常", "断", "未就绪", "无效", "异常", "未复归", "动作", "检修", "未储能", "跳闸", "失步", "分位" };
return err.Contains(valStr);
}
//更新网线配置
private async Task UpdateNetworkCableConfig()
{
@ -863,7 +870,7 @@ namespace YunDa.Server.ISMSTcp.Services
alertData.Parse(
configItem.TwinId,
2,
item.ResultValue == 1,
IsYxValueAlarm(item.ResultValueStr),
$"{configItem.P1DeviceName}{configItem.P2DeviceName}",
"网线断线",
item.ResultTime.ToString("yyyy-MM-dd HH:mm:ss")
@ -1020,7 +1027,7 @@ namespace YunDa.Server.ISMSTcp.Services
alertData.Parse(
configItem.TwinId,
2,
item.ResultValue == 1,
IsYxValueAlarm(item.ResultValueStr),
$"{configItem.P1DeviceName}{configItem.P2DeviceName}",
"光纤断线",
item.ResultTime.ToString("yyyy-MM-dd HH:mm:ss")
@ -1188,7 +1195,7 @@ namespace YunDa.Server.ISMSTcp.Services
alertData.Parse(
configItem.TwinId,
2,
item.ResultValue == 1,
IsYxValueAlarm(item.ResultValueStr),
$"{configItem.P1CabinetName}{configItem.P2CabinetName}",
"光缆断线",
item.ResultTime.ToString("yyyy-MM-dd HH:mm:ss")