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>
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
"""
|
|
部門 Model
|
|
"""
|
|
from datetime import datetime
|
|
from typing import Optional, List, TYPE_CHECKING
|
|
|
|
from sqlalchemy import String, Integer, Boolean, DateTime, ForeignKey
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.core.database import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.employee import Employee
|
|
|
|
|
|
class Department(Base):
|
|
"""部門"""
|
|
|
|
__tablename__ = "KPI_D_departments"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
code: Mapped[str] = mapped_column(String(20), unique=True, nullable=False)
|
|
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
|
level: Mapped[str] = mapped_column(String(20), default="DEPT") # COMPANY, BU, DEPT, TEAM
|
|
parent_id: Mapped[Optional[int]] = mapped_column(ForeignKey("KPI_D_departments.id"))
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
# Relationships
|
|
parent: Mapped[Optional["Department"]] = relationship(
|
|
"Department", remote_side=[id], back_populates="children"
|
|
)
|
|
children: Mapped[List["Department"]] = relationship(
|
|
"Department", back_populates="parent"
|
|
)
|
|
employees: Mapped[List["Employee"]] = relationship(
|
|
"Employee", back_populates="department"
|
|
)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<Department {self.code}: {self.name}>"
|