Features: - FastAPI backend with JWT authentication - MySQL database with SQLAlchemy ORM - KPI workflow: draft → pending → approved → evaluation → completed - Ollama LLM API integration for AI features - Gitea API integration for version control - Complete API endpoints for KPI, dashboard, notifications Tables: KPI_D_* prefix naming convention 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
"""
|
|
通知 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"<Notification id={self.id} type={self.type} recipient={self.recipient_id}>"
|
|
|
|
|
|
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"<NotificationPreference employee={self.employee_id}>"
|