# -*- coding: utf-8 -*- """请求级操作人上下文。 门户中间件根据登录会话设置当前操作人,各业务服务的日志/流转记录 统一通过 get_operator() 取真实用户,避免再硬编码“审计管理员”。 """ import contextvars _current = contextvars.ContextVar("audit_operator", default="系统") def set_operator(name: str) -> None: value = (name or "系统").strip() _current.set(value[:40] or "系统") def get_operator() -> str: try: return _current.get() or "系统" except Exception: return "系统"