-- Migration: 009_seed_default_rules
-- Description: 插入默认考核规则模板
-- Date: 2026-08-01
-- Refs: pmdocs/changes/2026-08-01-001-V0.2考核规则配置.md

-- 默认考核规则模板（草稿状态，待总部激活）
INSERT OR IGNORE INTO rules
  (code, name, description, period_type, period_start, period_end, status, version, created_by)
VALUES
  ('RULE_2026_Q3', '2026年第三季度考核规则', '第三季度综合考核，包含数量、质量、时效、合规四个维度', 'quarterly', '2026-07-01', '2026-09-30', 'draft', 1, '林致远');

-- 默认指标项（6个，覆盖四维度，权重之和为1.0）
INSERT OR IGNORE INTO rule_items
  (rule_id, category, name, metric_key, weight, min_score, max_score, formula_type, formula_params, display_order)
SELECT
  r.id,
  'quantity',
  '原创报道数量',
  'count_total',
  0.20,
  0, 100,
  'count',
  '{"threshold": 10, "base_score": 60, "bonus_per_item": 4, "max_bonus": 20}',
  1
FROM rules r WHERE r.code = 'RULE_2026_Q3';

INSERT OR IGNORE INTO rule_items
  (rule_id, category, name, metric_key, weight, min_score, max_score, formula_type, formula_params, display_order)
SELECT
  r.id,
  'quantity',
  '视频供稿数量',
  'count_video',
  0.10,
  0, 100,
  'count',
  '{"threshold": 5, "base_score": 60, "bonus_per_item": 5, "max_bonus": 20}',
  2
FROM rules r WHERE r.code = 'RULE_2026_Q3';

INSERT OR IGNORE INTO rule_items
  (rule_id, category, name, metric_key, weight, min_score, max_score, formula_type, formula_params, display_order)
SELECT
  r.id,
  'quality',
  '平均审核得分',
  'avg_score',
  0.25,
  0, 100,
  'avg_score',
  '{}',
  3
FROM rules r WHERE r.code = 'RULE_2026_Q3';

INSERT OR IGNORE INTO rule_items
  (rule_id, category, name, metric_key, weight, min_score, max_score, formula_type, formula_params, display_order)
SELECT
  r.id,
  'quality',
  '原创稿件占比',
  'original_ratio',
  0.15,
  0, 100,
  'rate',
  '{"target": 0.6, "base_score": 60, "bonus_per_pct": 40}',
  4
FROM rules r WHERE r.code = 'RULE_2026_Q3';

INSERT OR IGNORE INTO rule_items
  (rule_id, category, name, metric_key, weight, min_score, max_score, formula_type, formula_params, display_order)
SELECT
  r.id,
  'efficiency',
  '按时提交率',
  'on_time_rate',
  0.15,
  0, 100,
  'rate',
  '{"target": 0.9, "base_score": 60, "bonus_per_pct": 40}',
  5
FROM rules r WHERE r.code = 'RULE_2026_Q3';

INSERT OR IGNORE INTO rule_items
  (rule_id, category, name, metric_key, weight, min_score, max_score, formula_type, formula_params, display_order)
SELECT
  r.id,
  'compliance',
  '审核通过率',
  'pass_rate',
  0.15,
  0, 100,
  'rate',
  '{"target": 0.85, "base_score": 60, "bonus_per_pct": 40}',
  6
FROM rules r WHERE r.code = 'RULE_2026_Q3';