Conding #4
@@ -1,6 +1,7 @@
|
||||
from fastapi import HTTPException,Depends
|
||||
from util.database import get_db
|
||||
from model.student_model import Student_Model
|
||||
from typing import List, Optional, Dict, Any
|
||||
|
||||
def select_age(min_age,max_age,session=Depends(get_db)):
|
||||
try:
|
||||
@@ -17,8 +18,48 @@ def select_age(min_age,max_age,session=Depends(get_db)):
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
|
||||
def abc():
|
||||
return None
|
||||
|
||||
|
||||
def delete_student_dao(stu_id,db):
|
||||
try:
|
||||
rows = db.query(Student_Model).filter(Student_Model.stu_id == stu_id).delete()
|
||||
except:
|
||||
db.rollback()
|
||||
rows = 0
|
||||
else:
|
||||
db.commit()
|
||||
finally:
|
||||
return rows
|
||||
|
||||
def update_student_dao(stu_id,update_data,db):
|
||||
try:
|
||||
rows = db.query( Student_Model ).filter( Student_Model.stu_id == stu_id ).update( update_data )
|
||||
except:
|
||||
db.rollback()
|
||||
return False
|
||||
else:
|
||||
db.commit()
|
||||
return rows
|
||||
def get_student_dao(stu_id:Optional[int]
|
||||
,stu_name:Optional[str]
|
||||
,class_id:Optional[int]
|
||||
,db: Session
|
||||
,page: int
|
||||
,page_size: int
|
||||
) -> tuple[List[Dict[str, Any]], int]:
|
||||
q = db.query(Student_Model)
|
||||
if stu_id:
|
||||
q = q.filter(Student_Model.stu_id == stu_id)
|
||||
if stu_name:
|
||||
q = q.filter(Student_Model.stu_name.like(f"%{stu_name}%"))
|
||||
if class_id:
|
||||
q= q.filter(Student_Model.class_id == class_id)
|
||||
total = q.count()
|
||||
r = q.offset((page - 1) * page_size).limit(page_size).all()
|
||||
data = []
|
||||
for i in r:
|
||||
data.append({'stu_id': i.stu_id
|
||||
,'stu_name': i.stu_name
|
||||
,'class_id': i.class_id
|
||||
,'create_date': i.create_date
|
||||
,'update_date': i.update_date
|
||||
})
|
||||
return data, total
|
||||
|
||||
@@ -8,10 +8,10 @@ class Student_Model(Base):
|
||||
, primary_key=True
|
||||
, autoincrement=True
|
||||
,comment='学生编号')
|
||||
# class_id=Column(Integer
|
||||
# ,ForeignKey('wl_class.class_id')
|
||||
# ,nullable=False
|
||||
# ,comment='班级编号')
|
||||
class_id=Column(Integer
|
||||
,ForeignKey('wl_class.class_id')
|
||||
,nullable=False
|
||||
,comment='班级编号')
|
||||
stu_name=Column(String(100),comment='学生姓名')
|
||||
age=Column(Integer,comment='年龄')
|
||||
gender=Column(String(50),comment='性别')
|
||||
@@ -30,4 +30,3 @@ class Student_Model(Base):
|
||||
,onupdate=datetime.now)
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
# MaRuiZhi NB
|
||||
# MaRuiZhi NB Plus
|
||||
# hahaha
|
||||
from sqlalchemy import DATETIME,Column, Integer, String, Date,ForeignKey
|
||||
from datetime import datetime
|
||||
from util.database import Base,engine
|
||||
|
||||
class Teacher_Model(Base):
|
||||
__tablename__ = 'wl_teacher'
|
||||
teac_id=Column(Integer,primary_key=True,autoincrement=True,comment='老师编号')
|
||||
teac_name=Column(String(20),comment='老师姓名')
|
||||
teac_gender=Column(String(5),comment='老师性别')
|
||||
teac_age=Column(Integer,comment='老师年龄')
|
||||
teac_position =Column(String(20),comment='老师职位')
|
||||
status=Column(Integer,default=0,comment='课程进度:学习中=0,求职中=1,已就业=2')
|
||||
create_date=Column(DATETIME,default=datetime.now)
|
||||
update_date=Column(DATETIME,default=datetime.now,onupdate=datetime.now)
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
|
||||
@@ -1,4 +1,33 @@
|
||||
from pydantic import BaseModel,field_serializer
|
||||
from datetime import date
|
||||
from typing import Self
|
||||
from pydantic import BaseModel, field_serializer, field_validator,model_validator
|
||||
|
||||
|
||||
class StudentRequest(BaseModel):
|
||||
class_id:int |None = None
|
||||
stu_name:str |None = None
|
||||
age:int |None = None
|
||||
gender:str |None = None
|
||||
native_place:str |None = None
|
||||
birthday:date
|
||||
school:str |None = None
|
||||
major:str |None = None
|
||||
degree:str |None = None
|
||||
admission_date:date
|
||||
graduation_date:date
|
||||
@field_validator('age')
|
||||
@classmethod
|
||||
def check_age(cls, v):
|
||||
if v is not None and v < 0:
|
||||
raise ValueError('年龄不能为负数')
|
||||
return v
|
||||
|
||||
@model_validator(mode='after')
|
||||
def check_admission_graduation(self) -> Self:
|
||||
if self.admission_date and self.graduation_date:
|
||||
if self.admission_date > self.graduation_date:
|
||||
raise ValueError ('入学日期不能晚于毕业日期')
|
||||
return self
|
||||
|
||||
class StudentResponse(BaseModel):
|
||||
code:int = 200
|
||||
@@ -16,5 +45,3 @@ class StudentResponse(BaseModel):
|
||||
2:'已就业'
|
||||
}
|
||||
return d1.get(progress,'暂不明确')
|
||||
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ wl_student(学⽣编号、学⽣班级、学⽣姓名、年龄、性别、籍
|
||||
学⽣考核成绩表 **xxx 做成中**
|
||||
wl_score(学⽣编号、考核序次、成绩、删除状态(0:已删除,1:初始值)、作成时间、更新时间)
|
||||
|
||||
学⽣就业管理模表 **xxx 做成中**
|
||||
学⽣就业管理模表 **cyl 做成中**
|
||||
wl_employment(学⽣编号、就业开放时间(只有进入就业课的才会输入数据)、offer下发时间()、就业公司名称、就业薪资、删除状态(0:已删除,1:初始值)、作成时间、更新时间)
|
||||
|
||||
班级管理表 **xxx 做成中**
|
||||
wl_class(班级编号,开课时间,删除状态(0:已删除,1:初始值),班主任(老师编号),授课⽼师(老师编号),作成时间,更新时间)
|
||||
|
||||
⽼师管理表 **xxx 做成中**
|
||||
⽼师管理表 **sgt 做成中**
|
||||
wl_teacher(老师编号,姓名,性别,年龄,删除状态(0:已删除,1:初始值),职位,作成时间,更新时间)
|
||||
|
||||
dao层(每一个功能就是一个函数,判断能否功能复用)
|
||||
|
||||
Reference in New Issue
Block a user