-- =============================================================================
-- S8 订单计划交付超期 近30天灰度草案规则：排除演示客户 SO001 / AiDOP演示客户
-- 业务已拍板：首轮只处理真实业务单（S20260515001 / 瑞贝德），SO001 必须排除。
-- 仅 UPDATE 既有草案规则 expression 增加 order_no <> 'SO001'；enabled 保持 0。
-- 安全：enabled=0 守卫 + rule_code 精确匹配；不改 params_json / next_run_at / paused_until；
--      不 INSERT/DELETE watch_rule；不碰异常表 / 通知表。命中 2→1。
-- =============================================================================
UPDATE ado_s8_watch_rule
SET expression = 'SELECT order_no AS source_object_id, order_no AS related_object_code, customer_name AS related_object_name, plan_delivery_date AS due_at, delivery_status AS status FROM v_s8_order_delivery_watch WHERE plan_delivery_date >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND plan_delivery_date < NOW() AND delivery_status NOT IN (''COMPLETED'') AND order_no <> ''SO001''',
    updated_at = NOW()
WHERE rule_code = 'RULE_S1_ORDER_DELIVERY_DUE_GRAY30_DATE_DELAY'
  AND enabled = 0;
