Files
syops/backend/app/models/training.py
T

49 lines
2.3 KiB
Python

"""
backend/app/models/training.py
用途:定义新人入职培训记录模型,承载学员当前培训进度、成绩结算与 HR 统计来源。
依赖:models.base.Base、SQLAlchemy 映射、users 主表外键。
逻辑:每个用户维护一条当前培训记录;前端学习流与管理端统计都基于该表读写。
"""
from __future__ import annotations
from datetime import date, datetime
from typing import Optional
from sqlalchemy import Boolean, Date, DateTime, ForeignKey, Integer, JSON, String
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.models.base import Base
class TrainingRecord(Base):
"""新人入职培训当前记录。"""
__tablename__ = "training_records"
id: Mapped[int] = mapped_column(primary_key=True)
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), unique=True, index=True, nullable=False)
employee_id: Mapped[Optional[str]] = mapped_column(String(50), nullable=True, index=True)
name: Mapped[Optional[str]] = mapped_column(String(100), nullable=True, index=True)
department: Mapped[Optional[str]] = mapped_column(String(100), nullable=True, index=True)
join_date: Mapped[Optional[date]] = mapped_column(Date, nullable=True, index=True)
stage: Mapped[str] = mapped_column(String(20), nullable=False, default="video", index=True)
current_question_index: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
score: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
passed: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, index=True)
attempt_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
answer_details: Mapped[list[dict] | None] = mapped_column(JSON, nullable=True)
started_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.utcnow)
completion_time: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True, index=True)
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.utcnow, index=True)
updated_at: Mapped[datetime] = mapped_column(
DateTime,
nullable=False,
default=datetime.utcnow,
onupdate=datetime.utcnow,
index=True,
)
user = relationship("User", back_populates="training_record")