CreateDeviceThresholdAlarm

UpdateDeviceThresholdAlarm
CreateAreaThresholdAlarm
UpdateAreaThresholdAlarm
This commit is contained in:
2025-11-10 17:35:22 +08:00
parent d4e8aba1fd
commit f2b0c2987f
10 changed files with 375 additions and 38 deletions

View File

@@ -14,10 +14,11 @@ import (
)
type DeviceThresholdCheckParams struct {
DeviceID uint `json:"device_id"` // 设备ID
SensorType models.SensorType `json:"sensor_type"` // 传感器类型
Thresholds float64 `json:"thresholds"` // 阈值
Operator models.Operator `json:"operator"` // 操作符
DeviceID uint `json:"device_id"` // 设备ID
SensorType models.SensorType `json:"sensor_type"` // 传感器类型
Thresholds float64 `json:"thresholds"` // 阈值
Operator models.Operator `json:"operator"` // 操作符
Level models.SeverityLevel `json:"level"` // 告警等级
}
// DeviceThresholdCheckTask 是一个任务,用于检查设备传感器数据是否满足阈值条件。
@@ -99,7 +100,7 @@ func (d *DeviceThresholdCheckTask) Execute(ctx context.Context) error {
AlarmCode: alarmCode,
AlarmSummary: summary,
AlarmDetails: details,
Level: models.WarnLevel, // 默认告警等级,可后续根据需求调整
Level: d.params.Level,
TriggerTime: time.Now(),
}
@@ -172,6 +173,9 @@ func (d *DeviceThresholdCheckTask) parseParameters(ctx context.Context) error {
if params.DeviceID == 0 {
err = fmt.Errorf("任务 %v: 未配置设备ID", d.taskLog.TaskID)
}
if params.Level == "" {
params.Level = models.WarnLevel
}
d.params = params