mrz
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
from fastapi import APIRouter
|
||||||
|
from dao.statistics_dao import select_all,select_age,select_score
|
||||||
|
from schema.student_schema import StudentResponse
|
||||||
|
|
||||||
|
StudentAPI = APIRouter()
|
||||||
|
|
||||||
|
@StudentAPI.get("/age",response_model=StudentResponse,tags=['统计分析模块'],description='根据年龄查询学生信息')
|
||||||
|
def get_students(min_age:int|None=None,max_age:int|None=None):
|
||||||
|
l = select_age(min_age,max_age)
|
||||||
|
return [i for i in l]
|
||||||
|
|
||||||
|
@StudentAPI.get("/all",response_model=StudentResponse,tags=['统计分析模块'],description='统计每个班级的学员总数和男女生总数')
|
||||||
|
def get_students():
|
||||||
|
l = select_all()
|
||||||
|
return [i for i in l]
|
||||||
|
|
||||||
|
@StudentAPI.get("/score",response_model=StudentResponse,tags=['统计分析模块'],description='根据成绩查询学生信息')
|
||||||
|
def get_students(min_score:int|None=None,max_score:int|None=None):
|
||||||
|
l = select_score(min_score,max_score)
|
||||||
|
return [i for i in l]
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
from fastapi import HTTPException,Depends
|
||||||
|
from sqlalchemy import func
|
||||||
|
from model.all_model import Student_Model,WlScore
|
||||||
|
from util.database import get_db
|
||||||
|
|
||||||
|
# 实现根据年龄查询学生信息的功能
|
||||||
|
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()
|
||||||
|
return l1
|
||||||
|
except Exception:
|
||||||
|
raise HTTPException(status_code=500,detail="查询异常")
|
||||||
|
|
||||||
|
# 实现根据成绩查询学员信息的功能
|
||||||
|
def select_score(min_score,max_score,session=Depends(get_db)):
|
||||||
|
try:
|
||||||
|
if min_score is None and max_score is None:
|
||||||
|
raise HTTPException(status_code=400, detail="请至少传入一个参数")
|
||||||
|
session = session.query(Student_Model,WlScore.score,WlScore.score)\
|
||||||
|
.join(WlScore,WlScore.stu_id == Student_Model.stu_id,WlScore.delete_status==0,WlScore.delete_status == 0)
|
||||||
|
if min_score is not None:
|
||||||
|
session = session.filter(WlScore.score >= min_score)
|
||||||
|
if min_score is not None:
|
||||||
|
session = session.filter(WlScore.score <= max_score)
|
||||||
|
return session.all()
|
||||||
|
except HTTPException:
|
||||||
|
raise
|
||||||
|
except Exception:
|
||||||
|
raise HTTPException(status_code=500,detail="查询异常")
|
||||||
@@ -1,34 +1,7 @@
|
|||||||
from fastapi import HTTPException,Depends
|
from fastapi import Depends
|
||||||
from util.database import get_db
|
from util.database import get_db
|
||||||
from model.all_model import Student_Model
|
from model.all_model import Student_Model
|
||||||
from typing import List, Optional, Dict, Any
|
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)):
|
def add_student_dao(o,db=Depends(get_db)):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -10,11 +10,6 @@ class Student_Model(Base):
|
|||||||
, autoincrement=True
|
, autoincrement=True
|
||||||
,comment='学生编号')
|
,comment='学生编号')
|
||||||
|
|
||||||
class_id=Column(Integer
|
|
||||||
,ForeignKey('wl_class.class_id')
|
|
||||||
,nullable=False
|
|
||||||
,comment='班级编号')
|
|
||||||
|
|
||||||
stu_name=Column(String(100),comment='学生姓名')
|
stu_name=Column(String(100),comment='学生姓名')
|
||||||
|
|
||||||
age=Column(Integer,comment='年龄')
|
age=Column(Integer,comment='年龄')
|
||||||
@@ -54,6 +49,12 @@ class ClassManagement(Base):
|
|||||||
|
|
||||||
class_id= Column(Integer, primary_key=True, autoincrement=True,comment='班级编号')
|
class_id= Column(Integer, primary_key=True, autoincrement=True,comment='班级编号')
|
||||||
|
|
||||||
|
stu_id = Column(Integer
|
||||||
|
,ForeignKey('wl_student.stu_id')
|
||||||
|
,nullable=False
|
||||||
|
,comment='学生编号'
|
||||||
|
)
|
||||||
|
|
||||||
class_name = Column(String(100), comment='班级姓名')
|
class_name = Column(String(100), comment='班级姓名')
|
||||||
|
|
||||||
start_class_date = Column(DATE,comment='开课时间')
|
start_class_date = Column(DATE,comment='开课时间')
|
||||||
|
|||||||
@@ -54,9 +54,9 @@ dao层(每一个功能就是一个函数,判断能否功能复用)
|
|||||||
|
|
||||||
统计分析模块
|
统计分析模块
|
||||||
实现根据年龄查询学生信息的功能 **mrz 已作成**
|
实现根据年龄查询学生信息的功能 **mrz 已作成**
|
||||||
实现统计每个班级的学员总数以及男女生的总数的功能 **mrz 做成中**
|
实现统计每个班级的学员总数以及男女生的总数的功能 **mrz 已作成**
|
||||||
实现根据成绩查询学员信息的功能 **xxx 做成中**
|
实现根据成绩查询学员信息的功能 **mrz 已作成**
|
||||||
实现统计每次考试每个班级的平均分并排序的功能 **xxx 做成中**
|
实现统计每次考试每个班级的平均分并排序的功能 **mrz 做成中**
|
||||||
实现统计薪资最高的前五名的学员信息 **sgt 做成中**
|
实现统计薪资最高的前五名的学员信息 **sgt 做成中**
|
||||||
实现查询每个学生的就业时长 **xxx 做成中**
|
实现查询每个学生的就业时长 **xxx 做成中**
|
||||||
实现统计每个班级的平均就业时长 **xxx 做成中**
|
实现统计每个班级的平均就业时长 **xxx 做成中**
|
||||||
|
|||||||
Reference in New Issue
Block a user