Merge remote-tracking branch 'origin/conding' into conding

# Conflicts:
#	PythonProject/api/student_api.py
#	PythonProject/dao/statistics_dao.py
This commit is contained in:
msj
2026-09-21 18:10:35 +08:00
18 changed files with 378 additions and 111 deletions
+29
View File
@@ -0,0 +1,29 @@
from fastapi import APIRouter,Depends,HTTPException
from dao import employment_dao
from dao.employment_dao import get_employment_dao
from schema.employment_schema import EmploymentRequest,EmploymentResponse
from model.all_model import ClassManagement,Employment_info
from util.database import get_db
emp_api = APIRouter()
@emp_api.get('employment/students/{stu_id}',response_model=EmploymentResponse,summary='获取学生就业信息')
def get_emp_info1(stu_id: int,db=Depends(get_db)):
try:
if stu_id:
return employment_dao.get_employment_info()
except:
raise HTTPException(status_code=404, detail='该学生就业信息不存在')
@emp_api.get('employment/class/{class_id}',summary='获取班级学生就业信息')
def get_emp_info2(class_id: int,db=Depends(get_db)):
try:
if class_id:
return employment_dao.get_employment_info()
except:
raise HTTPException(status_code=404, detail='该班级就业信息不存在')
# @emp_api.post('employment/students/{stu_id}')
# def create_emp_info(stu_id: int,db=Depends(get_db)):
# try:
# pass
+17 -1
View File
@@ -1,7 +1,8 @@
from fastapi import APIRouter,Depends,HTTPException,Path
from fastapi import APIRouter,Depends,HTTPException,Path,Form
from util.database import get_db
from model.all_model import Student_Model
from dao.grade_dao import *
from schema.grade_schema import *
gradeAPI = APIRouter(tags=['学生考核成绩'])
@@ -12,3 +13,18 @@ def get_grade(stu_id: int,db=Depends(get_db)):
return {'code': 200,'msg':'查询成功','data':res}
except Exception as e:
raise HTTPException(status_code=500,detail=f'数据库查询异常:{str(e)}')
@gradeAPI.post('/{stu_id}',response_model=GradeResponse,summary='添加学生成绩')
def post_grade(o:GradeRequest=Form(),db=Depends(get_db)):
exist_obj = get_grade_dao(db,o.stu_id)
if exist_obj:
raise HTTPException(status_code=409, detail="该学生此考核序次成绩已存在!")
d=o.model_dump()
r=add_grade_dao(g=d,db=db)
if not r:
raise HTTPException(status_code=400, detail='学生不存在')
return o
+31 -13
View File
@@ -1,20 +1,38 @@
from fastapi import APIRouter
from dao.statistics_dao import select_all,select_age,select_score
from fastapi import APIRouter,Depends
from dao.statistics_dao import select_all,select_age,select_score,select_avg_score,select_salary,select_days
from schema.student_schema import StudentResponse
from schema.statistics_schema import AllStuResponse,AvgDayResponse
from util.database import get_db
StudentAPI = APIRouter()
StatisticsAPI = APIRouter()
@StudentAPI.get("/age",response_model=StudentResponse,tags=['统计分析模块'],description='根据年龄查询学生信息')
def get_students(min_age:int|None=None,max_age:int|None=None):
l = select_age(min_age,max_age)
@StatisticsAPI.get("/age",response_model=list[StudentResponse],tags=['统计分析模块'],summary='根据年龄查询学生信息')
def get_students(min_age:int|None=None,max_age:int|None=None,db=Depends(get_db)):
l = select_age(min_age,max_age,db)
return l
@StatisticsAPI.get("/all",response_model=list[AllStuResponse],tags=['统计分析模块'],summary='统计每个班级的学员总数和男女生总数')
def get_students(db=Depends(get_db)):
l = select_all(db)
return l
@StatisticsAPI.get("/score",response_model=StudentResponse,tags=['统计分析模块'],summary='根据成绩查询学生信息')
def get_students(min_score:int|None=None,max_score:int|None=None,db=Depends(get_db)):
l = select_score(min_score,max_score,db)
return [i for i in l]
@StudentAPI.get("/all",response_model=StudentResponse,tags=['统计分析模块'],description='统计每个班级的学员总数和男女生总数')
def get_students():
l = select_all()
@StatisticsAPI.get("/avg_score",response_model=StudentResponse,tags=['统计分析模块'],summary='统计每次考试每个班级的平均分并排序')
def get_scores(db=Depends(get_db)):
l = select_avg_score(db)
return [i for i in l]
@StudentAPI.get("/score",response_model=StudentResponse,tags=['统计分析模块'],description='根据成绩查询学生信息')
def get_students(min_score:int|None=None,max_score:int|None=None):
l = select_score(min_score,max_score)
return [i for i in l]
@StatisticsAPI.get("/salary",response_model=list[StudentResponse],tags=['统计分析模块'],summary='统计薪资最高的前五名的学员信息')
def get_scores(db=Depends(get_db)):
l = select_salary(db)
return l
@StatisticsAPI.get("/avg_day",response_model=list[AvgDayResponse],tags=['统计分析模块'],summary='统计每个班级的平均就业时长')
def get_days(db=Depends(get_db)):
l = select_days(db)
return l
+15 -4
View File
@@ -6,7 +6,7 @@ from util.database import get_db
StudentAPI = APIRouter()
@StudentAPI.get('/',response_model=list[StudentPageResponse],description='查询学生信息')
@StudentAPI.get('/',response_model=list[StudentPageResponse],tags=['学⽣基本信息管理模块'],description='查询学生信息')
def get_students(stu_id:int|None=None
,stu_name:str|None=None
,class_id:int|None=None
@@ -29,7 +29,7 @@ def get_students(stu_id:int|None=None
, 'total': total
, 'data': r}
@StudentAPI.put('/{stu_id}')
@StudentAPI.put('/{stu_id}',tags=['学⽣基本信息管理模块'])
def update_students(s:StudentRequest
,stu_id:int
,db=Depends(get_db)):
@@ -41,7 +41,7 @@ def update_students(s:StudentRequest
raise HTTPException(status_code=500, detail='没有更新!')
return {'code':200,'totals':r,'detail':'更新成功'}
@StudentAPI.delete('/{stu_id}')
@StudentAPI.delete('/{stu_id}',tags=['学⽣基本信息管理模块'])
def del_students(stu_id:int
,db=Depends(get_db)):
rows=delete_student_dao( stu_id=stu_id,db=db )
@@ -49,7 +49,7 @@ def del_students(stu_id:int
raise HTTPException(status_code=500,detail='没有删除')
return {'code':200,'totals':rows,'detail':'删除成功'}
@StudentAPI.post('/',response_model=StugetResponse,description='新增学生')
@StudentAPI.post('/',tags=['学⽣基本信息管理模块'],response_model=StugetResponse)
def add_students(s:StudentRequest
,db=Depends(get_db)):
d=s.model_dump(exclude_unset=False)
@@ -59,3 +59,14 @@ def add_students(s:StudentRequest
return stu_new
@StudentAPI.put('/',tags=['学⽣基本信息管理模块'])
def get_students(stu_id:int|None = None
,stu_name:str|None = None
,class_id:int|None=None
,db=Depends(get_db)
,page:int=1
,page_size:int=10):
r = get_student_dao(stu_id,stu_name,class_id,db,page,page_size )
if r:
return r
raise HTTPException(status_code=404,detail='学生不存在!')
+12 -17
View File
@@ -1,15 +1,11 @@
from fastapi import APIRouter,HTTPException
from fastapi.params import Depends
from model.all_model import *
from schema.teacher_schema import Teacher_ResponseModel, Teacher_RequestModel
from tmpl.work.util.database import get_db
from dao.teacher_dao import *
teacher_api=APIRouter()
@teacher_api.post("",response_model=Teacher_ResponseModel)
def add_teacher1(teacher:Teacher_RequestModel,session=Depends(get_db())):
@teacher_api.post("/",response_model=Teacher_ResponseModel,tags=['教师基本信息管理模块'],summary='新增教师接口')
def add_teacher(teacher:Teacher_RequestModel,session=Depends(get_db)):
d=teacher.model_dump()
r=add_teacher(req=d,session=session)
if not r:
@@ -17,25 +13,24 @@ def add_teacher1(teacher:Teacher_RequestModel,session=Depends(get_db())):
return Teacher_ResponseModel(totals=1,data=d)
@teacher_api.get("",response_model=Teacher_ResponseModel)
def get_teacher(id:int,session=Depends(get_db)):
r = session.query(Teacher_Model).filter( Teacher_Model.teac_id == id ).all()
if r:
return [{'teac_name':i.teac_name,'teac_gender':i.teac_gender,'teac_age':i.teac_age,'teac_position':i.teac_position} for i in r]
raise HTTPException(status_code=404,detail='老师不存在!')
@teacher_api.get("/",response_model=Teacher_ResponseModel,tags=['教师基本信息管理模块'],summary='查询教师接口')
def get_teacher(id: int, session=Depends(get_db)):
r = get_teacher(id=id, session=session)
if not r:
raise HTTPException(status_code=500, detail='查询异常!')
@teacher_api.put("",response_model=Teacher_ResponseModel)
def update_teacher1(id:int,teacher:Teacher_RequestModel,session=Depends(get_db)):
d=teacher.model_dump
@teacher_api.put("/",response_model=Teacher_ResponseModel,tags=['教师基本信息管理模块'],summary='更新教师接口')
def update_teacher(id:int,teacher:Teacher_RequestModel,session=Depends(get_db)):
d=teacher.model_dump()
r=update_teacher(id=id,req=d,session=session)
if not r:
raise HTTPException(status_code=500, detail='更新异常!')
return {'code': 200, 'totals': r, 'detail': '更新成功'}
@teacher_api.delete("",response_model=Teacher_ResponseModel)
def delete_teacher1(id:int,session=Depends(get_db)):
@teacher_api.delete("/",response_model=Teacher_ResponseModel,tags=['教师基本信息管理模块'],summary='删除教师接口')
def delete_teacher(id:int,session=Depends(get_db)):
r=delete_teacher(id=id,session=session)
if not r:
raise HTTPException(status_code=500,detail='删除异常!')