feat: 初始化学生管理系统代码
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
# 新增顾问信息
|
||||
class AdvisorCreate(BaseModel):
|
||||
advisor_no: str = Field(description="顾问编号")
|
||||
name: str = Field(description="顾问姓名")
|
||||
gender: Optional[str] = Field(description="顾问性别")
|
||||
phone: Optional[str] = Field(None, description="联系电话")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
|
||||
# 修改顾问信息
|
||||
class AdvisorUpdate(BaseModel):
|
||||
name: Optional[str] = Field(None, description="顾问姓名")
|
||||
gender: Optional[str] = Field(None, description="顾问性别")
|
||||
phone: Optional[str] = Field(None, description="联系电话")
|
||||
remark: Optional[str] = Field(None, description="备注")
|
||||
|
||||
# 顾问信息响应体
|
||||
class AdvisorResp(BaseModel):
|
||||
id: int
|
||||
advisor_no: str
|
||||
name: str
|
||||
gender: str
|
||||
phone: Optional[str] = None
|
||||
remark: Optional[str] = None
|
||||
|
||||
# Pydantic v2 写法:允许直接从 ORM 对象取值
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
# 某个顾问名下的学生信息
|
||||
class AdvisorStudentResp(BaseModel):
|
||||
id: int = Field(description="学生ID")
|
||||
name: str = Field(description="学生姓名")
|
||||
class_id: Optional[int] = Field(None, description="班级ID")
|
||||
advisor_no: Optional[str] = Field(None, description="顾问编号")
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
@@ -0,0 +1,25 @@
|
||||
# 请求和响应模型
|
||||
from datetime import date
|
||||
from pydantic import BaseModel,Field
|
||||
from typing import Optional
|
||||
|
||||
# 新增班级
|
||||
class ClassCreate(BaseModel):
|
||||
class_name: str=Field(...,min_length=2,max_length=20,description="班级名称")
|
||||
start_time: Optional[date]=Field(None,description="开课时间")
|
||||
|
||||
# 修改班级
|
||||
class ClassUpdate(BaseModel):
|
||||
class_name: Optional[str]=Field(...,min_length=2,max_length=20,description="班级名称")
|
||||
start_time: Optional[date]=Field(None,description="开课时间")
|
||||
statu: Optional[int]=Field(None,ge=0,le=1,description="判断存不存在")
|
||||
|
||||
# 响应模型
|
||||
class ClassIn(BaseModel):
|
||||
id: int
|
||||
class_name: str
|
||||
start_time: Optional[date]
|
||||
statu: int
|
||||
|
||||
class Config:
|
||||
from_attributes=True
|
||||
@@ -0,0 +1,38 @@
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
|
||||
|
||||
class EmploymentCreate(BaseModel):
|
||||
stu_id: int = Field(..., description="学生编号ID")
|
||||
name: str | None = None
|
||||
employment_open_time: datetime | None = None
|
||||
offer_time: datetime | None = None
|
||||
company_name: str | None = None
|
||||
salary: float | None = None
|
||||
|
||||
|
||||
|
||||
|
||||
class EmploymentSet(BaseModel):
|
||||
name: str | None = None
|
||||
stu_id: int | None = None
|
||||
min_salary: float | None = None
|
||||
max_salary: float | None = None
|
||||
|
||||
|
||||
class EmploymentUpdate(BaseModel):
|
||||
name: str | None = None
|
||||
employment_open_time: datetime | None = None
|
||||
offer_time: datetime | None = None
|
||||
company_name: str | None = None
|
||||
salary: float | None = None
|
||||
|
||||
class EmploymentOut(BaseModel):
|
||||
id:int
|
||||
stu_id:int
|
||||
name: str | None = None
|
||||
employment_open_time:datetime | None = None
|
||||
offer_time: datetime | None = None
|
||||
company_name:str | None = None
|
||||
salary:float | None = None
|
||||
@@ -0,0 +1,62 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
||||
class StudentOut(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
id: int
|
||||
name: str
|
||||
age: int | None = None
|
||||
class_id: int | None = None
|
||||
|
||||
|
||||
class StudentGenderOut(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
class_id: int | None = None
|
||||
total: int
|
||||
gender_male: int
|
||||
gender_female: int
|
||||
|
||||
|
||||
class StudentRecordOut1(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
id: int
|
||||
name: str
|
||||
score: float
|
||||
|
||||
|
||||
class StudentRecordOut2(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
id: int
|
||||
name: str
|
||||
class_id: int | None = None
|
||||
score: float
|
||||
|
||||
|
||||
class StudentRecordOut3(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
exam_seq: int
|
||||
class_name: str
|
||||
avg_score: float
|
||||
|
||||
|
||||
class StudentRecordOut4(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
name: str
|
||||
class_id: int | None = None
|
||||
employment_open_time: datetime | None = None
|
||||
company_name: str | None = None
|
||||
salary: float | None = None
|
||||
|
||||
|
||||
class StudentRecordOut5(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
stu_id: int
|
||||
time_diff: float
|
||||
|
||||
|
||||
class StudentRecordOut6(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
class_id: int | None = None
|
||||
time_diff: float
|
||||
@@ -0,0 +1,28 @@
|
||||
# scheme/score_scheme.py
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
# 录入成绩
|
||||
class ScoreCreate(BaseModel):
|
||||
student_id: int = Field(..., description="ID")
|
||||
exam_seq: int = Field(..., ge=1, description="第几次")
|
||||
score: float = Field(..., ge=0, le=100, description="分数")
|
||||
|
||||
# 修改成绩
|
||||
class ScoreUpdate(BaseModel):
|
||||
student_id: int = Field(..., description="ID")
|
||||
exam_seq: int = Field(..., ge=1, description="第几次")
|
||||
score: float = Field(..., ge=0, le=100, description="分数")
|
||||
|
||||
|
||||
# 返回前端
|
||||
class ScoreOut(BaseModel):
|
||||
id: int
|
||||
student_id: int
|
||||
exam_seq: int
|
||||
score: float
|
||||
is_warning: int
|
||||
create_time: str | None = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
@@ -0,0 +1,22 @@
|
||||
from pydantic import BaseModel,Field,field_validator
|
||||
from typing import Optional
|
||||
from model import student
|
||||
|
||||
class Create_Stu_Mod(BaseModel):
|
||||
name: str = Field(min_length=3, max_length=15,description="姓名")
|
||||
hometown :Optional[str]=Field(min_length=2)
|
||||
school :str= Field(min_length=2,description="毕业院校")
|
||||
major : str=Field(description="专业")
|
||||
enroll_time:Optional[str]=Field(None,description="入学时间")
|
||||
graduate_time:Optional[str] = Field(None,description="毕业时间")
|
||||
education :Optional[str] = Field(description="学历")
|
||||
age :int=Field(gt=14,lt=60,description="年龄")
|
||||
gender : str = Field(max_length=10,description="性别")
|
||||
advisor_name:Optional[str]=Field(description="顾问名字")
|
||||
class_name:str=Field(description="班级名称")
|
||||
# 自定义校验器
|
||||
@field_validator('gender')
|
||||
def gender_validator(cls, gender):
|
||||
if gender not in ['男','女']:
|
||||
raise ValueError('性别输入有误')
|
||||
return gender
|
||||
@@ -0,0 +1,14 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional
|
||||
|
||||
class TeacherBase(BaseModel):
|
||||
teacher_no: str = Field(..., max_length=50, description="教师编号")
|
||||
name: str = Field(..., max_length=50, description="教师姓名")
|
||||
phone: str = Field(..., max_length=50, description="手机号")
|
||||
|
||||
class TeacherCreate(TeacherBase):
|
||||
pass
|
||||
|
||||
class TeacherUpdate(BaseModel):
|
||||
name: Optional[str] = Field(None, max_length=50, description="教师姓名")
|
||||
phone: Optional[str] = Field(None, max_length=50, description="手机号")
|
||||
Reference in New Issue
Block a user