From 0984210387e119ed44c213d43999656c87facf5d Mon Sep 17 00:00:00 2001 From: wolin_ck666_999 Date: Tue, 22 Sep 2026 15:14:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=E3=80=8Cdao=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/e_dao.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 dao/e_dao.py diff --git a/dao/e_dao.py b/dao/e_dao.py new file mode 100644 index 0000000..015e65d --- /dev/null +++ b/dao/e_dao.py @@ -0,0 +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 +