Files
test/app/schema/score_schema.py
T
2026-09-21 19:03:31 +08:00

64 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""成绩模块出入参(需求 2.2)。"""
from __future__ import annotations
from datetime import date
from decimal import Decimal
from pydantic import BaseModel, Field, field_validator
from app.schema.common import ORMBase, STRIP_VALIDATOR
class ScoreCreate(BaseModel):
stu_id: int = Field(..., description="学生ID")
exam_seq: int = Field(..., ge=1, le=99, description="考核序次,如 1=第一次考核")
score: Decimal = Field(..., ge=0, le=1000, description="成绩")
exam_name: str | None = Field(None, max_length=50, description="考核名称")
exam_date: str | None = Field(None, description="考核日期 YYYY-MM-DD")
remark: str | None = Field(None, max_length=255, description="备注")
_v_strip = STRIP_VALIDATOR
class ScoreBatchCreate(BaseModel):
"""一个学生一次性录入多次考核成绩。"""
stu_id: int = Field(..., description="学生ID")
scores: list[ScoreCreate] = Field(..., min_length=1, description="成绩列表")
@field_validator("scores")
@classmethod
def _same_student(cls, v, info): # noqa: ANN001, ANN201
return v
class ScoreUpdate(BaseModel):
score: Decimal | None = Field(None, ge=0, le=1000, description="新成绩")
exam_name: str | None = None
exam_date: str | None = None
remark: str | None = None
class ScoreOut(ORMBase):
id: int
stu_id: int
student_name: str | None = Field(None, description="学生姓名(JOIN)")
class_name: str | None = Field(None, description="班级名称(JOIN)")
exam_seq: int
exam_name: str | None = None
exam_date: date | None = None
score: float
flag: int
is_warning: bool = Field(False, description="是否低于红线")
remark: str | None = None
class ScoreRecordResult(BaseModel):
"""录入结果:把红线预警顺手带回去,前端可以直接弹提示。"""
record: ScoreOut
warning: bool = Field(False, description="是否触发红线预警")
warning_msg: str | None = Field(None, description="预警文案")
avg_score: float | None = Field(None, description="录入后该生平均分")