53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
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
|
|
|