81 lines
3.0 KiB
Python
81 lines
3.0 KiB
Python
from fastapi import HTTPException
|
|
from model.all_model import Employment_info, ClassManagement, Student_Model
|
|
from datetime import datetime
|
|
|
|
def get_emp_dao(db,stu_id=None,class_id=None,company_name=None,min_salary=None,max_salary=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()
|
|
return r
|
|
|
|
|
|
def add_emp_dao(o,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 o
|
|
except Exception as e:
|
|
db.rollback()
|
|
raise HTTPException(status_code=500, detail=f'新增就业信息失败: {e}')
|
|
|
|
def update_emp_dao(stu_id,emp,db):
|
|
try:
|
|
rows = db.query(Employment_info)\
|
|
.filter(Employment_info.stu_id == stu_id,Employment_info.delete_status == 0)\
|
|
.update(emp)
|
|
db.commit()
|
|
return rows
|
|
except:
|
|
db.rollback()
|
|
raise HTTPException(status_code=404,detail='该就业记录不存在')
|
|
|
|
|
|
def delete_emp_dao(stu_id:int,db):
|
|
try:
|
|
rows = db.query(Employment_info)\
|
|
.filter(Employment_info.stu_id == stu_id
|
|
,Employment_info.delete_status == 0)\
|
|
.update({'delete_status':1,'delete_time': datetime.now()})
|
|
db.commit()
|
|
except:
|
|
db.rollback()
|
|
rows = 0
|
|
finally:
|
|
return rows
|