ceshi
This commit is contained in:
@@ -4,26 +4,39 @@ from dao.employment_dao import add_emp_dao, update_emp_dao, delete_emp_dao
|
||||
from schema.employment_schema import EmploymentRequest,EmploymentResponse
|
||||
from util.database import get_db
|
||||
from typing import Optional
|
||||
emp_api = APIRouter(tags=['学生就业管理系统'])
|
||||
@emp_api.get('/employment/students/{stu_id}',response_model=EmploymentResponse,summary='获取学生就业信息')
|
||||
emp_api = APIRouter(tags=['学生就业管理模块'])
|
||||
|
||||
@emp_api.get('/employment/class/{stu_id}',response_model=EmploymentResponse,summary='获取学生就业信息')
|
||||
def get_emp_info1(stu_id: Optional[int]=Path(description='学生编号')
|
||||
,company_name: Optional[str]=Query(None,description='公司名称')
|
||||
,min_salary: Optional[float]=Query(None,ge=0,description='最低工资')
|
||||
,max_salary: Optional[float]=Query(None,ge=0,description='最高工资')
|
||||
,db=Depends(get_db)):
|
||||
if min_salary and max_salary:
|
||||
if min_salary > max_salary:
|
||||
raise HTTPException(status_code=404, detail='该学生就业信息不存在')
|
||||
return [employment_dao.get_emp_dao(stu_id=stu_id,db=db)]
|
||||
e1 = employment_dao.get_emp_dao(stu_id=stu_id, db=db)
|
||||
if e1:
|
||||
return e1[0]
|
||||
raise HTTPException(status_code=404, detail='该学生就业信息不存在')
|
||||
|
||||
@emp_api.get('/employment/class/{class_id}',response_model=EmploymentResponse,summary='获取班级学生就业信息')
|
||||
def get_emp_info2(class_id: Optional[int]=Path(description='班级编号')
|
||||
,db=Depends(get_db)):
|
||||
e = employment_dao.get_emp_dao(class_id=class_id, db=db)
|
||||
if e:
|
||||
return e
|
||||
e2 = employment_dao.get_emp_dao(class_id=class_id, db=db)
|
||||
if e2:
|
||||
return e2
|
||||
raise HTTPException(status_code=404, detail='该班级就业信息不存在')
|
||||
|
||||
@emp_api.get('/employment}',response_model=EmploymentResponse,summary='按照学⽣编号,公司名字,⼯资范围查询学⽣就业信息')
|
||||
def get_emp_info3(stu_id:int|None = Query(None, description='学生编号')
|
||||
,company_name: str|None = Query(None,description='公司名称')
|
||||
,min_salary: float|None = Query(None,ge=0,description='最低工资')
|
||||
,max_salary: float|None = Query(None,ge=0,description='最高工资')
|
||||
,db=Depends(get_db)):
|
||||
if min_salary and max_salary:
|
||||
if min_salary > max_salary:
|
||||
raise HTTPException(status_code=404, detail='最低工资不能大于最高工资')
|
||||
return [employment_dao.get_emp_dao(stu_id=stu_id
|
||||
,company_name=company_name
|
||||
,min_salary=min_salary
|
||||
,max_salary=max_salary
|
||||
,db=db)]
|
||||
|
||||
@emp_api.post('/employment/students/{stu_id}',response_model=EmploymentResponse,summary='新增学生就业信息')
|
||||
def create_emp_info(emp:EmploymentRequest=Form(),db=Depends(get_db)):
|
||||
d=emp.model_dump(exclude_unset=False)
|
||||
|
||||
@@ -3,12 +3,21 @@ 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).\
|
||||
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)
|
||||
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)
|
||||
@@ -22,19 +31,23 @@ def get_emp_dao(stu_id=None,class_id=None,company_name=None,min_salary=None,max_
|
||||
q = q.filter(Employment_info.salary <= max_salary)
|
||||
|
||||
r = q.all()
|
||||
if r:
|
||||
return [{'emp_id':i.emp_id
|
||||
,'stu_id': i.stu_id
|
||||
,'stu_name':i.Student_Model.stu_name
|
||||
,'class_id':i.Student_Model.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
|
||||
]
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user