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

This commit is contained in:
msj
2026-09-22 09:56:40 +08:00
9 changed files with 147 additions and 59 deletions
+42 -14
View File
@@ -1,25 +1,53 @@
from fastapi import APIRouter,Depends,HTTPException
from fastapi import APIRouter, Query, Depends, HTTPException, Path
from util.database import get_db
from dao import employment_dao
from dao.employment_dao import get_employment_dao
from schema.employment_schema import EmploymentResponse
from model.all_model import ClassManagement,Employment_info
from dao.employment_dao import get_emp_dao, add_emp_dao, check_stu_dao, update_emp_dao, delete_emp_dao
from schema.employment_schema import EmploymentRequest,EmploymentResponse
from util.database import get_db
from typing import Optional
emp_api = APIRouter(tags=['学生就业管理系统'])
@emp_api.get('/employment/students/{stu_id}',response_model=EmploymentResponse,summary='获取学生就业信息')
def get_emp_info1(stu_id: int,db=Depends(get_db)):
if stu_id:
return employment_dao.get_employment_dao(stu_id=stu_id,db=db)
def get_emp_info1(stu_id: Optional[int]=Path(description='学生编号')
,company_name: Optional[str]=Query(None,description='公司名称')
,min_salary: Optional[float]=Query(None,description='最低工资')
,max_salary: Optional[float]=Query(None,description='最高工资')
,db=Depends(get_db)):
if stu_id or company_name or min_salary or max_salary:
return [employment_dao.get_emp_dao(stu_id=stu_id,db=db)]
raise HTTPException(status_code=404, detail='该学生就业信息不存在')
@emp_api.get('/employment/class/{class_id}',response_model=EmploymentResponse,summary='获取班级学生就业信息')
def get_emp_info2(class_id: int,db=Depends(get_db)):
def get_emp_info2(class_id: Optional[int],db=Depends(get_db)):
if class_id:
return employment_dao.get_employment_dao(class_id=class_id,db=db)
return employment_dao.get_emp_dao(class_id=class_id,db=db)
raise HTTPException(status_code=404, detail='该班级就业信息不存在')
# @emp_api.post('/employment/students/{stu_id}')
# def create_emp_info(stu_id: int,db=Depends(get_db),response_model=EmploymentResponse):
# if stu_id:
#
# return employment_dao.
@emp_api.post('/employment/students/{stu_id}',response_model=EmploymentResponse,summary='新增学生就业信息')
def create_emp_info(stu_id:int,emp:EmploymentRequest,db=Depends(get_db)):
if not check_stu_dao(stu_id,db):
raise HTTPException(status_code=404, detail='该学生不存在,无法添加就业信息')
emp.stu_id = stu_id
exist = db.query(employment_dao.Employment_info).filter(employment_dao.Employment_info.stu_id == stu_id,employment_dao.Employment_info.delete_status == 0).first()
if exist:
raise HTTPException(status_code=409,detail='该学生已有就业信息,请勿重复增加!')
d=emp.model_dump(exclude_unset=False)
r=add_emp_dao(d,db)
if not r:
raise HTTPException(status_code=500,detail='服务器繁忙,请稍后添加!')
return r
@emp_api.put('/employment/students/{stu_id}',response_model=EmploymentResponse,summary='更新学生就业信息')
def update_emp_info(stu_id:int,emp:EmploymentRequest,db=Depends(get_db)):
d = emp.model_dump(exclude_unset=True)
r = update_emp_dao(stu_id,d,db)
if not r:
raise HTTPException(status_code=500,detail='更新失败!')
return {'code':200,'totals':r,'detail':'更新成功!'}
@emp_api.delete('/employment/{stu_id}',summary='删除学生就业信息')
def delete_emp_info(stu_id:int,db=Depends(get_db)):
rows = delete_emp_dao(stu_id, db)
if not rows:
raise HTTPException(status_code=500, detail='没有删除!')
return {'code':200,'detail':'删除成功!'}
+32 -10
View File
@@ -6,11 +6,11 @@ from schema.grade_schema import *
gradeAPI = APIRouter(tags=['学生考核成绩'])
@gradeAPI.get("/grade/{stu_id}",summary="根据学生id查询成绩")
@gradeAPI.get("/grade/{stu_id}",response_model=list[GradeResponse],summary="根据学生id查询成绩")
def get_grade(stu_id: int,db=Depends(get_db)):
try:
res=get_grade_dao(stu_id,db)
return {'code': 200,'msg':'查询成功','data':res}
return res
except Exception as e:
raise HTTPException(status_code=500,detail=f'数据库查询异常:{str(e)}')
@@ -23,14 +23,36 @@ def post_grade(o:GradeRequest=Form(),db=Depends(get_db)):
return o
@gradeAPI.put('/{score_id}',summary='成绩修改')
def put_grade(score_id: int,o:GradeUpdate,db=Depends(get_db)):
d = o.model_update(exclude_unset=True)
r = update_grade_dao(score_id=score_id
,update_data=d
,db=db)
if not r:
raise HTTPException(status_code=500,detail='没有更新')
return {'code':200,'totals':r,'detail':'更新成功'}
def put_grade(
score_id: int
,o:GradeUpdate=Form()
,db=Depends(get_db)
):
old_obj = get_score_by_id_dao(score_id=score_id, db=db)
if not old_obj:
raise HTTPException(status_code=404, detail="成绩记录不存在(已删除)")
d = o.model_dump(exclude_unset=True)
if not d:
raise HTTPException(status_code=400,detail='请传入需要修改的字段')
if "exam_order" in d:
exist_obj = get_score_by_stu_exam_order_dao(
stu_id=old_obj.stu_id,
exam_order=d["exam_order"],
db=db
)
if exist_obj and exist_obj.id != score_id:
raise HTTPException(status_code=409, detail="修改后的考核序次,该学生已有成绩!")
try:
r = update_grade_dao(score_id=score_id, update_data=d, db=db)
except Exception:
raise HTTPException(status_code=409, detail="数据冲突,重复数据")
if r == 0:
return {"code": 200, "totals": r, "detail": "数据未发生变化"}
return {"code": 200, "totals": r, "detail": "更新成功"}
@gradeAPI.delete('/{score_id}',summary='删除成绩')
def delete_grade(score_id:int,db=Depends(get_db)):
+2 -2
View File
@@ -1,4 +1,4 @@
from fastapi import APIRouter,Depends
from fastapi import APIRouter,Depends,Query
from dao.statistics_dao import *
from schema.student_schema import StudentResponse
from schema.statistics_schema import *
@@ -7,7 +7,7 @@ from util.database import get_db
StatisticsAPI = APIRouter()
@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)):
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
+1 -1
View File
@@ -41,4 +41,4 @@ def delete_teacher1(t_id:int,session=Depends(get_db)):
r=delete_teacher(id=t_id,session=session)
if not r:
raise HTTPException(status_code=500,detail='删除异常!')
return {'code': 200, 'detail': 'cg'}
return {'code': 200, 'detail':'成功!'}