Initial commit: KPI Management System Backend
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>
This commit is contained in:
63
app/models/kpi_period.py
Normal file
63
app/models/kpi_period.py
Normal file
@@ -0,0 +1,63 @@
|
||||
"""
|
||||
KPI 期間 Model
|
||||
"""
|
||||
from datetime import datetime, date
|
||||
from typing import Optional, List, TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import String, DateTime, Date
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.models.kpi_sheet import KPISheet
|
||||
|
||||
|
||||
class KPIPeriod(Base):
|
||||
"""KPI 期間"""
|
||||
|
||||
__tablename__ = "KPI_D_periods"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
code: Mapped[str] = mapped_column(String(20), unique=True, nullable=False) # 例: 2024H1
|
||||
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
start_date: Mapped[date] = mapped_column(Date, nullable=False)
|
||||
end_date: Mapped[date] = mapped_column(Date, nullable=False)
|
||||
setting_start: Mapped[date] = mapped_column(Date, nullable=False)
|
||||
setting_end: Mapped[date] = mapped_column(Date, nullable=False)
|
||||
self_eval_start: Mapped[Optional[date]] = mapped_column(Date)
|
||||
self_eval_end: Mapped[Optional[date]] = mapped_column(Date)
|
||||
manager_eval_start: Mapped[Optional[date]] = mapped_column(Date)
|
||||
manager_eval_end: Mapped[Optional[date]] = mapped_column(Date)
|
||||
status: Mapped[str] = mapped_column(String(20), default="draft")
|
||||
# draft, setting, approved, self_eval, manager_eval, completed
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
kpi_sheets: Mapped[List["KPISheet"]] = relationship("KPISheet", back_populates="period")
|
||||
|
||||
@property
|
||||
def is_setting_period(self) -> bool:
|
||||
"""是否在設定期間"""
|
||||
today = date.today()
|
||||
return self.setting_start <= today <= self.setting_end
|
||||
|
||||
@property
|
||||
def is_self_eval_period(self) -> bool:
|
||||
"""是否在自評期間"""
|
||||
if not self.self_eval_start or not self.self_eval_end:
|
||||
return False
|
||||
today = date.today()
|
||||
return self.self_eval_start <= today <= self.self_eval_end
|
||||
|
||||
@property
|
||||
def is_manager_eval_period(self) -> bool:
|
||||
"""是否在主管評核期間"""
|
||||
if not self.manager_eval_start or not self.manager_eval_end:
|
||||
return False
|
||||
today = date.today()
|
||||
return self.manager_eval_start <= today <= self.manager_eval_end
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<KPIPeriod {self.code}: {self.name}>"
|
||||
Reference in New Issue
Block a user