d2e8476398
Motivation: 止盈、止损等不同策略信号会映射到同一事件(如 trade.close),但原有唯一约束要求每个事件只能有一条规则,无法按策略区分处理。放开该约束后,同一事件可配置多条规则,通过规则条件与精确/通配优先级区分,命中条件的规则全部发送;同时将去重键从消息原文改为信号维度,避免同一信号因时间戳等无关字段差异被误判为重复。 Changes: * 移除规则 source_id+event 的唯一约束,改为普通索引 * 事件匹配改为返回命中优先级内所有启用规则,并按 ID 逐条派发 * 通知服务遍历多条规则,按条件过滤后聚合发送渠道 * 去重键由消息 body 哈希改为策略/币种/周期/方向/价格信号维度哈希
31 lines
717 B
Go
31 lines
717 B
Go
package engine
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"aiaa-notification-service/internal/cache"
|
|
"aiaa-notification-service/internal/model"
|
|
"aiaa-notification-service/internal/store"
|
|
)
|
|
|
|
type Matcher struct {
|
|
store *store.Store
|
|
}
|
|
|
|
func NewMatcher(s *store.Store, _ *cache.Cache) *Matcher {
|
|
return &Matcher{store: s}
|
|
}
|
|
|
|
func (m *Matcher) Match(ctx context.Context, sourceID int, event string) ([]model.Rule, error) {
|
|
rules, err := m.store.ListEnabledRulesBySource(ctx, sourceID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("match rule: %w", err)
|
|
}
|
|
picked := PickEventRules(event, rules)
|
|
if len(picked) == 0 {
|
|
return nil, fmt.Errorf("match rule: no rule for source %d event %s", sourceID, event)
|
|
}
|
|
return picked, nil
|
|
}
|