From b9b067707baaddd4cfdcc03e36c169c70bd9bf24 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Sun, 16 Nov 2025 22:33:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AEbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../task/device_threshold_check_task.go | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/domain/task/device_threshold_check_task.go b/internal/domain/task/device_threshold_check_task.go index d351650..4e62fb8 100644 --- a/internal/domain/task/device_threshold_check_task.go +++ b/internal/domain/task/device_threshold_check_task.go @@ -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 { // 状态一:检查未通过,确保告警开启 @@ -122,23 +122,23 @@ func (d *DeviceThresholdCheckTask) Execute(ctx context.Context) error { return nil } -// checkThreshold 校验当前值是否满足阈值条件 -func (d *DeviceThresholdCheckTask) checkThreshold(currentValue float32, operator models.Operator, threshold float32) bool { +// shouldTriggerAlarm 判断当前值是否触发告警条件 +func (d *DeviceThresholdCheckTask) shouldTriggerAlarm(currentValue float32, operator models.Operator, threshold float32) bool { switch operator { case models.OperatorLessThan: - return currentValue < threshold - case models.OperatorLessThanOrEqualTo: - return currentValue <= threshold - case models.OperatorGreaterThan: - return currentValue > threshold - case models.OperatorGreaterThanOrEqualTo: return currentValue >= threshold + case models.OperatorLessThanOrEqualTo: + return currentValue > threshold + case models.OperatorGreaterThan: + return currentValue <= threshold + case models.OperatorGreaterThanOrEqualTo: + return currentValue < threshold case models.OperatorEqualTo: - return currentValue == threshold - case models.OperatorNotEqualTo: return currentValue != threshold + case models.OperatorNotEqualTo: + return currentValue == threshold default: - return false + return false // 默认不触发告警 } }