This commit is contained in:
maruizhi
2026-09-22 14:36:43 +08:00
parent 14e792885a
commit bf44ac9450
4 changed files with 34 additions and 33 deletions
+11 -12
View File
@@ -1,7 +1,7 @@
from fastapi import APIRouter, Query, Depends, HTTPException, Path,Form
from dao import employment_dao
from dao.employment_dao import add_emp_dao, update_emp_dao, delete_emp_dao
from schema.employment_schema import EmploymentRequest,EmploymentResponse
from schema.employment_schema import EmploymentRequest,UpdateEmpRequest,EmploymentResponse
from util.database import get_db
from typing import Optional
emp_api = APIRouter(tags=['学生就业管理模块'])
@@ -22,8 +22,8 @@ def get_emp_info2(class_id: Optional[int]=Path(description='班级编号')
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='学生编号')
@emp_api.get('/employment/class/{stu_id}',response_model=list[EmploymentResponse],summary='按照学⽣编号,公司名字,⼯资范围查询学⽣就业信息')
def get_emp_info3(stu_id:int = Path(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='最高工资')
@@ -31,11 +31,11 @@ def get_emp_info3(stu_id:int|None = Query(None, description='学生编号')
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)]
l1 = employment_dao.get_emp_dao(db, stu_id=stu_id
, company_name=company_name
, min_salary=min_salary
, max_salary=max_salary)
return l1
@emp_api.post('/employment/students/{stu_id}',response_model=EmploymentResponse,summary='新增学生就业信息')
def create_emp_info(emp:EmploymentRequest=Form(),db=Depends(get_db)):
@@ -45,10 +45,9 @@ def create_emp_info(emp:EmploymentRequest=Form(),db=Depends(get_db)):
raise HTTPException(status_code=500,detail='服务器繁忙,请稍后添加!')
return r
@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(emp_id=emp_id,db=db)
@emp_api.put('/employment/students/{emp_id}',summary='更新学生就业信息')
def update_emp_info(emp_id:int,emp:UpdateEmpRequest,db=Depends(get_db)):
r = update_emp_dao(emp_id,emp.model_dump(exclude_unset=True),db)
if not r:
raise HTTPException(status_code=500,detail='没有更新!')
return {'code':200,'totals':r,'detail':'更新成功!'}
+1 -1
View File
@@ -1,4 +1,4 @@
from fastapi import APIRouter,HTTPException
from fastapi import APIRouter,HTTPException,Depends
from dao.student_dao import *
from schema.student_schema import *
from util.database import get_db
+7 -20
View File
@@ -2,7 +2,7 @@ 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):
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
@@ -33,24 +33,11 @@ def get_emp_dao(stu_id=None,class_id=None,company_name=None,min_salary=None,max_
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
]
return r
def add_emp_dao(o:dict,db):
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()
@@ -70,11 +57,11 @@ def add_emp_dao(o:dict,db):
db.rollback()
raise HTTPException(status_code=500, detail=f'新增就业信息失败: {e}')
def update_emp_dao(emp_id:int,db):
def update_emp_dao(emp_id,emp,db):
try:
rows = db.query(Employment_info).filter(Employment_info.emp_id == emp_id
,Employment_info.delete_status == 0).first()
rows = db.query(Employment_info)\
.filter(Employment_info.emp_id == emp_id,Employment_info.delete_status == 0)\
.update(emp)
db.commit()
return rows
except:
+15
View File
@@ -18,6 +18,21 @@ class EmploymentRequest(BaseModel):
raise ValueError('offer下发日期不能早于就业开放日期')
return self
class UpdateEmpRequest(BaseModel):
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):
if self.employment_opening_date and self.offer_issuance_date:
if self.employment_opening_date > self.offer_issuance_date:
raise ValueError('offer下发日期不能早于就业开放日期')
return self
class EmploymentResponse(BaseModel):
code:int = 200
detail:str = 'OK'