From 22583badc27df9ec88812ee153d791f401aa9b1f Mon Sep 17 00:00:00 2001 From: wolin_ck666_999 Date: Tue, 22 Sep 2026 14:11:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=E3=80=8Capi=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/tj_api.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 api/tj_api.py diff --git a/api/tj_api.py b/api/tj_api.py new file mode 100644 index 0000000..04bd933 --- /dev/null +++ b/api/tj_api.py @@ -0,0 +1,56 @@ +from fastapi import APIRouter, Depends,FastAPI +from model.teaModel import Session +from dao.dao1 import fun1,fun2,fun3,fun4,fun5,fun6, fun7 ,fun8 + +StatsAPI = APIRouter(prefix='/stats', tags=['统计分析']) +app = FastAPI() +app.include_router(StatsAPI) +def get_db(): + db=Session() + try: + yield db + finally: + db.close() + +@StatsAPI.get('/age-over-30', summary='超过30岁学员') +def stat_age(db= Depends(get_db)): + rows = fun1(db) + return {'code': 200, 'data':rows } + +@StatsAPI.get('/class-gender', summary='各班人数及男女比') +def stat_class_gender(db= Depends(get_db)): + rows = fun2(db) + return {'code': 200, 'data': rows} + +@StatsAPI.get('/all-pass-80', summary='每次考试都≥80分') +def stat_pass80(db= Depends(get_db)): + rows = fun3(db) + return {'code': 200, 'data': rows} + +@StatsAPI.get('/two-fail', summary='两次以上不及格') +def stat_fail(db= Depends(get_db)): + rows = fun4(db) + return {'code': 200, 'data': rows} + +@StatsAPI.get('/avg-score', summary='各班每次考试平均分') +def stat_avg(db= Depends(get_db)): + rows = fun5(db) + return {'code': 200, 'data': rows} + +@StatsAPI.get('/top5-salary', summary='薪资前五名') +def stat_top5(db= Depends(get_db)): + rows = fun6(db) + return rows +@StatsAPI.get('/duration', summary='每个学生就业时长') +def stat_duration(db= Depends(get_db)): + rows = fun7(db) + return {'code': 200, 'data': rows} + +@StatsAPI.get('/avg-duration', summary='各班平均就业时长') +def stat_avg_duration(db= Depends(get_db)): + rows = fun8(db) + return {'code': 200, 'data': rows} + +if __name__ == '__main__': + import uvicorn + uvicorn.run('cxjk:app',host='127.0.0.1',port=9999) \ No newline at end of file -- 2.54.0