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

This commit is contained in:
test1
2026-09-22 09:18:43 +08:00
11 changed files with 161 additions and 71 deletions
+2 -2
View File
@@ -10,8 +10,8 @@ def add_class(data: claRequest, Session = Depends(get_db)):
return add_class_dao(data, Session)
@claAPI.get("/list", summary="查询班级")
def list_class(Session = Depends(get_db)):
return get_class_dao(Session)
def list_class(n:int,m:int,Session = Depends(get_db)):
return get_class_dao(n,m,Session)
@claAPI.put("/{class_id}", summary="更新班级信息")
def update_class(class_id: int, data: claRequest, Session = Depends(get_db)):
+42 -14
View File
@@ -1,25 +1,53 @@
from fastapi import APIRouter,Depends,HTTPException
from fastapi import APIRouter,Query,Depends,HTTPException
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]=Query(None,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)):
+5 -7
View File
@@ -6,7 +6,7 @@ from util.database import get_db
StudentAPI = APIRouter()
@StudentAPI.get('/students',response_model=list[StudentPageResponse],tags=['学⽣基本信息管理模块'],summary='学生信息查询接口',description='查询学生信息')
@StudentAPI.get('/students',response_model=StudentPageResponse,tags=['学⽣基本信息管理模块'],summary='学生信息查询接口',description='查询学生信息')
def get_students(stu_id:int|None=None
,stu_name:str|None=None
,class_id:int|None=None
@@ -22,12 +22,10 @@ def get_students(stu_id:int|None=None
if not r:
raise HTTPException(status_code=404,detail='学生不存在')
return {'code': 200
, 'detail': 'ok'
, 'page': page
, 'page_size': page_size
, 'total': total
, 'data': r}
return StudentPageResponse(page=page,
page_size=page_size,
total=total,
data=r)
@StudentAPI.put('/{stu_id}',tags=['学⽣基本信息管理模块'],summary='学生信息更新接口',description='更新学生信息')
def update_students(s:StudentRequest