97 lines
3.5 KiB
Python
97 lines
3.5 KiB
Python
from fastapi import HTTPException
|
|
from model.all_model import Employment_info, ClassManagement, Student_Model
|
|
from datetime import datetime
|
|
|
|
def get_emp_dao(stu_id=None,class_id=None,company_name=None,min_salary=None,max_salary=None,db=None):
|
|
q = db.query(Employment_info.emp_id
|
|
,Employment_info.stu_id
|
|
,Student_Model.stu_name
|
|
,Student_Model.class_id
|
|
,Employment_info.email
|
|
,Employment_info.employment_opening_date
|
|
,Employment_info.offer_issuance_date
|
|
,Employment_info.company_name
|
|
,Employment_info.company_address
|
|
,Employment_info.salary)\
|
|
.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:
|
|
q = q.filter(Employment_info.stu_id == stu_id)
|
|
if class_id:
|
|
q = q.filter(ClassManagement.class_id == class_id)
|
|
if company_name:
|
|
q = q.filter(Employment_info.company_name == company_name)
|
|
if min_salary:
|
|
q = q.filter(Employment_info.salary >= min_salary)
|
|
if max_salary:
|
|
q = q.filter(Employment_info.salary <= max_salary)
|
|
|
|
r = q.all()
|
|
if not r:
|
|
raise HTTPException(status_code=500,detail='查询异常,没有结果!')
|
|
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_emp_dao(o:dict,db):
|
|
try:
|
|
stu = db.query(Student_Model).filter(Student_Model.stu_id == o['stu_id']
|
|
, Student_Model.delete_status == 0).first()
|
|
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())
|
|
if exist:
|
|
raise HTTPException(status_code=409, detail='该学生已有就业信息,请勿重复增加!')
|
|
|
|
e1 = Employment_info(**o)
|
|
db.add(e1)
|
|
db.commit()
|
|
return e1
|
|
except Exception as e:
|
|
db.rollback()
|
|
raise HTTPException(status_code=500, detail=f'新增就业信息失败: {e}')
|
|
|
|
def update_emp_dao(emp_id:int,db):
|
|
try:
|
|
rows = db.query(Employment_info).filter(Employment_info.emp_id == emp_id
|
|
,Employment_info.delete_status == 0).first()
|
|
|
|
db.commit()
|
|
return rows
|
|
except:
|
|
db.rollback()
|
|
raise HTTPException(status_code=404,detail='该就业记录已存在')
|
|
|
|
|
|
def delete_emp_dao(emp_id:int,db):
|
|
try:
|
|
rows = db.query(Employment_info)\
|
|
.filter(Employment_info.emp_id == emp_id
|
|
,Employment_info.delete_status == 0)\
|
|
.update({'delete_status':1,'delete_time': datetime.now()})
|
|
db.commit()
|
|
except:
|
|
db.rollback()
|
|
rows = 0
|
|
finally:
|
|
return rows
|