mrz
This commit is contained in:
@@ -1,34 +1,7 @@
|
||||
from fastapi import HTTPException,Depends
|
||||
from fastapi import Depends
|
||||
from util.database import get_db
|
||||
from model.all_model import Student_Model
|
||||
from typing import List, Optional, Dict, Any
|
||||
from sqlalchemy import func
|
||||
|
||||
# 实现根据年龄查询学生信息的功能
|
||||
def select_age(min_age,max_age,session=Depends(get_db)):
|
||||
try:
|
||||
if min_age is None and max_age is None:
|
||||
raise HTTPException(status_code=400, detail="请至少传入一个参数")
|
||||
session = session.query(Student_Model)
|
||||
if min_age is not None:
|
||||
session = session.filter(Student_Model.age >= min_age,Student_Model.delete_status == 0)
|
||||
if max_age is not None:
|
||||
session = session.filter(Student_Model.age <= max_age,Student_Model.delete_status == 0)
|
||||
return session.all()
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
|
||||
# 实现统计每个班级的学员总数以及男女生的总数的功能
|
||||
def select_all(session=Depends(get_db)):
|
||||
print('1234')
|
||||
try:
|
||||
l1 = session.query(Student_Model.class_id,func.count(1)).group_by(Student_Model.class_id,Student_Model.gender).all()
|
||||
print(l1)
|
||||
return l1
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
|
||||
def add_student_dao(o,db=Depends(get_db)):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user