就业get次昂管的dao层和api接口
This commit is contained in:
@@ -13,7 +13,7 @@ def get_emp_info1(stu_id: int,db=Depends(get_db)):
|
|||||||
if stu_id:
|
if stu_id:
|
||||||
return employment_dao.get_employment_info()
|
return employment_dao.get_employment_info()
|
||||||
except:
|
except:
|
||||||
raise HTTPException(status_code=404, detail='就业信息不存在')
|
raise HTTPException(status_code=404, detail='该学生就业信息不存在')
|
||||||
|
|
||||||
@app.get('employment/class/{class_id}',summary='获取班级学生就业信息')
|
@app.get('employment/class/{class_id}',summary='获取班级学生就业信息')
|
||||||
def get_emp_info2(class_id: int,db=Depends(get_db)):
|
def get_emp_info2(class_id: int,db=Depends(get_db)):
|
||||||
@@ -21,10 +21,9 @@ def get_emp_info2(class_id: int,db=Depends(get_db)):
|
|||||||
if class_id:
|
if class_id:
|
||||||
return employment_dao.get_employment_info()
|
return employment_dao.get_employment_info()
|
||||||
except:
|
except:
|
||||||
raise HTTPException(status_code=404, detail='就业信息不存在')
|
raise HTTPException(status_code=404, detail='该班级就业信息不存在')
|
||||||
|
|
||||||
|
# @app.post('employment/students/{stu_id}')
|
||||||
|
# def create_emp_info(stu_id: int,db=Depends(get_db)):
|
||||||
@app.post('employment/students/{stu_id}')
|
# try:
|
||||||
def create_emp_info(stu_id: int,db=Depends(get_db)):
|
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,40 +1,46 @@
|
|||||||
|
from fastapi import HTTPException,Depends
|
||||||
from model.all_model import Employment_info, ClassManagement, Student_Model
|
from model.all_model import Employment_info, ClassManagement, Student_Model
|
||||||
from util.database import get_db
|
from util.database import get_db
|
||||||
from schema.employment_schema import EmlpoymentRequest
|
from schema.employment_schema import EmlpoymentRequest
|
||||||
|
|
||||||
def get_employment_dao(stu_id,class_id,db):
|
def get_employment_dao(stu_id,class_id,db=Depends(get_db())):
|
||||||
q = db.query(Employment_info).\
|
|
||||||
join(ClassManagement,ClassManagement.stu_id == Employment_info.stu_id).\
|
|
||||||
filter(Employment_info.delete_status == 0).\
|
|
||||||
filter(Student_Model.delete_status == 0).\
|
|
||||||
filter(ClassManagement.delete_status == 0)
|
|
||||||
if stu_id is not None:
|
|
||||||
q = q.filter(Employment_info.stu_id == stu_id)
|
|
||||||
if class_id is not None:
|
|
||||||
q = q.filter(ClassManagement.class_id == class_id)
|
|
||||||
r = q.all()
|
|
||||||
if r:
|
|
||||||
return [{'emp_id':i.emp_id
|
|
||||||
,'stu_id': i.stu_id
|
|
||||||
,'stu_name':i.stu_name
|
|
||||||
,'class_id':i.class_id
|
|
||||||
,'email':i.email
|
|
||||||
,'employment_opening_date':i.employment_opening_date
|
|
||||||
,'offer_issuance_date':i.offer_issuance_date
|
|
||||||
,'company_name':i.company_name
|
|
||||||
,'company_address':i.company_address
|
|
||||||
,'salary':i.salary
|
|
||||||
}for i in r
|
|
||||||
]
|
|
||||||
|
|
||||||
def add_employment_dao(e:EmlpoymentRequest,db,stu_id):
|
|
||||||
try:
|
try:
|
||||||
e1 = Employment_info(**e)
|
q = db.query(Employment_info).\
|
||||||
db.add(e1)
|
join(Student_Model,Employment_info.stu_id == Student_Model.stu_id).\
|
||||||
|
join(ClassManagement,Student_Model.class_id == ClassManagement.class_id).\
|
||||||
|
filter(Employment_info.delete_status == 0).\
|
||||||
|
filter(Student_Model.delete_status == 0).\
|
||||||
|
filter(ClassManagement.delete_status == 0)
|
||||||
|
if stu_id is not None:
|
||||||
|
q = q.filter(Employment_info.stu_id == stu_id)
|
||||||
|
if class_id is not None:
|
||||||
|
q = q.filter(ClassManagement.class_id == class_id)
|
||||||
|
r = q.all()
|
||||||
|
if r:
|
||||||
|
return [{'emp_id':i.emp_id
|
||||||
|
,'stu_id': i.stu_id
|
||||||
|
,'stu_name':i.stu_name
|
||||||
|
,'class_id':i.class_id
|
||||||
|
,'email':i.email
|
||||||
|
,'employment_opening_date':i.employment_opening_date
|
||||||
|
,'offer_issuance_date':i.offer_issuance_date
|
||||||
|
,'company_name':i.company_name
|
||||||
|
,'company_address':i.company_address
|
||||||
|
,'salary':i.salary
|
||||||
|
}for i in r
|
||||||
|
]
|
||||||
except:
|
except:
|
||||||
db.rollback()
|
raise HTTPException(status_code=404,detail='信息不存在!')
|
||||||
return False
|
|
||||||
else:
|
# def add_employment_dao(e:EmlpoymentRequest,db=Depends(get_db()),stu_id):
|
||||||
db.commit()
|
# try:
|
||||||
return True
|
# r = db.query(Employment_info).filter(Employment_info.stu_id == stu_id).all()
|
||||||
|
# if r:
|
||||||
|
# e1 = Employment_info(**e)
|
||||||
|
# db.add(e1)
|
||||||
|
# except:
|
||||||
|
# db.rollback()
|
||||||
|
# return False
|
||||||
|
# else:
|
||||||
|
# db.commit()
|
||||||
|
# return True
|
||||||
|
|||||||
Reference in New Issue
Block a user