Merge remote-tracking branch 'origin/conding' into conding
This commit is contained in:
@@ -5,27 +5,27 @@ from dao.cla_dao import add_class_dao,get_class_dao,update_class_dao,delete_clas
|
||||
|
||||
claAPI = APIRouter(prefix="/class", tags=["班级管理"])
|
||||
|
||||
@claAPI.post("/class", summary="新增班级")
|
||||
@claAPI.post("", summary="新增班级")
|
||||
def add_class(data: claRequest, Session = Depends(get_db)):
|
||||
return add_class_dao(data, Session)
|
||||
|
||||
@claAPI.get("/class/list", summary="查询班级")
|
||||
@claAPI.get("/list", summary="查询班级")
|
||||
def list_class(Session = Depends(get_db)):
|
||||
return get_class_dao(Session)
|
||||
|
||||
@claAPI.put("/class/{class_id}", summary="更新班级信息")
|
||||
@claAPI.put("/{class_id}", summary="更新班级信息")
|
||||
def update_class(class_id: int, data: claRequest, Session = Depends(get_db)):
|
||||
return update_class_dao(class_id, data, Session)
|
||||
|
||||
@claAPI.get("/class/{class_id}", summary="逻辑删除班级信息")
|
||||
@claAPI.delete("/{class_id}", summary="逻辑删除班级信息")
|
||||
def delete_class(class_id: int, Session = Depends(get_db)):
|
||||
return delete_class_dao(class_id, Session)
|
||||
|
||||
@claAPI.get("/class/delete/check/{class_id}", summary="硬删除前查询")
|
||||
@claAPI.get("/delete/check/{class_id}", summary="硬删除前查询")
|
||||
def check_delete(class_id: int, Session = Depends(get_db)):
|
||||
return get_class_for_delete(class_id, Session)
|
||||
|
||||
@claAPI.delete("/class/delete/confirm/{class_id}", summary="删除班级信息")
|
||||
@claAPI.delete("/delete/confirm/{class_id}", summary="删除班级信息")
|
||||
def confirm_delete(class_id: int, Session = Depends(get_db)):
|
||||
return hard_delete_class(class_id, Session)
|
||||
|
||||
|
||||
@@ -2,28 +2,24 @@ from fastapi import APIRouter,Depends,HTTPException
|
||||
|
||||
from dao import employment_dao
|
||||
from dao.employment_dao import get_employment_dao
|
||||
from schema.employment_schema import EmploymentRequest,EmploymentResponse
|
||||
from schema.employment_schema import EmploymentResponse
|
||||
from model.all_model import ClassManagement,Employment_info
|
||||
from util.database import get_db
|
||||
|
||||
emp_api = APIRouter()
|
||||
@emp_api.get('employment/students/{stu_id}',response_model=EmploymentResponse,summary='获取学生就业信息')
|
||||
emp_api = APIRouter(tags=['学生就业管理系统'])
|
||||
@emp_api.get('/employment/students/{stu_id}',response_model=EmploymentResponse,summary='获取学生就业信息')
|
||||
def get_emp_info1(stu_id: int,db=Depends(get_db)):
|
||||
try:
|
||||
if stu_id:
|
||||
return employment_dao.get_employment_info()
|
||||
except:
|
||||
raise HTTPException(status_code=404, detail='该学生就业信息不存在')
|
||||
if stu_id:
|
||||
return employment_dao.get_employment_dao(stu_id=stu_id,db=db)
|
||||
raise HTTPException(status_code=404, detail='该学生就业信息不存在')
|
||||
|
||||
@emp_api.get('employment/class/{class_id}',summary='获取班级学生就业信息')
|
||||
@emp_api.get('/employment/class/{class_id}',response_model=EmploymentResponse,summary='获取班级学生就业信息')
|
||||
def get_emp_info2(class_id: int,db=Depends(get_db)):
|
||||
try:
|
||||
if class_id:
|
||||
return employment_dao.get_employment_info()
|
||||
except:
|
||||
raise HTTPException(status_code=404, detail='该班级就业信息不存在')
|
||||
if class_id:
|
||||
return employment_dao.get_employment_dao(class_id=class_id,db=db)
|
||||
raise HTTPException(status_code=404, detail='该班级就业信息不存在')
|
||||
|
||||
# @emp_api.post('employment/students/{stu_id}')
|
||||
# def create_emp_info(stu_id: int,db=Depends(get_db)):
|
||||
# try:
|
||||
# pass
|
||||
# @emp_api.post('/employment/students/{stu_id}')
|
||||
# def create_emp_info(stu_id: int,db=Depends(get_db),response_model=EmploymentResponse):
|
||||
# if stu_id:
|
||||
#
|
||||
# return employment_dao.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from fastapi import APIRouter,Depends
|
||||
from dao.statistics_dao import select_all,select_age,select_score,select_avg_score,select_salary,select_days
|
||||
from dao.statistics_dao import *
|
||||
from schema.student_schema import StudentResponse
|
||||
from schema.statistics_schema import AllStuResponse,AvgDayResponse,AcgScoreResponse
|
||||
from schema.statistics_schema import *
|
||||
from util.database import get_db
|
||||
|
||||
StatisticsAPI = APIRouter()
|
||||
@@ -35,3 +35,9 @@ def get_scores(db=Depends(get_db)):
|
||||
def get_days(db=Depends(get_db)):
|
||||
l = select_days(db)
|
||||
return l
|
||||
|
||||
|
||||
@StatisticsAPI.get('/emp',response_model=AllEmpResponse,tags=['统计分析模块'],summary='统计每个学生的就业时长')
|
||||
def get_emp(db=Depends(get_db)):
|
||||
l= select_days2(db)
|
||||
return l
|
||||
@@ -6,7 +6,7 @@ from util.database import get_db
|
||||
|
||||
StudentAPI = APIRouter()
|
||||
|
||||
@StudentAPI.get('/students',response_model=list[StudentPageResponse],tags=['学⽣基本信息管理模块'],description='查询学生信息')
|
||||
@StudentAPI.get('/students',response_model=list[StudentPageResponse],tags=['学⽣基本信息管理模块'],summary='学生信息查询接口',description='查询学生信息')
|
||||
def get_students(stu_id:int|None=None
|
||||
,stu_name:str|None=None
|
||||
,class_id:int|None=None
|
||||
@@ -29,7 +29,7 @@ def get_students(stu_id:int|None=None
|
||||
, 'total': total
|
||||
, 'data': r}
|
||||
|
||||
@StudentAPI.put('/{stu_id}',tags=['学⽣基本信息管理模块'])
|
||||
@StudentAPI.put('/{stu_id}',tags=['学⽣基本信息管理模块'],summary='学生信息更新接口',description='更新学生信息')
|
||||
def update_students(s:StudentRequest
|
||||
,stu_id:int
|
||||
,db=Depends(get_db)):
|
||||
@@ -41,7 +41,7 @@ def update_students(s:StudentRequest
|
||||
raise HTTPException(status_code=500, detail='没有更新!')
|
||||
return {'code':200,'totals':r,'detail':'更新成功'}
|
||||
|
||||
@StudentAPI.delete('/{stu_id}',tags=['学⽣基本信息管理模块'])
|
||||
@StudentAPI.delete('/{stu_id}',tags=['学⽣基本信息管理模块'],summary='学生信息删除接口',description='删除学生信息')
|
||||
def del_students(stu_id:int
|
||||
,db=Depends(get_db)):
|
||||
rows=delete_student_dao( stu_id=stu_id,db=db )
|
||||
@@ -49,7 +49,7 @@ def del_students(stu_id:int
|
||||
raise HTTPException(status_code=500,detail='没有删除')
|
||||
return {'code':200,'totals':rows,'detail':'删除成功'}
|
||||
|
||||
@StudentAPI.post('/students',tags=['学⽣基本信息管理模块'],response_model=StugetResponse)
|
||||
@StudentAPI.post('/students',tags=['学⽣基本信息管理模块'],response_model=StugetResponse,summary='学生信息新增接口',description='新增学生信息')
|
||||
def add_students(s:StudentRequest
|
||||
,db=Depends(get_db)):
|
||||
d=s.model_dump(exclude_unset=False)
|
||||
@@ -57,16 +57,3 @@ def add_students(s:StudentRequest
|
||||
if not stu_new:
|
||||
raise HTTPException(status_code=500,detail='添加失败')
|
||||
return stu_new
|
||||
|
||||
|
||||
@StudentAPI.put('/students',tags=['学⽣基本信息管理模块'])
|
||||
def get_students(stu_id:int|None = None
|
||||
,stu_name:str|None = None
|
||||
,class_id:int|None=None
|
||||
,db=Depends(get_db)
|
||||
,page:int=1
|
||||
,page_size:int=10):
|
||||
r = get_student_dao(stu_id,stu_name,class_id,db,page,page_size )
|
||||
if r:
|
||||
return r
|
||||
raise HTTPException(status_code=404,detail='学生不存在!')
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from fastapi import HTTPException,Depends
|
||||
from fastapi import HTTPException
|
||||
from model.all_model import Employment_info, ClassManagement, Student_Model
|
||||
from util.database import get_db
|
||||
from schema.employment_schema import EmploymentRequest
|
||||
|
||||
def get_employment_dao(stu_id,class_id,db=Depends(get_db())):
|
||||
def get_employment_dao(stu_id,class_id,db):
|
||||
try:
|
||||
q = db.query(Employment_info).\
|
||||
join(Student_Model,Employment_info.stu_id == Student_Model.stu_id).\
|
||||
@@ -27,20 +27,19 @@ def get_employment_dao(stu_id,class_id,db=Depends(get_db())):
|
||||
,'company_name':i.company_name
|
||||
,'company_address':i.company_address
|
||||
,'salary':i.salary
|
||||
}for i in r
|
||||
}for i in r
|
||||
]
|
||||
except:
|
||||
raise HTTPException(status_code=404,detail='信息不存在!')
|
||||
|
||||
# def add_employment_dao(e:EmlpoymentRequest,db=Depends(get_db()),stu_id):
|
||||
# try:
|
||||
# r = db.query(Employment_info).filter(Employment_info.stu_id == stu_id).all()
|
||||
# if r:
|
||||
# e1 = Employment_info(**e)
|
||||
# db.add(e1)
|
||||
# except:
|
||||
# db.rollback()
|
||||
# return False
|
||||
# else:
|
||||
# db.commit()
|
||||
# return True
|
||||
def add_employment_dao(e:EmploymentRequest,db):
|
||||
try:
|
||||
d = e.model_dump()
|
||||
e1 = Employment_info(**d)
|
||||
db.add(e1)
|
||||
except:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=404, detail='信息不存在!')
|
||||
else:
|
||||
db.commit()
|
||||
return e1
|
||||
|
||||
@@ -91,3 +91,21 @@ def select_days(db):
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500, detail="查询异常")
|
||||
|
||||
#统计每个学⽣的就业时⻓
|
||||
def select_days2(db):
|
||||
try:
|
||||
l2 =db.query(
|
||||
Employment_info.stu_id
|
||||
,Employment_info.employment_opening_date
|
||||
,Employment_info.offer_issuance_date
|
||||
,func.datediff(
|
||||
Employment_info.offer_issuance_date
|
||||
,Employment_info.employment_opening_date
|
||||
)
|
||||
.label("employment_duration_day")
|
||||
).filter(
|
||||
Employment_info.delete_status == 0
|
||||
).all()
|
||||
return l2
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500, detail="查询异常")
|
||||
@@ -1,10 +1,10 @@
|
||||
from fastapi import Query,HTTPException
|
||||
from pydantic import BaseModel, field_validator
|
||||
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=Query(ge=1)
|
||||
stu_id: int=Field(ge=1)
|
||||
email: str|None
|
||||
employment_opening_date:date
|
||||
offer_issuance_date:date
|
||||
@@ -13,11 +13,17 @@ class EmploymentRequest(BaseModel):
|
||||
salary:float
|
||||
|
||||
@field_validator('stu_id')
|
||||
def check(cls,n):
|
||||
i = cls.model_dump()
|
||||
if i['stu_id'] == n:
|
||||
return n
|
||||
raise HTTPException(status_code=404,detail='未找到该学生的就业信息!')
|
||||
@classmethod
|
||||
def check_stu_id(cls,v):
|
||||
if v <= 0:
|
||||
raise ValueError('输入有误,学生ID必须大于0')
|
||||
return v
|
||||
|
||||
@model_validator(mode='after')
|
||||
def check_date(self):
|
||||
if self.employment_opening_date > self.offer_issuance_date:
|
||||
raise ValueError('offer下发日期不能早于就业开放日期')
|
||||
return self
|
||||
|
||||
class EmploymentResponse(BaseModel):
|
||||
code:int = 200
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel,Field
|
||||
from datetime import date
|
||||
from typing import List, Optional
|
||||
|
||||
class AllStuResponse(BaseModel):
|
||||
class_id: int
|
||||
@@ -13,3 +15,17 @@ class AvgDayResponse(BaseModel):
|
||||
class_id: int
|
||||
avg_days: str | None
|
||||
|
||||
class EmpRequest(BaseModel):
|
||||
stu_id: int
|
||||
|
||||
class EmpItem(BaseModel):
|
||||
stu_id: int
|
||||
employment_opening_date:date | None
|
||||
offer_issuance_date:date | None
|
||||
employment_duration_day: int | None
|
||||
|
||||
class AllEmpResponse(BaseModel):
|
||||
code: int
|
||||
msg: str
|
||||
data: List[EmpItem]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user