mrz
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from fastapi import HTTPException,Depends
|
||||
from fastapi import HTTPException
|
||||
from sqlalchemy import func
|
||||
from model.all_model import Student_Model,WlScore
|
||||
from util.database import get_db
|
||||
from model.all_model import Student_Model,WlScore,Employment_info
|
||||
|
||||
# 实现根据年龄查询学生信息的功能
|
||||
def select_age(min_age,max_age,db):
|
||||
@@ -23,7 +22,8 @@ def select_age(min_age,max_age,db):
|
||||
# 实现统计每个班级的学员总数以及男女生的总数的功能
|
||||
def select_all(db):
|
||||
try:
|
||||
l1 = db.query(Student_Model.class_id,Student_Model.gender,func.count(1)).group_by(Student_Model.class_id,Student_Model.gender).all()
|
||||
l1 = db.query(Student_Model.class_id,Student_Model.gender,func.count(1).label('cnt'))\
|
||||
.group_by(Student_Model.class_id,Student_Model.gender).all()
|
||||
return l1
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
@@ -34,7 +34,8 @@ def select_score(min_score,max_score,db):
|
||||
if min_score is None and max_score is None:
|
||||
raise HTTPException(status_code=400, detail="请至少传入一个参数")
|
||||
db = db.query(Student_Model,WlScore.score,WlScore.score)\
|
||||
.join(WlScore,WlScore.stu_id == Student_Model.stu_id,WlScore.delete_status==0,WlScore.delete_status == 0)
|
||||
.join(WlScore,WlScore.stu_id == Student_Model.stu_id)\
|
||||
.filter(WlScore.delete_status==0,Student_Model.delete_status == 0)
|
||||
if min_score is not None:
|
||||
db = db.filter(WlScore.score >= min_score)
|
||||
if min_score is not None:
|
||||
@@ -45,3 +46,48 @@ def select_score(min_score,max_score,db):
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
|
||||
# 实现统计每次考试每个班级的平均分并排序的功能
|
||||
def select_avg_score(db):
|
||||
try:
|
||||
l1 = db.query(func.avg(WlScore.score))\
|
||||
.join(Student_Model,WlScore.stu_id == Student_Model.stu_id)\
|
||||
.filter(WlScore.delete_status==0,Student_Model.delete_status == 0)\
|
||||
.group_by(Student_Model.class_id)\
|
||||
.order_by(func.avg(WlScore.score)).all()
|
||||
return l1
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
|
||||
# 实现统计薪资最高的前五名的学员信息
|
||||
def select_salary(db):
|
||||
try:
|
||||
l1 = db.query(Student_Model,Employment_info.salary)\
|
||||
.join(Employment_info,Employment_info.stu_id==Student_Model.stu_id)\
|
||||
.filter(Employment_info.delete_status==0,Student_Model.delete_status == 0)\
|
||||
.order_by(Employment_info.salary.desc())\
|
||||
.limit(5).all()
|
||||
return l1
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
|
||||
# 实现统计每个班级的平均就业时长
|
||||
def select_days(db):
|
||||
try:
|
||||
l1 = db.query(Student_Model.class_id,
|
||||
func.coalesce(
|
||||
func.avg(
|
||||
func.datediff(
|
||||
Employment_info.offer_issuance_date, Employment_info.employment_opening_date
|
||||
)
|
||||
),0).label("avg_days")
|
||||
).join(Employment_info,Employment_info.stu_id == Student_Model.stu_id)\
|
||||
.filter(Student_Model.delete_status == 0,
|
||||
Employment_info.delete_status == 0,
|
||||
Employment_info.employment_opening_date.isnot(None),
|
||||
Employment_info.offer_issuance_date.isnot(None),)\
|
||||
.group_by( Student_Model.class_id)\
|
||||
.order_by(func.avg(func.datediff(Employment_info.offer_issuance_date,Student_Model.admission_date)).desc()).all()
|
||||
return l1
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500, detail="查询异常")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user