余额告警独立页面与多渠道通知:钉钉/飞书/企业微信/Bark,支持通知频率策略

- 告警设置拆分为独立页面,支持钉钉/飞书/企业微信/Bark/通用Webhook 多渠道
- 通知策略:低于阈值后按间隔重复提醒,达到最大次数停止,余额恢复自动重置
- 旧 webhook 配置自动迁移为通用渠道,渠道支持测试发送
- 优化告警话术:去商户ID展示、数字千分位格式化
This commit is contained in:
yml2213
2026-08-04 13:56:26 +08:00
parent 941e7ad79a
commit ca58c2bcaa
13 changed files with 1154 additions and 156 deletions
+40 -2
View File
@@ -34,7 +34,9 @@ type RechargeApplication struct {
Merchant *Merchant `gorm:"foreignKey:MerchantID" json:"merchant,omitempty"`
}
// MerchantAlertConfig 低余额 Webhook 告警配置(每商户一份)。
// MerchantAlertConfig 低余额告警配置(每商户一份)。
// 通知策略:余额低于阈值期间按 NotifyIntervalMinutes 间隔重复通知,
// 最多 MaxNotifications 次(0 表示不限);余额恢复阈值以上后重置计数。
type MerchantAlertConfig struct {
ID uint `gorm:"primarykey" json:"id"`
CreatedAt time.Time `json:"created_at"`
@@ -43,5 +45,41 @@ type MerchantAlertConfig struct {
MerchantID uint `gorm:"not null;uniqueIndex" json:"merchant_id"`
Enabled bool `gorm:"not null;default:false" json:"enabled"`
ThresholdPoints int64 `gorm:"not null;default:0" json:"threshold_points"`
WebhookURL string `gorm:"size:1024" json:"webhook_url"`
WebhookURL string `gorm:"size:1024" json:"-"`
// 通知频率策略
NotifyIntervalMinutes int `gorm:"not null;default:60" json:"notify_interval_minutes"`
MaxNotifications int `gorm:"not null;default:5" json:"max_notifications"`
LastNotifiedAt *time.Time `json:"last_notified_at"`
NotificationCount int `gorm:"not null;default:0" json:"notification_count"`
}
// 告警通知渠道类型
const (
AlertChannelDingtalk = "dingtalk"
AlertChannelFeishu = "feishu"
AlertChannelWecom = "wecom"
AlertChannelBark = "bark"
AlertChannelWebhook = "webhook"
)
// AlertChannelConfig 告警渠道专属配置:webhook 类渠道用 WebhookURLBark 用 Server+Key。
type AlertChannelConfig struct {
WebhookURL string `json:"webhook_url,omitempty"`
Server string `json:"server,omitempty"`
Key string `json:"key,omitempty"`
}
// AlertNotifyChannel 余额告警通知渠道,Config 为渠道专属 JSON 配置。
type AlertNotifyChannel struct {
ID uint `gorm:"primarykey" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
MerchantID uint `gorm:"not null;index" json:"merchant_id"`
ChannelType string `gorm:"size:32;not null" json:"channel_type"`
Name string `gorm:"size:64" json:"name"`
Config AlertChannelConfig `gorm:"type:text;serializer:json" json:"config"`
Enabled bool `gorm:"not null;default:true" json:"enabled"`
}