7651c57536
Motivation: 前端在展示规则详情与规则列表时,需要同时看到每条规则绑定了哪些通知渠道以及各渠道的启用状态。此前规则接口只返回规则本身,渠道绑定信息需要额外请求才能获取,增加了交互成本。本次让规则读取接口一次性携带关联渠道信息。 Changes: * 规则模型新增 Channels 字段及渠道条目结构,包含渠道标识、名称、类型和按规则维度的启用开关 * 创建、查询单条、列表查询规则接口在返回结果时填充绑定的渠道信息,无绑定时返回空列表 * 新增批量查询规则与渠道绑定关系的数据访问能力,按规则聚合返回,避免列表场景下逐条查询 * 单个渠道数据读取失败时跳过该条目,不阻断整体结果返回
87 lines
3.3 KiB
Go
87 lines
3.3 KiB
Go
package model
|
|
|
|
import (
|
|
"database/sql"
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
type Source struct {
|
|
ID int `db:"id" json:"id"`
|
|
Name string `db:"name" json:"name"`
|
|
APIKey string `db:"api_key" json:"api_key,omitempty"`
|
|
ParseMode string `db:"parse_mode" json:"parse_mode"`
|
|
ParsePattern string `db:"parse_pattern" json:"parse_pattern,omitempty"`
|
|
Status int `db:"status" json:"status"`
|
|
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
|
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
|
}
|
|
|
|
type Template struct {
|
|
ID int `db:"id" json:"id"`
|
|
Name string `db:"name" json:"name"`
|
|
Content string `db:"content" json:"content"`
|
|
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
|
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
|
}
|
|
|
|
type Channel struct {
|
|
ID int `db:"id" json:"id"`
|
|
Name string `db:"name" json:"name"`
|
|
Type string `db:"type" json:"type"`
|
|
Config *json.RawMessage `db:"config" json:"config"`
|
|
Status int `db:"status" json:"status"`
|
|
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
|
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
|
}
|
|
|
|
type RuleChannelItem struct {
|
|
ID int `json:"id"`
|
|
Name string `json:"name"`
|
|
Type string `json:"type"`
|
|
Enabled int `json:"enabled"`
|
|
}
|
|
|
|
type Rule struct {
|
|
ID int `db:"id" json:"id"`
|
|
Name string `db:"name" json:"name"`
|
|
SourceID int `db:"source_id" json:"source_id"`
|
|
Event string `db:"event" json:"event"`
|
|
TemplateID int `db:"template_id" json:"template_id"`
|
|
Conditions *json.RawMessage `db:"conditions" json:"conditions,omitempty"`
|
|
Enabled int `db:"enabled" json:"enabled"`
|
|
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
|
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
|
// Channels holds the channels bound to this rule. Populated by handlers when
|
|
// reading rules; each item includes the per-rule enabled switch.
|
|
Channels []RuleChannelItem `json:"channels"`
|
|
}
|
|
|
|
type Condition struct {
|
|
Field string `json:"field"`
|
|
Op string `json:"op"`
|
|
Value string `json:"value,omitempty"`
|
|
}
|
|
|
|
type RuleChannel struct {
|
|
ID int `db:"id" json:"id"`
|
|
RuleID int `db:"rule_id" json:"rule_id"`
|
|
ChannelID int `db:"channel_id" json:"channel_id"`
|
|
Enabled int `db:"enabled" json:"enabled"`
|
|
}
|
|
|
|
type MessageLog struct {
|
|
ID int64 `db:"id" json:"id"`
|
|
RuleID int `db:"rule_id" json:"rule_id"`
|
|
ChannelID int `db:"channel_id" json:"channel_id"`
|
|
Source string `db:"source" json:"source"`
|
|
Event string `db:"event" json:"event"`
|
|
Payload json.RawMessage `db:"payload" json:"payload"`
|
|
Content string `db:"content" json:"content"`
|
|
Status string `db:"status" json:"status"`
|
|
RetryCount int `db:"retry_count" json:"retry_count"`
|
|
Response sql.NullString `db:"response" json:"response,omitempty"`
|
|
ErrorMsg sql.NullString `db:"error_msg" json:"error_msg,omitempty"`
|
|
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
|
}
|