feat(规则匹配): 事件名支持通配符匹配

Motivation:
通知规则的事件名此前仅支持精确匹配,无法用一条规则覆盖多类事件(如 trade.* 下的全部交易事件),规则配置维护成本高。本次引入通配符匹配,让规则可按模式批量命中事件,同时保证精确规则优先。

Changes:

* 事件名支持 * 和 ? 通配符匹配
* 匹配优先级:精确匹配 > 更具体的通配 > 泛匹配,同分时取更小 ID
* 精确命中未命中时回退为列出源下启用规则并按优先级挑选
* 抽取缓存预热逻辑为独立方法
* 更新文档说明事件名通配规则
This commit is contained in:
2026-08-15 23:39:00 +08:00
parent dc313fda13
commit de7a52e81f
5 changed files with 160 additions and 20 deletions
+13
View File
@@ -66,6 +66,19 @@ func (s *Store) GetRuleBySourceEvent(ctx context.Context, sourceID int, event st
return &r, nil
}
func (s *Store) ListEnabledRulesBySource(ctx context.Context, sourceID int) ([]model.Rule, error) {
rows, err := s.DB.QueryContext(ctx, `SELECT id, source_id, event, template_id, conditions, enabled, created_at, updated_at FROM notification_rule WHERE source_id = ? AND enabled = 1`, sourceID)
if err != nil {
return nil, fmt.Errorf("list enabled rules by source: %w", err)
}
defer rows.Close()
rules, err := scanRules(rows)
if err != nil {
return nil, err
}
return rules, nil
}
func (s *Store) ListRules(ctx context.Context, page PageFilter) ([]model.Rule, int, error) {
var count int
if err := s.DB.GetContext(ctx, &count, `SELECT COUNT(*) FROM notification_rule`); err != nil {