using OrpaonVision.Core.Results;
namespace OrpaonVision.Core.AlarmSystem;
///
/// 异常报警系统服务接口。
///
public interface IAlarmSystemService
{
///
/// 触发报警。
///
/// 报警请求。
/// 取消令牌。
/// 报警结果。
Task> TriggerAlarmAsync(AlarmRequest alarmRequest, CancellationToken cancellationToken = default);
///
/// 确认报警。
///
/// 报警ID。
/// 确认用户。
/// 确认备注。
/// 取消令牌。
/// 确认结果。
Task> ConfirmAlarmAsync(Guid alarmId, string confirmUser, string? confirmNote = null, CancellationToken cancellationToken = default);
///
/// 清除报警。
///
/// 报警ID。
/// 清除用户。
/// 清除备注。
/// 取消令牌。
/// 清除结果。
Task> ClearAlarmAsync(Guid alarmId, string clearUser, string? clearNote = null, CancellationToken cancellationToken = default);
///
/// 获取报警栈。
///
/// 栈类型。
/// 最大数量。
/// 取消令牌。
/// 报警栈。
Task>> GetAlarmStackAsync(AlarmStackType stackType, int maxCount = 100, CancellationToken cancellationToken = default);
///
/// 获取活跃报警。
///
/// 取消令牌。
/// 活跃报警列表。
Task>> GetActiveAlarmsAsync(CancellationToken cancellationToken = default);
///
/// 获取报警历史。
///
/// 开始时间。
/// 结束时间。
/// 报警级别(可选)。
/// 取消令牌。
/// 报警历史。
Task>> GetAlarmHistoryAsync(DateTime startTime, DateTime endTime, AlarmLevel? alarmLevel = null, CancellationToken cancellationToken = default);
///
/// 获取报警统计信息。
///
/// 开始时间。
/// 结束时间。
/// 取消令牌。
/// 统计信息。
Task> GetAlarmStatisticsAsync(DateTime startTime, DateTime endTime, CancellationToken cancellationToken = default);
///
/// 批量确认报警。
///
/// 报警ID列表。
/// 确认用户。
/// 确认备注。
/// 取消令牌。
/// 批量确认结果。
Task> BatchConfirmAlarmsAsync(IReadOnlyList alarmIds, string confirmUser, string? confirmNote = null, CancellationToken cancellationToken = default);
///
/// 批量清除报警。
///
/// 报警ID列表。
/// 清除用户。
/// 清除备注。
/// 取消令牌。
/// 批量清除结果。
Task> BatchClearAlarmsAsync(IReadOnlyList alarmIds, string clearUser, string? clearNote = null, CancellationToken cancellationToken = default);
///
/// 创建报警规则。
///
/// 报警规则。
/// 取消令牌。
/// 创建结果。
Task> CreateAlarmRuleAsync(AlarmRule rule, CancellationToken cancellationToken = default);
///
/// 更新报警规则。
///
/// 报警规则。
/// 取消令牌。
/// 更新结果。
Task UpdateAlarmRuleAsync(AlarmRule rule, CancellationToken cancellationToken = default);
///
/// 删除报警规则。
///
/// 规则ID。
/// 取消令牌。
/// 删除结果。
Task DeleteAlarmRuleAsync(Guid ruleId, CancellationToken cancellationToken = default);
///
/// 获取报警规则列表。
///
/// 是否启用(可选)。
/// 取消令牌。
/// 规则列表。
Task>> GetAlarmRulesAsync(bool? isEnabled = null, CancellationToken cancellationToken = default);
///
/// 检查报警条件。
///
/// 条件检查请求。
/// 取消令牌。
/// 检查结果。
Task>> CheckAlarmConditionsAsync(AlarmConditionCheckRequest conditionCheckRequest, CancellationToken cancellationToken = default);
///
/// 获取报警恢复状态。
///
/// 报警ID。
/// 取消令牌。
/// 恢复状态。
Task> GetAlarmRecoveryStatusAsync(Guid alarmId, CancellationToken cancellationToken = default);
///
/// 设置报警恢复状态。
///
/// 恢复请求。
/// 取消令牌。
/// 设置结果。
Task> SetAlarmRecoveryStatusAsync(AlarmRecoveryRequest recoveryRequest, CancellationToken cancellationToken = default);
}
///
/// 报警请求。
///
public sealed class AlarmRequest
{
///
/// 请求ID。
///
public Guid RequestId { get; init; }
///
/// 报警类型。
///
public AlarmType AlarmType { get; init; }
///
/// 报警级别。
///
public AlarmLevel AlarmLevel { get; init; }
///
/// 报警标题。
///
public string Title { get; init; } = string.Empty;
///
/// 报警描述。
///
public string Description { get; init; } = string.Empty;
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 会话ID。
///
public string SessionId { get; init; } = string.Empty;
///
/// 相关层级。
///
public int? RelatedLayer { get; init; }
///
/// 相关部件。
///
public string? RelatedPart { get; init; }
///
/// 报警源。
///
public string Source { get; init; } = string.Empty;
///
/// 报警数据。
///
public object? AlarmData { get; init; }
///
/// 是否需要确认。
///
public bool RequiresConfirmation { get; init; } = true;
///
/// 是否自动清除。
///
public bool AutoClear { get; init; } = false;
///
/// 自动清除时间(秒)。
///
public int AutoClearAfterSeconds { get; init; } = 0;
///
/// 报警标签。
///
public IReadOnlyList Tags { get; init; } = Array.Empty();
///
/// 请求时间。
///
public DateTime RequestTimeUtc { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 报警结果。
///
public sealed class AlarmResult
{
///
/// 报警ID。
///
public Guid AlarmId { get; init; }
///
/// 请求ID。
///
public Guid RequestId { get; init; }
///
/// 是否成功触发。
///
public bool IsTriggered { get; init; }
///
/// 报警状态。
///
public AlarmStatus AlarmStatus { get; init; }
///
/// 触发时间。
///
public DateTime TriggerTimeUtc { get; init; }
///
/// 触发耗时(毫秒)。
///
public long TriggerElapsedMs { get; init; }
///
/// 报警级别。
///
public AlarmLevel AlarmLevel { get; init; }
///
/// 报警栈位置。
///
public int StackPosition { get; init; }
///
/// 是否重复报警。
///
public bool IsDuplicate { get; init; }
///
/// 重复报警数量。
///
public int DuplicateCount { get; init; }
///
/// 结果描述。
///
public string? ResultDescription { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 报警确认结果。
///
public sealed class AlarmConfirmResult
{
///
/// 报警ID。
///
public Guid AlarmId { get; init; }
///
/// 是否成功确认。
///
public bool IsConfirmed { get; init; }
///
/// 确认时间。
///
public DateTime ConfirmTimeUtc { get; init; }
///
/// 确认用户。
///
public string ConfirmUser { get; init; } = string.Empty;
///
/// 确认备注。
///
public string? ConfirmNote { get; init; }
///
/// 确认前状态。
///
public AlarmStatus PreviousStatus { get; init; }
///
/// 确认后状态。
///
public AlarmStatus NewStatus { get; init; }
///
/// 结果描述。
///
public string? ResultDescription { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 报警清除结果。
///
public sealed class AlarmClearResult
{
///
/// 报警ID。
///
public Guid AlarmId { get; init; }
///
/// 是否成功清除。
///
public bool IsCleared { get; init; }
///
/// 清除时间。
///
public DateTime ClearTimeUtc { get; init; }
///
/// 清除用户。
///
public string ClearUser { get; init; } = string.Empty;
///
/// 清除备注。
///
public string? ClearNote { get; init; }
///
/// 清除前状态。
///
public AlarmStatus PreviousStatus { get; init; }
///
/// 清除后状态。
///
public AlarmStatus NewStatus { get; init; }
///
/// 结果描述。
///
public string? ResultDescription { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 批量报警确认结果。
///
public sealed class BatchAlarmConfirmResult
{
///
/// 确认结果列表。
///
public IReadOnlyList ConfirmResults { get; init; } = Array.Empty();
///
/// 总报警数量。
///
public int TotalAlarms { get; init; }
///
/// 成功确认数量。
///
public int ConfirmedCount { get; init; }
///
/// 失败确认数量。
///
public int FailedCount { get; init; }
///
/// 确认用户。
///
public string ConfirmUser { get; init; } = string.Empty;
///
/// 批量操作时间。
///
public DateTime BatchOperationTimeUtc { get; init; }
///
/// 总耗时(毫秒)。
///
public long TotalElapsedMs { get; init; }
///
/// 结果描述。
///
public string? ResultDescription { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 批量报警清除结果。
///
public sealed class BatchAlarmClearResult
{
///
/// 清除结果列表。
///
public IReadOnlyList ClearResults { get; init; } = Array.Empty();
///
/// 总报警数量。
///
public int TotalAlarms { get; init; }
///
/// 成功清除数量。
///
public int ClearedCount { get; init; }
///
/// 失败清除数量。
///
public int FailedCount { get; init; }
///
/// 清除用户。
///
public string ClearUser { get; init; } = string.Empty;
///
/// 批量操作时间。
///
public DateTime BatchOperationTimeUtc { get; init; }
///
/// 总耗时(毫秒)。
///
public long TotalElapsedMs { get; init; }
///
/// 结果描述。
///
public string? ResultDescription { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 报警。
///
public sealed class Alarm
{
///
/// 报警ID。
///
public Guid AlarmId { get; init; }
///
/// 报警类型。
///
public AlarmType AlarmType { get; init; }
///
/// 报警级别。
///
public AlarmLevel AlarmLevel { get; init; }
///
/// 报警标题。
///
public string Title { get; init; } = string.Empty;
///
/// 报警描述。
///
public string Description { get; init; } = string.Empty;
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 会话ID。
///
public string SessionId { get; init; } = string.Empty;
///
/// 相关层级。
///
public int? RelatedLayer { get; init; }
///
/// 相关部件。
///
public string? RelatedPart { get; init; }
///
/// 报警源。
///
public string Source { get; init; } = string.Empty;
///
/// 报警数据。
///
public object? AlarmData { get; init; }
///
/// 报警状态。
///
public AlarmStatus AlarmStatus { get; init; }
///
/// 触发时间。
///
public DateTime TriggerTimeUtc { get; init; }
///
/// 确认时间。
///
public DateTime? ConfirmTimeUtc { get; init; }
///
/// 清除时间。
///
public DateTime? ClearTimeUtc { get; init; }
///
/// 确认用户。
///
public string? ConfirmUser { get; init; }
///
/// 清除用户。
///
public string? ClearUser { get; init; }
///
/// 确认备注。
///
public string? ConfirmNote { get; init; }
///
/// 清除备注。
///
public string? ClearNote { get; init; }
///
/// 报警标签。
///
public IReadOnlyList Tags { get; init; } = Array.Empty();
///
/// 报警栈位置。
///
public int StackPosition { get; init; }
///
/// 重复报警数量。
///
public int DuplicateCount { get; init; }
///
/// 是否重复报警。
///
public bool IsDuplicate { get; init; }
///
/// 原报警ID(重复报警时)。
///
public Guid? OriginalAlarmId { get; init; }
///
/// 恢复状态。
///
public AlarmRecoveryStatus? RecoveryStatus { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 报警统计信息。
///
public sealed class AlarmStatistics
{
///
/// 总报警数量。
///
public int TotalAlarms { get; init; }
///
/// 活跃报警数量。
///
public int ActiveAlarms { get; init; }
///
/// 已确认报警数量。
///
public int ConfirmedAlarms { get; init; }
///
/// 已清除报警数量。
///
public int ClearedAlarms { get; init; }
///
/// 按报警类型分组的统计。
///
public Dictionary ByAlarmType { get; init; } = new();
///
/// 按报警级别分组的统计。
///
public Dictionary ByAlarmLevel { get; init; } = new();
///
/// 按报警状态分组的统计。
///
public Dictionary ByAlarmStatus { get; init; } = new();
///
/// 按产品类型分组的统计。
///
public Dictionary ByProductType { get; init; } = new();
///
/// 按报警源分组的统计。
///
public Dictionary ByAlarmSource { get; init; } = new();
///
/// 重复报警统计。
///
public DuplicateAlarmStatistics DuplicateAlarms { get; init; } = new();
///
/// 平均确认时间(分钟)。
///
public double AverageConfirmTimeMinutes { get; init; }
///
/// 平均清除时间(分钟)。
///
public double AverageClearTimeMinutes { get; init; }
///
/// 统计开始时间。
///
public DateTime StartTimeUtc { get; init; }
///
/// 统计结束时间。
///
public DateTime EndTimeUtc { get; init; }
}
///
/// 报警类型统计。
///
public sealed class AlarmTypeStatistics
{
///
/// 报警类型。
///
public AlarmType AlarmType { get; init; }
///
/// 报警数量。
///
public int AlarmCount { get; init; }
///
/// 占比。
///
public double Percentage { get; init; }
///
/// 平均级别。
///
public double AverageLevel { get; init; }
}
///
/// 报警级别统计。
///
public sealed class AlarmLevelStatistics
{
///
/// 报警级别。
///
public AlarmLevel AlarmLevel { get; init; }
///
/// 报警数量。
///
public int AlarmCount { get; init; }
///
/// 占比。
///
public double Percentage { get; init; }
}
///
/// 报警状态统计。
///
public sealed class AlarmStatusStatistics
{
///
/// 报警状态。
///
public AlarmStatus AlarmStatus { get; init; }
///
/// 报警数量。
///
public int AlarmCount { get; init; }
///
/// 占比。
///
public double Percentage { get; init; }
}
///
/// 产品类型报警统计。
///
public sealed class ProductTypeAlarmStatistics
{
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 报警数量。
///
public int AlarmCount { get; init; }
///
/// 占比。
///
public double Percentage { get; init; }
///
/// 平均级别。
///
public double AverageLevel { get; init; }
}
///
/// 报警源统计。
///
public sealed class AlarmSourceStatistics
{
///
/// 报警源。
///
public string AlarmSource { get; init; } = string.Empty;
///
/// 报警数量。
///
public int AlarmCount { get; init; }
///
/// 占比。
///
public double Percentage { get; init; }
}
///
/// 重复报警统计。
///
public sealed class DuplicateAlarmStatistics
{
///
/// 重复报警数量。
///
public int DuplicateAlarmCount { get; init; }
///
/// 重复报警占比。
///
public double DuplicatePercentage { get; init; }
///
/// 平均重复次数。
///
public double AverageDuplicateCount { get; init; }
}
///
/// 报警规则。
///
public sealed class AlarmRule
{
///
/// 规则ID。
///
public Guid RuleId { get; init; }
///
/// 规则名称。
///
public string RuleName { get; init; } = string.Empty;
///
/// 规则描述。
///
public string RuleDescription { get; init; } = string.Empty;
///
/// 报警类型。
///
public AlarmType AlarmType { get; init; }
///
/// 报警级别。
///
public AlarmLevel AlarmLevel { get; init; }
///
/// 触发条件。
///
public string TriggerCondition { get; init; } = string.Empty;
///
/// 触发阈值。
///
public double TriggerThreshold { get; init; }
///
/// 比较操作符。
///
public ComparisonOperator ComparisonOperator { get; init; }
///
/// 是否启用。
///
public bool IsEnabled { get; init; } = true;
///
/// 是否需要确认。
///
public bool RequiresConfirmation { get; init; } = true;
///
/// 是否自动清除。
///
public bool AutoClear { get; init; } = false;
///
/// 自动清除时间(秒)。
///
public int AutoClearAfterSeconds { get; init; } = 0;
///
/// 优先级。
///
public int Priority { get; init; } = 1;
///
/// 创建时间。
///
public DateTime CreatedAtUtc { get; init; }
///
/// 更新时间。
///
public DateTime UpdatedAtUtc { get; init; }
///
/// 版本号。
///
public string Version { get; init; } = "1.0";
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 报警条件检查请求。
///
public sealed class AlarmConditionCheckRequest
{
///
/// 检查上下文。
///
public object CheckContext { get; init; } = new();
///
/// 检查的规则ID列表(可选,不指定则检查所有启用的规则)。
///
public IReadOnlyList? RuleIds { get; init; }
///
/// 产品类型编码。
///
public string ProductTypeCode { get; init; } = string.Empty;
///
/// 会话ID。
///
public string SessionId { get; init; } = string.Empty;
///
/// 检查时间。
///
public DateTime CheckTimeUtc { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 报警条件检查结果。
///
public sealed class AlarmConditionCheckResult
{
///
/// 规则ID。
///
public Guid RuleId { get; init; }
///
/// 规则名称。
///
public string RuleName { get; init; } = string.Empty;
///
/// 是否触发报警。
///
public bool ShouldTriggerAlarm { get; init; }
///
/// 实际值。
///
public double ActualValue { get; init; }
///
/// 阈值。
///
public double Threshold { get; init; }
///
/// 检查时间。
///
public DateTime CheckTimeUtc { get; init; }
///
/// 检查详情。
///
public string? CheckDetails { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 报警恢复状态。
///
public sealed class AlarmRecoveryStatus
{
///
/// 报警ID。
///
public Guid AlarmId { get; init; }
///
/// 恢复状态。
///
public RecoveryStatus Status { get; init; }
///
/// 恢复时间。
///
public DateTime? RecoveryTimeUtc { get; init; }
///
/// 恢复原因。
///
public string? RecoveryReason { get; init; }
///
/// 恢复用户。
///
public string? RecoveryUser { get; init; }
///
/// 恢复检查次数。
///
public int RecoveryCheckCount { get; init; }
///
/// 最后检查时间。
///
public DateTime LastCheckTimeUtc { get; init; }
///
/// 下次检查时间。
///
public DateTime NextCheckTimeUtc { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 报警恢复请求。
///
public sealed class AlarmRecoveryRequest
{
///
/// 报警ID。
///
public Guid AlarmId { get; init; }
///
/// 恢复状态。
///
public RecoveryStatus Status { get; init; }
///
/// 恢复原因。
///
public string? RecoveryReason { get; init; }
///
/// 恢复用户。
///
public string RecoveryUser { get; init; } = string.Empty;
///
/// 是否自动恢复。
///
public bool IsAutoRecovery { get; init; } = false;
///
/// 恢复检查间隔(秒)。
///
public int RecoveryCheckIntervalSeconds { get; init; } = 30;
///
/// 请求时间。
///
public DateTime RequestTimeUtc { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 报警恢复结果。
///
public sealed class AlarmRecoveryResult
{
///
/// 报警ID。
///
public Guid AlarmId { get; init; }
///
/// 是否成功设置。
///
public bool IsSuccess { get; init; }
///
/// 恢复状态。
///
public RecoveryStatus Status { get; init; }
///
/// 设置时间。
///
public DateTime SetTimeUtc { get; init; }
///
/// 设置用户。
///
public string SetUser { get; init; } = string.Empty;
///
/// 结果描述。
///
public string? ResultDescription { get; init; }
///
/// 扩展属性。
///
public Dictionary ExtendedProperties { get; init; } = new();
}
///
/// 报警类型枚举。
///
public enum AlarmType
{
///
/// 系统报警。
///
System = 0,
///
/// 设备报警。
///
Equipment = 1,
///
/// 工艺报警。
///
Process = 2,
///
/// 质量报警。
///
Quality = 3,
///
/// 安全报警。
///
Safety = 4,
///
/// 性能报警。
///
Performance = 5,
///
/// 网络报警。
///
Network = 6,
///
/// 用户报警。
///
User = 7,
///
/// 自定义报警。
///
Custom = 8
}
///
/// 报警级别枚举。
///
public enum AlarmLevel
{
///
/// 信息级别。
///
Info = 0,
///
/// 警告级别。
///
Warning = 1,
///
/// 错误级别。
///
Error = 2,
///
/// 严重级别。
///
Critical = 3,
///
/// 致命级别。
///
Fatal = 4
}
///
/// 报警状态枚举。
///
public enum AlarmStatus
{
///
/// 活跃。
///
Active = 0,
///
/// 已确认。
///
Confirmed = 1,
///
/// 已清除。
///
Cleared = 2,
///
/// 已恢复。
///
Recovered = 3,
///
/// 已忽略。
///
Ignored = 4
}
///
/// 报警栈类型枚举。
///
public enum AlarmStackType
{
///
/// 活跃报警栈。
///
Active = 0,
///
/// 历史报警栈。
///
History = 1,
///
/// 确认报警栈。
///
Confirmed = 2,
///
/// 清除报警栈。
///
Cleared = 3
}
///
/// 恢复状态枚举。
///
public enum RecoveryStatus
{
///
/// 未恢复。
///
NotRecovered = 0,
///
/// 恢复中。
///
Recovering = 1,
///
/// 已恢复。
///
Recovered = 2,
///
/// 恢复失败。
///
RecoveryFailed = 3
}
///
/// 比较操作符枚举。
///
public enum ComparisonOperator
{
///
/// 等于。
///
Equal = 0,
///
/// 不等于。
///
NotEqual = 1,
///
/// 大于。
///
GreaterThan = 2,
///
/// 大于等于。
///
GreaterThanOrEqual = 3,
///
/// 小于。
///
LessThan = 4,
///
/// 小于等于。
///
LessThanOrEqual = 5
}
///
/// 报警通知类型枚举。
///
public enum AlarmNotificationType
{
///
/// UI通知。
///
UI = 0,
///
/// 日志通知。
///
Log = 1,
///
/// 邮件通知。
///
Email = 2,
///
/// 短信通知。
///
SMS = 3,
///
/// 声音通知。
///
Sound = 4,
///
/// 灯光通知。
///
Light = 5,
///
/// 推送通知。
///
Push = 6,
///
/// 自定义通知。
///
Custom = 7
}