From 5020eeb640dec355eb53985b41605c7c3d444034 Mon Sep 17 00:00:00 2001 From: yb <739325183@qq.com> Date: Tue, 22 Sep 2026 17:02:59 +0800 Subject: [PATCH] =?UTF-8?q?statcalc=E5=B0=B1=E4=B8=9A=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 +- StatCalc/api/statcalc_api.py | 32 ++++++++++++++++++++++++++++++++ stu_jiuye/CURD_api.py | 6 ++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 30b7315..bbd34b4 100644 --- a/.env +++ b/.env @@ -1,7 +1,7 @@ # .env(放项目根目录,每个人自己建,不提交 Git) # 用来修改数据库账户密码 DB_USER=root -DB_PASSWORD=420821 +DB_PASSWORD=123456 DB_HOST=localhost DB_PORT=3306 DB_NAME=student_manage_system \ No newline at end of file diff --git a/StatCalc/api/statcalc_api.py b/StatCalc/api/statcalc_api.py index 343e519..dabea0a 100644 --- a/StatCalc/api/statcalc_api.py +++ b/StatCalc/api/statcalc_api.py @@ -113,4 +113,36 @@ def get_students( stu:StudentsQuery = Depends() raise HTTPException(status_code=404, detail="没有找到符合条件的学生") +@CURD.get('/Top5',summary='就业薪资Top5') +def salarytop5(db=Depends(get_db)): + q = db.query(Employments,Company.employment_company) \ + .join(Company, Employments.company_id == Company.id) \ + .filter(Employments.is_deleted == 0)\ + .order_by(Employments.employment_salary.desc())\ + .limit(5) .all() + return [{'学生姓名':i.sname,'学生班级编号':i.class_num,'就业时间':i.offer_recived_time,'公司':employment_company} for i,employment_company in q] +@CURD.get('/worktime',summary='学生就业时常') +def worktime(db=Depends(get_db)): + q = db.query(Employments)\ + .filter(Employments.is_deleted==0)\ + .all() + + return [{'学生姓名':i.sname,'就业时常':f'{i.offer_recived_time-i.employment_open_time}' if i.offer_recived_time and i.employment_open_time else '暂无数据'} for i in q] + + +@CURD.get('/avgworktime',summary='学生平均就业时常') +def avgworktime(db=Depends(get_db)): + q = db.query(Employments)\ + .filter(Employments.employment_open_time.isnot(None) + ,Employments.offer_recived_time.isnot(None) + ,Employments.is_deleted==0)\ + .all() + if not q: + return {'平均就业时常': '暂无数据'} + total = sum((i.offer_recived_time - i.employment_open_time).total_seconds() for i in q) + avg_days=total /len(q)/86400 #一天86400秒 + return { + '人数': len(q), + '平均就业时常(天)': round(avg_days, 2) + } diff --git a/stu_jiuye/CURD_api.py b/stu_jiuye/CURD_api.py index e35592e..608fd20 100644 --- a/stu_jiuye/CURD_api.py +++ b/stu_jiuye/CURD_api.py @@ -96,7 +96,7 @@ def delete_stuinfo( #删除模块 raise HTTPException(status_code=500, detail='没有删除!') #失败返回错误信息 return {'code': 200, 'totals': rows, 'detail': '删除成功'} #成功返回信息 - +''' @CURD.get('/Top5',summary='就业薪资Top5') def salarytop5(db=Depends(get_db)): q = db.query(Employments,Company.employment_company) \ @@ -129,4 +129,6 @@ def avgworktime(db=Depends(get_db)): return { '人数': len(q), '平均就业时常(天)': round(avg_days, 2) - } \ No newline at end of file + } + +''' \ No newline at end of file