初步添加报警功能

This commit is contained in:
2025-09-13 12:30:12 +08:00
parent 5a39796f0e
commit 15e2caed22
12 changed files with 457 additions and 1 deletions

View File

@@ -0,0 +1,30 @@
namespace DMS.Core.Enums
{
public enum AlarmRule
{
/// <summary>
/// 超过上限报警
/// </summary>
AboveMax,
/// <summary>
/// 低于下限报警
/// </summary>
BelowMin,
/// <summary>
/// 超出范围报警(同时检查上限和下限)
/// </summary>
OutOfRange,
/// <summary>
/// 死区报警
/// </summary>
Deadband,
/// <summary>
/// 布尔值变化报警
/// </summary>
BooleanChange
}
}

View File

@@ -0,0 +1,27 @@
using System;
namespace DMS.Core.Events
{
public class AlarmEventArgs : EventArgs
{
public int VariableId { get; }
public string VariableName { get; }
public double CurrentValue { get; }
public double ThresholdValue { get; }
public string Message { get; }
public DateTime Timestamp { get; }
public string AlarmType { get; } // 可以是 "High", "Low", "Change" 等
public AlarmEventArgs(int variableId, string variableName, double currentValue,
double thresholdValue, string message, string alarmType)
{
VariableId = variableId;
VariableName = variableName;
CurrentValue = currentValue;
ThresholdValue = thresholdValue;
Message = message;
Timestamp = DateTime.Now;
AlarmType = alarmType;
}
}
}

View File

@@ -0,0 +1,16 @@
using DMS.Core.Models;
namespace DMS.Core.Interfaces.Repositories
{
/// <summary>
/// 报警历史记录仓库接口
/// </summary>
public interface IAlarmHistoryRepository : IBaseRepository<AlarmHistory>
{
// 可以添加特定于报警历史记录的查询方法
// 例如:
// Task<IEnumerable<AlarmHistory>> GetUnacknowledgedAlarmsAsync();
// Task<IEnumerable<AlarmHistory>> GetAlarmsByVariableIdAsync(int variableId);
// Task AcknowledgeAlarmAsync(int alarmId, string acknowledgedBy);
}
}

View File

@@ -0,0 +1,71 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DMS.Core.Models
{
/// <summary>
/// 报警历史记录实体
/// </summary>
public class AlarmHistory
{
/// <summary>
/// 主键ID
/// </summary>
[Key]
public int Id { get; set; }
/// <summary>
/// 变量ID
/// </summary>
public int VariableId { get; set; }
/// <summary>
/// 变量名称
/// </summary>
[MaxLength(100)]
public string VariableName { get; set; }
/// <summary>
/// 当前值
/// </summary>
public double CurrentValue { get; set; }
/// <summary>
/// 阈值
/// </summary>
public double ThresholdValue { get; set; }
/// <summary>
/// 报警类型 (High, Low, Deadband, BooleanChange)
/// </summary>
[MaxLength(50)]
public string AlarmType { get; set; }
/// <summary>
/// 报警消息
/// </summary>
public string Message { get; set; }
/// <summary>
/// 报警触发时间
/// </summary>
public DateTime Timestamp { get; set; }
/// <summary>
/// 是否已确认
/// </summary>
public bool IsAcknowledged { get; set; }
/// <summary>
/// 确认时间
/// </summary>
public DateTime? AcknowledgedAt { get; set; }
/// <summary>
/// 确认人
/// </summary>
[MaxLength(100)]
public string AcknowledgedBy { get; set; }
}
}