From 3087aac1da05edff1313a52113d2ce4398a19893 Mon Sep 17 00:00:00 2001 From: wolin_chenyulin001 <123@163.com> Date: Tue, 22 Sep 2026 22:52:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9put=E5=92=8Cdelete=E7=9A=84?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=8F=82=E6=95=B0=E4=B8=BAstu=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonProject/api/employment_api.py | 12 ++++++------ PythonProject/dao/employment_dao.py | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/PythonProject/api/employment_api.py b/PythonProject/api/employment_api.py index 6faec0e..d2d8efb 100644 --- a/PythonProject/api/employment_api.py +++ b/PythonProject/api/employment_api.py @@ -39,16 +39,16 @@ def create_emp_info(emp:EmploymentRequest=Form(),db=Depends(get_db)): raise HTTPException(status_code=500,detail='服务器繁忙,请稍后添加!') return r -@emp_api.put('/employment/students/{emp_id}',summary='更新学生就业信息') -def update_emp_info(emp_id:int,emp:UpdateEmpRequest,db=Depends(get_db)): - r = update_emp_dao(emp_id,emp.model_dump(exclude_unset=True),db) +@emp_api.put('/employment/students/{stu_id}',summary='更新学生就业信息') +def update_emp_info(stu_id:int,emp:UpdateEmpRequest,db=Depends(get_db)): + r = update_emp_dao(stu_id,emp.model_dump(exclude_unset=True),db) if not r: raise HTTPException(status_code=500,detail='没有更新!') return {'code':200,'totals':r,'detail':'更新成功!'} -@emp_api.delete('/employment/{emp_id}',summary='删除学生就业信息') -def delete_emp_info(emp_id:int=Path(description='序号'),db=Depends(get_db)): - rows = delete_emp_dao(emp_id, db) +@emp_api.delete('/employment/{stu_id}',summary='删除学生就业信息') +def delete_emp_info(stu_id:int=Path(description='序号'),db=Depends(get_db)): + rows = delete_emp_dao(stu_id, db) if not rows: raise HTTPException(status_code=500, detail='没有删除!') return {'code':200,'detail':'删除成功!'} diff --git a/PythonProject/dao/employment_dao.py b/PythonProject/dao/employment_dao.py index 9e0f8b7..2a738af 100644 --- a/PythonProject/dao/employment_dao.py +++ b/PythonProject/dao/employment_dao.py @@ -41,8 +41,8 @@ def add_emp_dao(o,db): if not stu: raise HTTPException(status_code=404, detail='该学生不存在,无法添加就业信息') - exist = (db.query(Employment_info).filter(Employment_info.stu_id == o['stu_id'] - ,Employment_info.delete_status == 0).first()) + exist = db.query(Employment_info).filter(Employment_info.stu_id == o['stu_id'] + ,Employment_info.delete_status == 0).first() if exist: raise HTTPException(status_code=409, detail='该学生已有就业信息,请勿重复增加!') @@ -54,22 +54,22 @@ def add_emp_dao(o,db): db.rollback() raise HTTPException(status_code=500, detail=f'新增就业信息失败: {e}') -def update_emp_dao(emp_id,emp,db): +def update_emp_dao(stu_id,emp,db): try: rows = db.query(Employment_info)\ - .filter(Employment_info.emp_id == emp_id,Employment_info.delete_status == 0)\ + .filter(Employment_info.stu_id == stu_id,Employment_info.delete_status == 0)\ .update(emp) db.commit() return rows except: db.rollback() - raise HTTPException(status_code=404,detail='该就业记录已存在') + raise HTTPException(status_code=404,detail='该就业记录不存在') -def delete_emp_dao(emp_id:int,db): +def delete_emp_dao(stu_id:int,db): try: rows = db.query(Employment_info)\ - .filter(Employment_info.emp_id == emp_id + .filter(Employment_info.stu_id == stu_id ,Employment_info.delete_status == 0)\ .update({'delete_status':1,'delete_time': datetime.now()}) db.commit()