UPDATE recommendation
SET action_status=CASE WHEN action_status IN ('止盈1','止盈2','止损','跟踪止盈') THEN action_status ELSE '过期' END,
    execution_status='invalid',
    display_bucket='history',
    lifecycle_state='invalidated',
    entry_triggered=0,
    state_reason=COALESCE(NULLIF(state_reason, ''), '机会失效，归入历史复盘')
WHERE status IN ('expired', 'invalid', 'archived')
  AND COALESCE(display_bucket, '') != 'history';
