namespace ClassNotify.Shared.Models; /// /// 终端自检批次流程运行状态 (RunState) /// 严格独立于健康状态 (OverallStatus) /// public static class SelfCheckRunStates { public const string PendingDispatch = "PendingDispatch"; public const string Dispatched = "Dispatched"; public const string Completed = "Completed"; public const string Unreachable = "Unreachable"; public const string TimedOut = "TimedOut"; public static readonly string[] All = [PendingDispatch, Dispatched, Completed, Unreachable, TimedOut]; public static bool IsTerminal(string state) => state is Completed or Unreachable or TimedOut; } /// /// 7 项标准探针键规范化与映射 /// public static class SelfCheckProbeKeys { public const string Service = "service"; public const string SignalR = "signalr"; public const string HttpsPing = "https_ping"; public const string ClockOffset = "clock_offset"; public const string IpcPipe = "ipc_pipe"; public const string WpfClient = "wpf_client"; public const string TtsEngine = "tts_engine"; public static readonly string[] All = [ Service, SignalR, HttpsPing, ClockOffset, IpcPipe, WpfClient, TtsEngine ]; public static string Normalize(string probeName) { if (string.IsNullOrWhiteSpace(probeName)) return string.Empty; var p = probeName.Trim().ToLowerInvariant().Replace(" ", "_").Replace("-", "_"); return p switch { "service" => Service, "signalr" => SignalR, "https" or "https_ping" or "httpsping" => HttpsPing, "clock" or "clock_offset" or "clockoffset" => ClockOffset, "ipc" or "ipc_pipe" or "named_pipe" or "pipe" => IpcPipe, "wpf" or "wpf_client" or "wpfclient" or "client" => WpfClient, "tts" or "tts_engine" or "ttsengine" => TtsEngine, _ => p }; } } /// /// 发起批量设备自检请求载荷 /// public class CreateSelfCheckBatchRequest { public string ClientRequestId { get; set; } = string.Empty; public List DeviceIds { get; set; } = new(); } /// /// 批量自检创建成功返回 DTO /// public class SelfCheckBatchCreatedDto { public string BatchId { get; set; } = string.Empty; public string Status { get; set; } = "Running"; public int TargetDeviceCount { get; set; } public DateTimeOffset CreatedAtUtc { get; set; } public DateTimeOffset DeadlineAtUtc { get; set; } } /// /// 批次总体健康与完成度统计(纯内存聚合计算,严格守恒) /// public class SelfCheckBatchSummaryDto { public string BatchId { get; set; } = string.Empty; public string Status { get; set; } = string.Empty; public int Target { get; set; } public int Pending { get; set; } public int Completed { get; set; } public int Healthy { get; set; } public int Warning { get; set; } public int Failed { get; set; } public int Unreachable { get; set; } public int TimedOut { get; set; } public DateTimeOffset CreatedAtUtc { get; set; } public DateTimeOffset? CompletedAtUtc { get; set; } } /// /// 单项探针故障聚合统计 /// public class ProbeFailureCountDto { public string Probe { get; set; } = string.Empty; public int WarningCount { get; set; } public int FailedCount { get; set; } } /// /// 批次详情响应载荷 /// public class SelfCheckBatchDetailDto { public string BatchId { get; set; } = string.Empty; public string Status { get; set; } = string.Empty; public DateTimeOffset CreatedAtUtc { get; set; } public DateTimeOffset DeadlineAtUtc { get; set; } public DateTimeOffset? CompletedAtUtc { get; set; } public SelfCheckBatchSummaryDto Summary { get; set; } = new(); public List ProbeFailures { get; set; } = new(); } /// /// 批次下设备自检运行项目简要信息 /// public class SelfCheckBatchDeviceItemDto { public string RunId { get; set; } = string.Empty; public string DeviceId { get; set; } = string.Empty; public string TenantId { get; set; } = string.Empty; public string SchoolName { get; set; } = string.Empty; public string ClassroomId { get; set; } = string.Empty; public string ClassroomName { get; set; } = string.Empty; public string Hostname { get; set; } = string.Empty; public bool IsOnline { get; set; } public string? ServiceVersion { get; set; } public string? ClientVersion { get; set; } public string RunState { get; set; } = string.Empty; public string? OverallStatus { get; set; } public List Checks { get; set; } = new(); public DateTimeOffset RequestedAtUtc { get; set; } public DateTimeOffset? DispatchedAtUtc { get; set; } public DateTimeOffset? CompletedAtUtc { get; set; } public string CorrelationId { get; set; } = string.Empty; } /// /// 设备明细过滤与分页查询参数 /// public class SelfCheckBatchDeviceQuery { public string? Health { get; set; } // Healthy, Warning, Failed, Unreachable, TimedOut, Pending public string? Probe { get; set; } // ipc_pipe, clock_offset, etc. public string? TenantId { get; set; } public string? Q { get; set; } public int Page { get; set; } = 1; public int PageSize { get; set; } = 50; } /// /// 设备明细分页返回结果 /// public class SelfCheckBatchDevicePagedResultDto { public int Total { get; set; } public int Page { get; set; } public int PageSize { get; set; } public List Items { get; set; } = new(); } /// /// 下发到终端的批量自检指令载荷 /// public class DeviceSelfCheckCommandDto { public string SelfCheckId { get; set; } = string.Empty; public string BatchId { get; set; } = string.Empty; public string CorrelationId { get; set; } = string.Empty; public DateTimeOffset RequestedAtUtc { get; set; } public DateTimeOffset DeadlineAtUtc { get; set; } }