From 216bda58da5f52cbffaa8deb79f9891184adc315 Mon Sep 17 00:00:00 2001 From: erio Date: Mon, 13 Apr 2026 17:38:33 +0800 Subject: [PATCH] fix: change quota notify threshold semantics to "remaining quota" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Threshold now represents remaining quota instead of usage amount: - Fixed ($): threshold=400, limit=1000 → alert when remaining drops to $400 (i.e., usage reaches $600) - Percentage (%): threshold=30%, limit=1000 → alert when remaining drops to 30% (i.e., usage reaches $700) Also: - Rename 告警阈值 → 提醒阈值 in i18n - Widen type dropdown to w-16 for proper $ / % display --- backend/cmd/server/VERSION | 2 +- .../service/balance_notify_service.go | 15 +++-- .../components/account/QuotaNotifyToggle.vue | 58 ++++++------------- frontend/src/i18n/locales/en.ts | 2 +- frontend/src/i18n/locales/zh.ts | 2 +- 5 files changed, 30 insertions(+), 49 deletions(-) diff --git a/backend/cmd/server/VERSION b/backend/cmd/server/VERSION index f0c65691..01eddd22 100644 --- a/backend/cmd/server/VERSION +++ b/backend/cmd/server/VERSION @@ -1 +1 @@ -0.1.110.31 +0.1.110.34 diff --git a/backend/internal/service/balance_notify_service.go b/backend/internal/service/balance_notify_service.go index a392a13e..f5abbacc 100644 --- a/backend/internal/service/balance_notify_service.go +++ b/backend/internal/service/balance_notify_service.go @@ -115,13 +115,18 @@ type quotaDim struct { limit float64 } -// resolvedThreshold returns the effective threshold value. -// For percentage type, it computes threshold = limit * percentage / 100. +// resolvedThreshold converts the user-facing "remaining" threshold into a usage-based trigger point. +// The threshold represents how much quota REMAINS when the alert fires: +// - Fixed ($): threshold=400, limit=1000 → fires when usage reaches 600 (remaining drops to 400) +// - Percentage (%): threshold=30, limit=1000 → fires when usage reaches 700 (remaining drops to 30%) func (d quotaDim) resolvedThreshold() float64 { - if d.thresholdType == thresholdTypePercentage && d.limit > 0 { - return d.limit * d.threshold / 100 + if d.limit <= 0 { + return 0 } - return d.threshold + if d.thresholdType == thresholdTypePercentage { + return d.limit * (1 - d.threshold/100) + } + return d.limit - d.threshold } // buildQuotaDims returns the three quota dimensions for notification checking. diff --git a/frontend/src/components/account/QuotaNotifyToggle.vue b/frontend/src/components/account/QuotaNotifyToggle.vue index c7583a01..23979638 100644 --- a/frontend/src/components/account/QuotaNotifyToggle.vue +++ b/frontend/src/components/account/QuotaNotifyToggle.vue @@ -1,8 +1,4 @@ diff --git a/frontend/src/i18n/locales/en.ts b/frontend/src/i18n/locales/en.ts index 5c593946..dcbcf03c 100644 --- a/frontend/src/i18n/locales/en.ts +++ b/frontend/src/i18n/locales/en.ts @@ -2264,7 +2264,7 @@ export default { quotaLimitAmount: 'Total Limit', quotaLimitAmountHint: 'Cumulative spending limit. Does not auto-reset.', quotaNotify: { - alert: 'Alert Threshold', + alert: 'Alert', enabled: 'Enable Alert', threshold: 'Alert Amount', thresholdPlaceholder: 'Enter percentage', diff --git a/frontend/src/i18n/locales/zh.ts b/frontend/src/i18n/locales/zh.ts index 141193c1..6dc9311c 100644 --- a/frontend/src/i18n/locales/zh.ts +++ b/frontend/src/i18n/locales/zh.ts @@ -2262,7 +2262,7 @@ export default { quotaLimitAmount: '总限额', quotaLimitAmountHint: '累计消费上限,不会自动重置。', quotaNotify: { - alert: '告警阈值', + alert: '提醒阈值', enabled: '启用告警', threshold: '告警金额', thresholdPlaceholder: '输入百分比',