""" 通知 Model """ from datetime import datetime from typing import Optional, TYPE_CHECKING from sqlalchemy import String, Integer, Boolean, DateTime, Text, ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship from app.core.database import Base if TYPE_CHECKING: from app.models.employee import Employee from app.models.kpi_sheet import KPISheet class Notification(Base): """通知""" __tablename__ = "KPI_D_notifications" id: Mapped[int] = mapped_column(primary_key=True) recipient_id: Mapped[int] = mapped_column(ForeignKey("KPI_D_employees.id"), nullable=False) type: Mapped[str] = mapped_column(String(50), nullable=False) # kpi_submitted, kpi_approved, kpi_rejected, eval_reminder, etc. title: Mapped[str] = mapped_column(String(200), nullable=False) content: Mapped[Optional[str]] = mapped_column(Text) related_sheet_id: Mapped[Optional[int]] = mapped_column(ForeignKey("KPI_D_sheets.id", ondelete="SET NULL")) is_read: Mapped[bool] = mapped_column(Boolean, default=False) read_at: Mapped[Optional[datetime]] = mapped_column(DateTime) created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow) # Relationships recipient: Mapped["Employee"] = relationship("Employee", back_populates="notifications") related_sheet: Mapped[Optional["KPISheet"]] = relationship("KPISheet") def __repr__(self) -> str: return f"" class NotificationPreference(Base): """通知偏好""" __tablename__ = "KPI_D_notification_preferences" id: Mapped[int] = mapped_column(primary_key=True) employee_id: Mapped[int] = mapped_column(ForeignKey("KPI_D_employees.id"), unique=True, nullable=False) email_enabled: Mapped[bool] = mapped_column(Boolean, default=True) in_app_enabled: Mapped[bool] = mapped_column(Boolean, default=True) reminder_days_before: Mapped[int] = mapped_column(Integer, default=3) created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow) updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) # Relationships employee: Mapped["Employee"] = relationship("Employee") def __repr__(self) -> str: return f""