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>
69 lines
2.6 KiB
Python
69 lines
2.6 KiB
Python
"""
|
|
員工 Model
|
|
"""
|
|
from datetime import datetime, date
|
|
from typing import Optional, List, TYPE_CHECKING
|
|
|
|
from sqlalchemy import String, Integer, Boolean, DateTime, Date, ForeignKey
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.core.database import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.department import Department
|
|
from app.models.kpi_sheet import KPISheet
|
|
from app.models.notification import Notification
|
|
|
|
|
|
class Employee(Base):
|
|
"""員工"""
|
|
|
|
__tablename__ = "KPI_D_employees"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
employee_no: Mapped[str] = mapped_column(String(20), unique=True, nullable=False)
|
|
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
|
email: Mapped[str] = mapped_column(String(200), unique=True, nullable=False)
|
|
password_hash: Mapped[str] = mapped_column(String(200), nullable=False)
|
|
department_id: Mapped[int] = mapped_column(ForeignKey("KPI_D_departments.id"), nullable=False)
|
|
manager_id: Mapped[Optional[int]] = mapped_column(ForeignKey("KPI_D_employees.id"))
|
|
job_title: Mapped[Optional[str]] = mapped_column(String(100))
|
|
role: Mapped[str] = mapped_column(String(20), default="employee") # employee, manager, admin, hr
|
|
status: Mapped[str] = mapped_column(String(20), default="active") # active, inactive, resigned
|
|
hire_date: Mapped[Optional[date]] = mapped_column(Date)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
# Relationships
|
|
department: Mapped["Department"] = relationship("Department", back_populates="employees")
|
|
manager: Mapped[Optional["Employee"]] = relationship(
|
|
"Employee", remote_side=[id], back_populates="subordinates"
|
|
)
|
|
subordinates: Mapped[List["Employee"]] = relationship(
|
|
"Employee", back_populates="manager"
|
|
)
|
|
kpi_sheets: Mapped[List["KPISheet"]] = relationship(
|
|
"KPISheet", back_populates="employee", foreign_keys="KPISheet.employee_id"
|
|
)
|
|
notifications: Mapped[List["Notification"]] = relationship(
|
|
"Notification", back_populates="recipient"
|
|
)
|
|
|
|
@property
|
|
def is_manager(self) -> bool:
|
|
"""是否為主管"""
|
|
return self.role in ("manager", "admin")
|
|
|
|
@property
|
|
def is_admin(self) -> bool:
|
|
"""是否為管理員"""
|
|
return self.role == "admin"
|
|
|
|
@property
|
|
def is_hr(self) -> bool:
|
|
"""是否為人資"""
|
|
return self.role == "hr"
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<Employee {self.employee_no}: {self.name}>"
|