""" backend/app/models/wecom.py 用途:企业微信触达与回调审计模型。 依赖:models.base.Base。 """ from __future__ import annotations from datetime import datetime from typing import Optional from sqlalchemy import DateTime, ForeignKey, String, Text from sqlalchemy.orm import Mapped, mapped_column from app.models.base import Base class WecomNotifyAudit(Base): """ 企业微信触达审计表 用途:记录企微消息发送结果与回流点击数据 """ __tablename__ = 'wecom_notify_audits' id: Mapped[int] = mapped_column(primary_key=True) event_type: Mapped[str] = mapped_column(String(64), index=True) status: Mapped[str] = mapped_column(String(20), default='sent', index=True) trace_id: Mapped[str] = mapped_column(String(64), unique=True, index=True) user_id: Mapped[Optional[int]] = mapped_column(ForeignKey('users.id'), nullable=True, index=True) username: Mapped[Optional[str]] = mapped_column(String(50), nullable=True) wecom_userid: Mapped[Optional[str]] = mapped_column(String(128), nullable=True) title: Mapped[Optional[str]] = mapped_column(String(120), nullable=True) content: Mapped[Optional[str]] = mapped_column(Text, nullable=True) jump_url: Mapped[Optional[str]] = mapped_column(String(512), nullable=True) error_code: Mapped[Optional[str]] = mapped_column(String(64), nullable=True) error_message: Mapped[Optional[str]] = mapped_column(String(255), nullable=True) created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, index=True) opened_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True, index=True) class WecomCallbackAudit(Base): """ 企业微信回调审计表 用途:记录消息与事件回调(安全模式解密后的内容摘要) """ __tablename__ = 'wecom_callback_audits' id: Mapped[int] = mapped_column(primary_key=True) msg_signature: Mapped[Optional[str]] = mapped_column(String(128), nullable=True) timestamp: Mapped[Optional[str]] = mapped_column(String(32), nullable=True) nonce: Mapped[Optional[str]] = mapped_column(String(64), nullable=True) encrypt_raw: Mapped[Optional[str]] = mapped_column(Text, nullable=True) decrypted_xml: Mapped[Optional[str]] = mapped_column(Text, nullable=True) msg_type: Mapped[Optional[str]] = mapped_column(String(32), nullable=True, index=True) event: Mapped[Optional[str]] = mapped_column(String(64), nullable=True, index=True) from_user: Mapped[Optional[str]] = mapped_column(String(128), nullable=True, index=True) agent_id: Mapped[Optional[str]] = mapped_column(String(32), nullable=True) msg_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True, index=True) error_message: Mapped[Optional[str]] = mapped_column(String(255), nullable=True) created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, index=True)