添加statistics tag

This commit is contained in:
2026-09-23 20:56:36 +08:00
parent 93f2356c5d
commit d70705e7fe
3 changed files with 14 additions and 6 deletions
+3 -3
View File
@@ -32,7 +32,7 @@ def list_score(
return {"total": total, "data": data_list} return {"total": total, "data": data_list}
@scores_router.put("{score_id}", summary="更新成绩接口") @scores_router.put("/{score_id}", summary="更新成绩接口")
def modify_score(score_id: int, req: ScoreUpdate, db: Session = Depends(get_db)): def modify_score(score_id: int, req: ScoreUpdate, db: Session = Depends(get_db)):
update_dict = req.model_dump(exclude_unset=True) update_dict = req.model_dump(exclude_unset=True)
if not update_dict: if not update_dict:
@@ -43,9 +43,9 @@ def modify_score(score_id: int, req: ScoreUpdate, db: Session = Depends(get_db))
return {"msg": "修改成功"} return {"msg": "修改成功"}
@scores_router.delete("{score_id}", summary="删除成绩接口") @scores_router.delete("/{score_id}", summary="删除成绩接口")
def remove_score(score_id: int, db: Session = Depends(get_db)): def remove_score(score_id: int, db: Session = Depends(get_db)):
ok = delete_score_dao(score_id, db) ok = delete_score_dao(score_id, db)
if not ok: if not ok:
raise HTTPException(status_code=400, detail="删除失败,记录不存在或已删除") raise HTTPException(status_code=400, detail="删除失败,记录不存在或已删除")
return {"msg": "逻辑删除成功"} return {"msg": "逻辑删除成功"}
+2 -2
View File
@@ -3,7 +3,6 @@ from sqlalchemy import func
#`GET /statistics/students/age-over-30` #`GET /statistics/students/age-over-30`
#查询所有超过 30 岁的学员信息 #查询所有超过 30 岁的学员信息
def age_over_thirty(Student,db): def age_over_thirty(Student,db):
student_list=db.query(Student).filter(Student.age>30,Student.is_deleted==0).all() student_list=db.query(Student).filter(Student.age>30,Student.is_deleted==0).all()
if not student_list : if not student_list :
@@ -30,7 +29,7 @@ def age_over_thirty(Student,db):
"is_deleted": student.is_deleted, "is_deleted": student.is_deleted,
}) })
return result return result
#统计男、女、总人数
def gender_count(Student,db): def gender_count(Student,db):
result=db.query(Student.class_id,Student.gender,func.count(Student.id)).filter(Student.is_deleted==0).group_by(Student.class_id,Student.gender).all() result=db.query(Student.class_id,Student.gender,func.count(Student.id)).filter(Student.is_deleted==0).group_by(Student.class_id,Student.gender).all()
if not result : if not result :
@@ -43,6 +42,7 @@ def gender_count(Student,db):
dict1[i]['总人数']+=k dict1[i]['总人数']+=k
return dict1 return dict1
#查询每次考试成绩都在 80 分以上的学生编号、姓名和成绩 #查询每次考试成绩都在 80 分以上的学生编号、姓名和成绩
#首先,拿到最低值>80的人的列表,row。然后,遍历元素拿到符合条件的id的属性。
def score_over_eighty(Score,Student,db): def score_over_eighty(Score,Student,db):
student_list=db.query(Student.id, Student.student_name)\ student_list=db.query(Student.id, Student.student_name)\
.join(Score,Score.student_id==Student.id).filter(Student.is_deleted==0,Score.is_deleted==0).group_by(Student.id,Student.student_name)\ .join(Score,Score.student_id==Student.id).filter(Student.is_deleted==0,Score.is_deleted==0).group_by(Student.id,Student.student_name)\
+9 -1
View File
@@ -1,4 +1,7 @@
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.responses import RedirectResponse
from fastapi.staticfiles import StaticFiles
from pathlib import Path
from api.example import example_router from api.example import example_router
from middleware import log_middleware from middleware import log_middleware
from api.statistics import statistics_router from api.statistics import statistics_router
@@ -8,6 +11,12 @@ from api.teacher import router as teacher_router,class_teacher_router
from api.magic import magic_router from api.magic import magic_router
app = FastAPI(title='学生管理系统') app = FastAPI(title='学生管理系统')
app.mount("/ui", StaticFiles(directory=Path(__file__).resolve().parent / "frontend", html=True), name="frontend")
@app.get("/", include_in_schema=False)
def home():
return RedirectResponse("/ui/")
app.middleware("http")(log_middleware) app.middleware("http")(log_middleware)
app.include_router(magic_router) app.include_router(magic_router)
@@ -25,7 +34,6 @@ from api import consultant
app.include_router(consultant.router) app.include_router(consultant.router)
#-------------张昕浩--------------- #-------------张昕浩---------------
app.include_router(example_router) app.include_router(example_router)
app.include_router(magic_router)
app.include_router(statistics_router, prefix="/statistics") app.include_router(statistics_router, prefix="/statistics")
#-------------曾凯--------------- #-------------曾凯---------------