feat(channel-monitor): apply template via subset picker; CC 2.1.114 baseline doc

Apply flow:
- POST /admin/channel-monitor-templates/:id/apply now requires monitor_ids
  (non-empty array). Service applies the template only to the selected
  subset, gated by AND template_id = :id (so users can't sneak in
  unrelated monitor IDs).
- New GET /admin/channel-monitor-templates/:id/monitors returns the
  associated monitor briefs (id/name/provider/enabled) for the picker.
- ApplyToMonitors signature gains monitorIDs []int64; empty list returns
  ErrChannelMonitorTemplateApplyEmpty.

Frontend:
- New MonitorTemplateApplyPickerDialog.vue: list of associated monitors
  with checkboxes (default all checked), 全选 / 全不选 shortcuts, live
  selected/total count. Submit calls apply(id, ids).
- MonitorTemplateManagerDialog replaces the old ConfirmDialog flow with
  the picker; onApplied refetches the list to refresh associated counts.

i18n: applyPicker* + common.selectAll keys.

chore: bump version to 0.1.114.33

The CC 2.1.114 (sdk-cli) UA / APIKeyBetaHeader / JSON metadata.user_id
baseline (already verified working via the in-process apply on prod
template id=1) is documented in internal/pkg/claude/constants.go and
is what the seed template in the manager UI should follow.
This commit is contained in:
erio
2026-04-21 14:39:19 +08:00
parent a296425994
commit 6925ac25c4
10 changed files with 341 additions and 51 deletions

View File

@@ -15,10 +15,23 @@ type ChannelMonitorRequestTemplateRepository interface {
Delete(ctx context.Context, id int64) error
List(ctx context.Context, params ChannelMonitorRequestTemplateListParams) ([]*ChannelMonitorRequestTemplate, error)
// ApplyToMonitors 把模板当前的 extra_headers / body_override_mode / body_override
// 批量覆盖到所有 template_id = id 的监控上。返回被覆盖的监控数量。
ApplyToMonitors(ctx context.Context, id int64) (int64, error)
// 批量覆盖到指定 monitorIDs 的监控上(同时还要求这些监控当前 template_id = id
// 防止误覆盖未关联的监控。monitorIDs 必须非空;空列表直接返回 0 不写库。
// 返回被覆盖的监控数量。
ApplyToMonitors(ctx context.Context, id int64, monitorIDs []int64) (int64, error)
// CountAssociatedMonitors 统计 template_id = id 的监控数(用于 UI 展示「应用到 N 个配置」)。
CountAssociatedMonitors(ctx context.Context, id int64) (int64, error)
// ListAssociatedMonitors 列出所有 template_id = id 的监控简略信息id/name/provider/enabled
// 给 apply picker UI 用,避免前端再做一次 list+filter。
ListAssociatedMonitors(ctx context.Context, id int64) ([]*AssociatedMonitorBrief, error)
}
// AssociatedMonitorBrief 模板关联监控的简略信息picker / 列表展示用)。
type AssociatedMonitorBrief struct {
ID int64
Name string
Provider string
Enabled bool
}
// ChannelMonitorRequestTemplateService 模板管理 service。
@@ -90,13 +103,17 @@ func (s *ChannelMonitorRequestTemplateService) Delete(ctx context.Context, id in
return nil
}
// ApplyToMonitors 把模板当前配置一键应用到所有关联监控。
// 返回被影响的监控数
func (s *ChannelMonitorRequestTemplateService) ApplyToMonitors(ctx context.Context, id int64) (int64, error) {
// ApplyToMonitors 把模板当前配置应用到 monitorIDs 列表里的关联监控。
// monitorIDs 必须非空且每个 id 都必须当前 template_id = id不满足条件的会被 SQL WHERE 过滤掉
// 返回实际被覆盖的监控数。
func (s *ChannelMonitorRequestTemplateService) ApplyToMonitors(ctx context.Context, id int64, monitorIDs []int64) (int64, error) {
if _, err := s.repo.GetByID(ctx, id); err != nil {
return 0, err
}
affected, err := s.repo.ApplyToMonitors(ctx, id)
if len(monitorIDs) == 0 {
return 0, ErrChannelMonitorTemplateApplyEmpty
}
affected, err := s.repo.ApplyToMonitors(ctx, id, monitorIDs)
if err != nil {
return 0, fmt.Errorf("apply template to monitors: %w", err)
}
@@ -108,6 +125,15 @@ func (s *ChannelMonitorRequestTemplateService) CountAssociatedMonitors(ctx conte
return s.repo.CountAssociatedMonitors(ctx, id)
}
// ListAssociatedMonitors 返回模板关联的所有监控简略信息。
// 给前端 apply picker 用handler 直接吐 JSON 不再做 join。
func (s *ChannelMonitorRequestTemplateService) ListAssociatedMonitors(ctx context.Context, id int64) ([]*AssociatedMonitorBrief, error) {
if _, err := s.repo.GetByID(ctx, id); err != nil {
return nil, err
}
return s.repo.ListAssociatedMonitors(ctx, id)
}
// ---------- 校验 & 工具 ----------
// validateTemplateCreateParams 聚合 create 入参校验,避免函数超过 30 行。