|
|
"""
|
|
|
Pydantic模型定义(用于API请求和响应)
|
|
|
"""
|
|
|
from pydantic import BaseModel
|
|
|
from typing import Optional, List
|
|
|
from datetime import datetime
|
|
|
|
|
|
# 学生相关模型
|
|
|
class StudentBase(BaseModel):
|
|
|
student_id: str
|
|
|
name: str
|
|
|
major: Optional[str] = None
|
|
|
|
|
|
class StudentCreate(StudentBase):
|
|
|
pass
|
|
|
|
|
|
class StudentUpdate(BaseModel):
|
|
|
name: Optional[str] = None
|
|
|
major: Optional[str] = None
|
|
|
|
|
|
class Student(StudentBase):
|
|
|
id: int
|
|
|
total_score: float
|
|
|
random_rollcall_count: int
|
|
|
order_rollcall_count: int
|
|
|
transfer_right_count: int
|
|
|
created_at: datetime
|
|
|
updated_at: datetime
|
|
|
|
|
|
class Config:
|
|
|
from_attributes = True
|
|
|
|
|
|
# 点名相关模型
|
|
|
class RollCallRequest(BaseModel):
|
|
|
rollcall_type: str # "random" or "order"
|
|
|
student_id: Optional[int] = None # 顺序点名时需要指定学生ID
|
|
|
|
|
|
class RollCallResult(BaseModel):
|
|
|
student_id: int
|
|
|
student_code: str
|
|
|
name: str
|
|
|
major: Optional[str]
|
|
|
total_score: float
|
|
|
random_rollcall_count: int
|
|
|
|
|
|
class RollCallRecordCreate(BaseModel):
|
|
|
student_id: int
|
|
|
rollcall_type: str
|
|
|
is_present: bool = True
|
|
|
question_repeat_score: float = 0.0
|
|
|
answer_score: float = 0.0
|
|
|
event_type: Optional[str] = None
|
|
|
|
|
|
class RollCallRecordResponse(BaseModel):
|
|
|
id: int
|
|
|
student_id: int
|
|
|
student_code: str
|
|
|
student_name: str
|
|
|
rollcall_type: str
|
|
|
is_present: bool
|
|
|
total_score_change: float
|
|
|
created_at: datetime
|
|
|
|
|
|
class Config:
|
|
|
from_attributes = True
|
|
|
|
|
|
# 积分相关模型
|
|
|
class ScoreUpdate(BaseModel):
|
|
|
student_id: int
|
|
|
attendance_score: float = 0.0
|
|
|
question_repeat_score: float = 0.0
|
|
|
answer_score: float = 0.0
|
|
|
event_type: Optional[str] = None
|
|
|
|
|
|
class RankingItem(BaseModel):
|
|
|
rank: int
|
|
|
student_id: str
|
|
|
name: str
|
|
|
major: Optional[str]
|
|
|
total_score: float
|
|
|
random_rollcall_count: int
|
|
|
|
|
|
class RankingResponse(BaseModel):
|
|
|
rankings: List[RankingItem]
|
|
|
total: int
|
|
|
|
|
|
# Excel导入导出模型
|
|
|
class ExcelImportResponse(BaseModel):
|
|
|
success: bool
|
|
|
message: str
|
|
|
imported_count: int
|
|
|
failed_count: int
|
|
|
|