ceshi
This commit is contained in:
@@ -8,18 +8,20 @@ emp_api = APIRouter(tags=['学生就业管理系统'])
|
||||
@emp_api.get('/employment/students/{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,description='最低工资')
|
||||
,max_salary: Optional[float]=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 stu_id or company_name or min_salary or max_salary:
|
||||
return [employment_dao.get_emp_dao(stu_id=stu_id,db=db)]
|
||||
raise HTTPException(status_code=404, detail='该学生就业信息不存在')
|
||||
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)]
|
||||
|
||||
@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)):
|
||||
if class_id:
|
||||
return employment_dao.get_emp_dao(class_id=class_id,db=db)
|
||||
e = employment_dao.get_emp_dao(class_id=class_id, db=db)
|
||||
if e:
|
||||
return e
|
||||
raise HTTPException(status_code=404, detail='该班级就业信息不存在')
|
||||
|
||||
@emp_api.post('/employment/students/{stu_id}',response_model=EmploymentResponse,summary='新增学生就业信息')
|
||||
@@ -30,17 +32,17 @@ def create_emp_info(emp:EmploymentRequest=Form(),db=Depends(get_db)):
|
||||
raise HTTPException(status_code=500,detail='服务器繁忙,请稍后添加!')
|
||||
return r
|
||||
|
||||
@emp_api.put('/employment/students/{stu_id}',response_model=EmploymentResponse,summary='更新学生就业信息')
|
||||
def update_emp_info(stu_id:int,emp:EmploymentRequest,db=Depends(get_db)):
|
||||
@emp_api.put('/employment/students/{emp_id}',response_model=EmploymentResponse,summary='更新学生就业信息')
|
||||
def update_emp_info(emp_id:int,emp:EmploymentRequest,db=Depends(get_db)):
|
||||
d = emp.model_dump(exclude_unset=True)
|
||||
r = update_emp_dao(stu_id,d,db)
|
||||
r = update_emp_dao(emp_id=emp_id,db=db)
|
||||
if not r:
|
||||
raise HTTPException(status_code=500,detail='更新失败!')
|
||||
raise HTTPException(status_code=500,detail='没有更新!')
|
||||
return {'code':200,'totals':r,'detail':'更新成功!'}
|
||||
|
||||
@emp_api.delete('/employment/{stu_id}',summary='删除学生就业信息')
|
||||
def delete_emp_info(stu_id:int,db=Depends(get_db)):
|
||||
rows = delete_emp_dao(stu_id, db)
|
||||
@emp_api.delete('/employment/{emp_id}',summary='删除学生就业信息')
|
||||
def delete_emp_info(emp_id:int=Path(description='序号'),db=Depends(get_db)):
|
||||
rows = delete_emp_dao(emp_id, db)
|
||||
if not rows:
|
||||
raise HTTPException(status_code=500, detail='没有删除!')
|
||||
return {'code':200,'detail':'删除成功!'}
|
||||
|
||||
@@ -1,69 +1,67 @@
|
||||
from fastapi import HTTPException, APIRouter
|
||||
from fastapi import HTTPException
|
||||
from model.all_model import Employment_info, ClassManagement, Student_Model
|
||||
from datetime import datetime
|
||||
|
||||
emp_api = APIRouter()
|
||||
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)
|
||||
|
||||
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 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
|
||||
]
|
||||
|
||||
|
||||
def add_emp_dao(o:dict,db):
|
||||
try:
|
||||
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)
|
||||
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 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
|
||||
]
|
||||
except:
|
||||
raise HTTPException(status_code=404,detail='信息不存在!')
|
||||
|
||||
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()
|
||||
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()
|
||||
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 HTTPException:
|
||||
raise
|
||||
return e1
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500, detail=f'新增就业信息失败: {e}')
|
||||
|
||||
def update_emp_dao(stu_id,o,db):
|
||||
def update_emp_dao(emp_id:int,db):
|
||||
try:
|
||||
rows = db.query(Employment_info).filter(Employment_info.stu_id == stu_id,Employment_info.delete_status == 0).first()
|
||||
rows = db.query(Employment_info).filter(Employment_info.emp_id == emp_id
|
||||
,Employment_info.delete_status == 0).first()
|
||||
|
||||
db.commit()
|
||||
return rows
|
||||
except:
|
||||
@@ -71,10 +69,11 @@ def update_emp_dao(stu_id,o,db):
|
||||
raise HTTPException(status_code=404,detail='该就业记录已存在')
|
||||
|
||||
|
||||
def delete_emp_dao(stu_id,db):
|
||||
def delete_emp_dao(emp_id:int,db):
|
||||
try:
|
||||
rows = db.query(Employment_info)\
|
||||
.filter(Employment_info.stu_id == stu_id,Employment_info.delete_status == 0)\
|
||||
.filter(Employment_info.emp_id == emp_id
|
||||
,Employment_info.delete_status == 0)\
|
||||
.update({'delete_status':1,'delete_time': datetime.now()})
|
||||
db.commit()
|
||||
except:
|
||||
|
||||
@@ -145,7 +145,7 @@ class Employment_info(Base):
|
||||
delete_status = Column(
|
||||
Integer,default=0,comment='删除状态:0未删除,1已删除')
|
||||
|
||||
delete_time = Column(DATETIME,comment='删除时间')
|
||||
delete_time = Column(DATETIME,default=None,comment='删除时间')
|
||||
|
||||
class WlScore(Base):
|
||||
__tablename__ = 'wl_score'
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
from fastapi import HTTPException
|
||||
from pydantic import BaseModel, Field,field_validator, model_validator
|
||||
from datetime import date
|
||||
from typing import Optional
|
||||
|
||||
class EmploymentRequest(BaseModel):
|
||||
stu_id: int=Field(ge=1)
|
||||
email: str|None = None
|
||||
employment_opening_date:date|None = None
|
||||
offer_issuance_date:date|None = None
|
||||
company_name:str|None = None
|
||||
company_address:str|None = None
|
||||
salary:float|None = None
|
||||
stu_id: int=Field(ge=1,description='学生编号')
|
||||
email: Optional[str] = Field(None, description='邮箱')
|
||||
employment_opening_date:Optional[date] = Field(None, description='就业开放日期')
|
||||
offer_issuance_date:Optional[date] = Field(None, description='offer下发日期')
|
||||
company_name:Optional[str] = Field(None, description='公司名称')
|
||||
company_address:Optional[str] = Field(None, description='公司地址')
|
||||
salary:Optional[float] = Field(None, description='薪资')
|
||||
|
||||
@model_validator(mode='after')
|
||||
def check_date(self):
|
||||
@@ -22,7 +21,10 @@ class EmploymentRequest(BaseModel):
|
||||
class EmploymentResponse(BaseModel):
|
||||
code:int = 200
|
||||
detail:str = 'OK'
|
||||
emp_id: int
|
||||
stu_id:int
|
||||
stu_name: Optional[str] = None
|
||||
class_id: Optional[int] = None
|
||||
email: str|None = None
|
||||
employment_opening_date:date|None = None
|
||||
offer_issuance_date:date|None = None
|
||||
|
||||
Reference in New Issue
Block a user