This commit is contained in:
2025-11-16 22:33:49 +08:00
parent 3daa03eab2
commit b9b067707b

View File

@@ -86,7 +86,7 @@ func (d *DeviceThresholdCheckTask) Execute(ctx context.Context) error {
} }
// 阈值检查未通过 // 阈值检查未通过
isExceeded := !d.checkThreshold(currentValue, d.params.Operator, d.params.Thresholds) isExceeded := !d.shouldTriggerAlarm(currentValue, d.params.Operator, d.params.Thresholds)
if isExceeded { if isExceeded {
// 状态一:检查未通过,确保告警开启 // 状态一:检查未通过,确保告警开启
@@ -122,23 +122,23 @@ func (d *DeviceThresholdCheckTask) Execute(ctx context.Context) error {
return nil return nil
} }
// checkThreshold 校验当前值是否满足阈值条件 // shouldTriggerAlarm 判断当前值是否触发告警条件
func (d *DeviceThresholdCheckTask) checkThreshold(currentValue float32, operator models.Operator, threshold float32) bool { func (d *DeviceThresholdCheckTask) shouldTriggerAlarm(currentValue float32, operator models.Operator, threshold float32) bool {
switch operator { switch operator {
case models.OperatorLessThan: case models.OperatorLessThan:
return currentValue < threshold
case models.OperatorLessThanOrEqualTo:
return currentValue <= threshold
case models.OperatorGreaterThan:
return currentValue > threshold
case models.OperatorGreaterThanOrEqualTo:
return currentValue >= threshold return currentValue >= threshold
case models.OperatorLessThanOrEqualTo:
return currentValue > threshold
case models.OperatorGreaterThan:
return currentValue <= threshold
case models.OperatorGreaterThanOrEqualTo:
return currentValue < threshold
case models.OperatorEqualTo: case models.OperatorEqualTo:
return currentValue == threshold
case models.OperatorNotEqualTo:
return currentValue != threshold return currentValue != threshold
case models.OperatorNotEqualTo:
return currentValue == threshold
default: default:
return false return false // 默认不触发告警
} }
} }