From f2b311519b10196b03b98916cd3a31a8ffff80fc Mon Sep 17 00:00:00 2001 From: wolin_ck666_999 Date: Tue, 22 Sep 2026 15:30:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20dao/epy=5Fdao.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/{e_dao.py => epy_dao.py} | 104 +++++++++++++++++------------------ 1 file changed, 52 insertions(+), 52 deletions(-) rename dao/{e_dao.py => epy_dao.py} (96%) diff --git a/dao/e_dao.py b/dao/epy_dao.py similarity index 96% rename from dao/e_dao.py rename to dao/epy_dao.py index 015e65d..1b12ed1 100644 --- a/dao/e_dao.py +++ b/dao/epy_dao.py @@ -1,52 +1,52 @@ -from http.client import HTTPException - -from model.e_model import Employment -from fastapi import HTTPException - -def get_employment_dao(db): - try: - r = db.query(Employment).all() - except Exception as e: - db.rollback() - raise HTTPException(status_code=500, detail=f'查询失败:str(e)') - else: - db.commit() - return [{'stu_id':i.stu_id,'class_name':i.class_name} for i in r ] - - -def wq_employment_dao(o,db): - try: - o1 = Employment(**o) - db.add(o1) - except Exception as e: - db.rollback() - raise HTTPException(status_code=500, detail=f'添加失败:str(e)') - else: - db.commit() - return 1 - -def upd_employment_dao(e,db): - try: - rows = db.query(Employment).filter(Employment.stu_id == e['stu_id']).update(e) - except: - db.rollback() - raise HTTPException(status_code=500, detail='更新异常,请稍后再执行!') - else: - db.commit() - return 1 - -def del_employment_dao(stu_id,db): - try: - row = db.query(Employment).filter(Employment.stu_id == stu_id).all() - if not row: - raise HTTPException(status_code=404,detail='记录不存在') - for i in row: - if i.deleted == 0: - db.query(Employment).filter(Employment.stu_id == i.stu_id).update({'deleted':1}) - except Exception as e: - db.rollback() - raise HTTPException(status_code=500,detail=f'删除失败:{str(e)}') - else: - db.commit() - return 1 - +from http.client import HTTPException + +from model.e_model import Employment +from fastapi import HTTPException + +def get_employment_dao(db): + try: + r = db.query(Employment).all() + except Exception as e: + db.rollback() + raise HTTPException(status_code=500, detail=f'查询失败:str(e)') + else: + db.commit() + return [{'stu_id':i.stu_id,'class_name':i.class_name} for i in r ] + + +def wq_employment_dao(o,db): + try: + o1 = Employment(**o) + db.add(o1) + except Exception as e: + db.rollback() + raise HTTPException(status_code=500, detail=f'添加失败:str(e)') + else: + db.commit() + return 1 + +def upd_employment_dao(e,db): + try: + rows = db.query(Employment).filter(Employment.stu_id == e['stu_id']).update(e) + except: + db.rollback() + raise HTTPException(status_code=500, detail='更新异常,请稍后再执行!') + else: + db.commit() + return 1 + +def del_employment_dao(stu_id,db): + try: + row = db.query(Employment).filter(Employment.stu_id == stu_id).all() + if not row: + raise HTTPException(status_code=404,detail='记录不存在') + for i in row: + if i.deleted == 0: + db.query(Employment).filter(Employment.stu_id == i.stu_id).update({'deleted':1}) + except Exception as e: + db.rollback() + raise HTTPException(status_code=500,detail=f'删除失败:{str(e)}') + else: + db.commit() + return 1 +