修复 Bug

This commit is contained in:
2026-01-17 13:13:17 +08:00
parent a27045e0a0
commit 8482996a94
10 changed files with 177 additions and 59 deletions

View File

@@ -44,8 +44,61 @@ public class DeviceConfigHandler : ICommandHandler
var device = _cameraManager.GetDevice(dto.Id);
string op = device != null ? "更新" : "新增";
_sysLog.Warning($"[Sync] 即将{op}设备配置 => ID:{dto.Id} Name:{dto.Name} IP:{dto.IpAddress} Port:{dto.Port} Brand:{(DeviceBrand)dto.Brand} Rtsp:{dto.RtspPath}");
_sysLog.Debug($"[Sync] 即将{op}设备配置 => ID:{dto.Id} Name:{dto.Name} IP:{dto.IpAddress} 详情:" + "{@dto}", dto, dto.AutoSubscriptions);
string changeSummary = string.Empty;
if (device != null)
{
var old = device.Config;
var sb = new System.Text.StringBuilder();
// 1. 物理参数审计 (冷更新判定)
if (dto.IpAddress != old.IpAddress) sb.Append($"IP:{old.IpAddress}->{dto.IpAddress}; ");
if (dto.Port != old.Port) sb.Append($"Port:{old.Port}->{dto.Port}; ");
if (dto.Username != old.Username) sb.Append($"User:{old.Username}->{dto.Username}; ");
if (dto.Password != old.Password) sb.Append("密码:[已变更]; ");
if (dto.ChannelIndex != old.ChannelIndex) sb.Append($"通道:{old.ChannelIndex}->{dto.ChannelIndex}; ");
// 2. 运行意图审计 (播放/停止)
// Modified: 明确呈现播放状态的切换
if (dto.ImmediateExecution != device.IsRunning)
sb.Append($"运行状态:{(device.IsRunning ? "" : "")}->{(dto.ImmediateExecution ? "" : "")}; ");
// 3. 图像参数审计
if (dto.StreamType != old.StreamType) sb.Append($"码流:{old.StreamType}->{dto.StreamType}; ");
if (dto.UseGrayscale) sb.Append("灰度模式:开启; ");
// 4. 订阅策略深度审计 (使用新增的强类型方法)
// Optimized: 通过 AppId 匹配,找出 FPS 变动
if (dto.AutoSubscriptions != null)
{
var currentReqs = device.Controller?.GetRequirements();
if (currentReqs != null)
{
foreach (var newSub in dto.AutoSubscriptions)
{
var matched = currentReqs.FirstOrDefault(x => x.AppId == newSub.AppId);
if (matched != null)
{
if (matched.TargetFps != newSub.TargetFps || (int)matched.Type != newSub.Type)
{
sb.Append($"[订阅变动:{newSub.AppId}] FPS:{matched.TargetFps}->{newSub.TargetFps}; ");
}
}
else
{
sb.Append($"[新增订阅:{newSub.AppId}] FPS:{newSub.TargetFps}; ");
}
}
}
}
changeSummary = sb.Length > 0 ? $" | 变更明目: {sb.ToString().TrimEnd(' ', ';')}" : " | 配置一致";
}
_sysLog.Information($"[Sync] 即将{op}设备配置, 新配置 => ID:{dto.Id} Name:{dto.Name} IP:{dto.IpAddress} Port:{dto.Port} Brand:{(DeviceBrand)dto.Brand} Rtsp:{dto.RtspPath}");
_sysLog.Debug($"[Sync] 即将{op}设备配置, 新配置 => ID:{dto.Id} Name:{dto.Name} IP:{dto.IpAddress} 详情:" + "{@dto}", dto, dto.AutoSubscriptions);
if (!string.IsNullOrEmpty(changeSummary))
_sysLog.Warning($"[Sync] 即将{op}设备配置, ID:{dto.Id} 变更项 => {changeSummary}");
if (device != null)
{