This commit is contained in:
maruizhi
2026-09-22 11:49:44 +08:00
parent 751d430e3e
commit bff10de7fa
4 changed files with 98 additions and 22 deletions
+38 -7
View File
@@ -23,7 +23,17 @@ def select_all(db):
try:
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
all_cnt = sum(i.cnt for i in l1)
l2 = []
for i in l1:
l2.append({
"all_cnt": all_cnt,
"class_id": i.class_id,
"gender": i.gender,
"cnt": i.cnt
})
return l2
except Exception:
raise HTTPException(status_code=500,detail="查询异常")
@@ -32,12 +42,23 @@ def select_score(min_score,max_score,db):
try:
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)\
db = db.query(WlScore.score
,Student_Model.stu_name
,Student_Model.age
,Student_Model.gender
,Student_Model.native_place
,Student_Model.school
,Student_Model.major
,Student_Model.degree
,Student_Model.admission_date
,Student_Model.graduation_date
,Student_Model.progress
)\
.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:
if max_score is not None:
db = db.filter(WlScore.score <= max_score)
return db.all()
except HTTPException:
@@ -60,7 +81,17 @@ def select_avg_score(db):
# 实现统计薪资最高的前五名的学员信息
def select_salary(db):
try:
l1 = db.query(Student_Model,Employment_info.salary)\
l1 = db.query(Employment_info.salary
,Student_Model.stu_name
,Student_Model.age
,Student_Model.gender
,Student_Model.native_place
,Student_Model.school
,Student_Model.major
,Student_Model.degree
,Student_Model.admission_date
,Student_Model.graduation_date
,Student_Model.progress)\
.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())\
@@ -70,7 +101,7 @@ def select_salary(db):
raise HTTPException(status_code=500,detail="查询异常")
# 实现统计每个班级的平均就业时长
def select_days(db):
def select_avg_days(db):
try:
l1 = db.query(Student_Model.class_id,
func.coalesce(
@@ -84,14 +115,14 @@ def select_days(db):
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)\
.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="查询异常")
#统计每个学⽣的就业时⻓
def select_days2(db):
def select_days(db):
try:
l2 =db.query(
Employment_info.stu_id