From 40a6d79b37adfc443952c6466d9b70dd586f3b7b Mon Sep 17 00:00:00 2001 From: 0919word <835535015@qq.com> Date: Tue, 22 Sep 2026 15:43:19 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=92=8B=E7=AB=8B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/dao/cla_dao.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PythonProject/dao/cla_dao.py b/PythonProject/dao/cla_dao.py index 23267a9..a75a7e4 100644 --- a/PythonProject/dao/cla_dao.py +++ b/PythonProject/dao/cla_dao.py @@ -1,6 +1,7 @@ from model.all_model import ClassManagement from fastapi import HTTPException from schema.cla_schema import claRequest +from datetime import datetime def add_class_dao(c: claRequest, session): @@ -34,7 +35,7 @@ def update_class_dao(id:int,req:claRequest,session): def delete_class_dao(id:int,session): try: session.query(ClassManagement).filter(ClassManagement.class_id==id,ClassManagement.delete_status==0)\ - .update({'delete_status': 1}) + .update({'delete_status': 1,'delete_time': datetime.now()}) session.commit() except: raise HTTPException(status_code=404, detail="删除异常,请重新核对之后删除!") From 7a25cf6f681bb3d30b177dafecf41e0c40ca3523 Mon Sep 17 00:00:00 2001 From: maruizhi <3088243241@qq.com> Date: Tue, 22 Sep 2026 15:44:56 +0800 Subject: [PATCH 2/4] mrz --- PythonProject/api/statistics_api.py | 2 +- PythonProject/dao/statistics_dao.py | 30 +++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/PythonProject/api/statistics_api.py b/PythonProject/api/statistics_api.py index a5f2867..649c779 100644 --- a/PythonProject/api/statistics_api.py +++ b/PythonProject/api/statistics_api.py @@ -6,7 +6,7 @@ from util.database import get_db StatisticsAPI = APIRouter(tags=['统计分析模块']) -@StatisticsAPI.get("/age",response_model=list[StudentResponse],summary='根据年龄查询学生信息') +@StatisticsAPI.get("/age",response_model=list[StugetResponse],summary='根据年龄查询学生信息') def get_students(min_age:int|None=Query(None,ge=0,le=150),max_age:int|None=Query(None,ge=0,le=150),db=Depends(get_db)): l = select_age(min_age,max_age,db) return l diff --git a/PythonProject/dao/statistics_dao.py b/PythonProject/dao/statistics_dao.py index fd8251d..0306a61 100644 --- a/PythonProject/dao/statistics_dao.py +++ b/PythonProject/dao/statistics_dao.py @@ -38,8 +38,11 @@ def select_all(db): "gender": i.gender, "cnt": i.cnt }) - + if not l2: + raise HTTPException(status_code=404, detail="没有数据") return l2 + except HTTPException: + raise except Exception: raise HTTPException(status_code=500,detail="查询异常") @@ -66,7 +69,10 @@ def select_score(min_score,max_score,db): db = db.filter(WlScore.score >= min_score) if max_score is not None: db = db.filter(WlScore.score <= max_score) - return db.all() + l1 = db.all() + if not l1: + raise HTTPException(status_code=404, detail="没有数据") + return l1 except HTTPException: raise except Exception: @@ -80,7 +86,11 @@ def select_avg_score(db): .filter(WlScore.delete_status==0,Student_Model.delete_status == 0)\ .group_by(Student_Model.class_id)\ .order_by(func.round(func.avg(WlScore.score),1)).all() + if not l1: + raise HTTPException(status_code=404, detail="没有数据") return l1 + except HTTPException: + raise except Exception: raise HTTPException(status_code=500,detail="查询异常") @@ -102,7 +112,11 @@ def select_salary(db): .filter(Employment_info.delete_status==0,Student_Model.delete_status == 0)\ .order_by(Employment_info.salary.desc())\ .limit(5).all() + if not l1: + raise HTTPException(status_code=404, detail="没有数据") return l1 + except HTTPException: + raise except Exception: raise HTTPException(status_code=500,detail="查询异常") @@ -123,19 +137,27 @@ def select_avg_days(db): 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() + if not l1: + raise HTTPException(status_code=404, detail="没有数据") return l1 + except HTTPException: + raise except Exception: raise HTTPException(status_code=500, detail="查询异常") #统计每个学⽣的就业时⻓ def select_days(db): try: - l2 =db.query(Employment_info.stu_id + l1 =db.query(Employment_info.stu_id ,func.coalesce(func.datediff(Employment_info.offer_issuance_date ,Employment_info.employment_opening_date),0)\ .label("diff_days") ).filter(Employment_info.delete_status == 0).all() - return l2 + if not l1: + raise HTTPException(status_code=404, detail="没有数据") + return l1 + except HTTPException: + raise except Exception: raise HTTPException(status_code=500, detail="查询异常") From 664741e52f74507cdb14691ebedfa047db5d0635 Mon Sep 17 00:00:00 2001 From: maruizhi <3088243241@qq.com> Date: Tue, 22 Sep 2026 15:46:20 +0800 Subject: [PATCH 3/4] mrz --- PythonProject/api/student_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PythonProject/api/student_api.py b/PythonProject/api/student_api.py index 5006068..6dbddd2 100644 --- a/PythonProject/api/student_api.py +++ b/PythonProject/api/student_api.py @@ -19,7 +19,7 @@ def get_students(stu_id:int|None=None ,page=page ,page_size=page_size ,db=db) - return StudentPageResponse(page=page, + return StuPageResponse(page=page, page_size=page_size, totals=total, data=r) From 847b908c4f24a66b888cf4c2b1e2b01b9c627993 Mon Sep 17 00:00:00 2001 From: test1 Date: Tue, 22 Sep 2026 16:02:51 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E9=A9=AC=E7=9D=BF=E6=99=BA=E7=89=9B?= =?UTF-8?q?=E9=80=BC=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/api/statistics_api.py | 5 +++++ PythonProject/dao/statistics_dao.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/PythonProject/api/statistics_api.py b/PythonProject/api/statistics_api.py index 649c779..86c09e2 100644 --- a/PythonProject/api/statistics_api.py +++ b/PythonProject/api/statistics_api.py @@ -45,3 +45,8 @@ def get_emp(db=Depends(get_db)): def get_salaries(db=Depends(get_db)): s=classify_salary(db) return s + +@StatisticsAPI.get('/avg_salaries',summary='统计每个班级平均薪资') +def get_avg_salaries(db=Depends(get_db)): + s=avg_salary(db) + return s diff --git a/PythonProject/dao/statistics_dao.py b/PythonProject/dao/statistics_dao.py index 0306a61..f6576b5 100644 --- a/PythonProject/dao/statistics_dao.py +++ b/PythonProject/dao/statistics_dao.py @@ -182,3 +182,15 @@ def classify_salary(db): except: raise HTTPException(status_code=500,detail='查询异常!') +#统计每个班的平均就业薪资 +def avg_salary(db): + try: + l=db.query(Student_Model.class_id,func.avg(Employment_info.salary).label('avg_salaries'))\ + .join(Employment_info,Employment_info.stu_id == Student_Model.stu_id)\ + .filter(Employment_info.salary>0,Employment_info.delete_status==0,Student_Model.delete_status==0)\ + .group_by(Student_Model.class_id)\ + .order_by(func.avg(Employment_info.salary).desc()).all() + return l + except: + raise HTTPException(status_code=500,detail='统计异常!') +