学生
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user