Merge remote-tracking branch 'origin/conding' into conding
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from util.database import get_db
|
||||
from schema.cla_schema import claRequest
|
||||
from dao.cla_dao import add_class_dao,get_class_dao,update_class_dao,delete_class_dao,get_class_for_delete,hard_delete_class
|
||||
from dao.cla_dao import add_class_dao,get_class_dao,update_class_dao,delete_class_dao
|
||||
|
||||
claAPI = APIRouter(prefix="/class", tags=["班级管理"])
|
||||
claAPI = APIRouter(prefix="/class", tags=["班级管理模块"])
|
||||
|
||||
@claAPI.post("", summary="新增班级")
|
||||
@claAPI.post("/", summary="新增班级信息")
|
||||
def add_class(data: claRequest, Session = Depends(get_db)):
|
||||
return add_class_dao(data, Session)
|
||||
|
||||
@claAPI.get("/list", summary="查询班级")
|
||||
@claAPI.get("/list", summary="查询班级信息")
|
||||
def list_class(n:int,m:int,Session = Depends(get_db)):
|
||||
return get_class_dao(n,m,Session)
|
||||
|
||||
@@ -21,12 +21,5 @@ def update_class(class_id: int, data: claRequest, Session = Depends(get_db)):
|
||||
def delete_class(class_id: int, Session = Depends(get_db)):
|
||||
return delete_class_dao(class_id, Session)
|
||||
|
||||
@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("/delete/confirm/{class_id}", summary="删除班级信息")
|
||||
def confirm_delete(class_id: int, Session = Depends(get_db)):
|
||||
return hard_delete_class(class_id, Session)
|
||||
|
||||
|
||||
|
||||
@@ -1,53 +1,61 @@
|
||||
from fastapi import APIRouter, Query, Depends, HTTPException, Path
|
||||
from util.database import get_db
|
||||
|
||||
from fastapi import APIRouter, Query, Depends, HTTPException, Path,Form
|
||||
from dao import employment_dao
|
||||
from dao.employment_dao import get_emp_dao, add_emp_dao, check_stu_dao, update_emp_dao, delete_emp_dao
|
||||
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,description='最低工资')
|
||||
,max_salary: Optional[float]=Query(None,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)]
|
||||
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],db=Depends(get_db)):
|
||||
if class_id:
|
||||
return employment_dao.get_emp_dao(class_id=class_id,db=db)
|
||||
def get_emp_info2(class_id: Optional[int]=Path(description='班级编号')
|
||||
,db=Depends(get_db)):
|
||||
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(stu_id:int,emp:EmploymentRequest,db=Depends(get_db)):
|
||||
if not check_stu_dao(stu_id,db):
|
||||
raise HTTPException(status_code=404, detail='该学生不存在,无法添加就业信息')
|
||||
emp.stu_id = stu_id
|
||||
exist = db.query(employment_dao.Employment_info).filter(employment_dao.Employment_info.stu_id == stu_id,employment_dao.Employment_info.delete_status == 0).first()
|
||||
if exist:
|
||||
raise HTTPException(status_code=409,detail='该学生已有就业信息,请勿重复增加!')
|
||||
def create_emp_info(emp:EmploymentRequest=Form(),db=Depends(get_db)):
|
||||
d=emp.model_dump(exclude_unset=False)
|
||||
r=add_emp_dao(d,db)
|
||||
if not r:
|
||||
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':'删除成功!'}
|
||||
|
||||
@@ -3,56 +3,74 @@ from util.database import get_db
|
||||
from model.all_model import Student_Model
|
||||
from dao.grade_dao import *
|
||||
from schema.grade_schema import *
|
||||
from fastapi import APIRouter, Depends, HTTPException, Body
|
||||
|
||||
gradeAPI = APIRouter(tags=['学生考核成绩'])
|
||||
gradeAPI = APIRouter(tags=['学生考核成绩管理模块'])
|
||||
|
||||
@gradeAPI.get("/grade/{stu_id}",response_model=list[GradeResponse],summary="根据学生id查询成绩")
|
||||
@gradeAPI.get("/grade/{stu_id}",summary="根据学生id查询成绩")
|
||||
def get_grade(stu_id: int,db=Depends(get_db)):
|
||||
try:
|
||||
res=get_grade_dao(stu_id,db)
|
||||
return res
|
||||
return {
|
||||
"code": 200,
|
||||
"detail": "查询成功",
|
||||
"data": res
|
||||
}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500,detail=f'数据库查询异常:{str(e)}')
|
||||
|
||||
@gradeAPI.post('/grade',response_model=GradeResponse,summary='添加学生成绩')
|
||||
def post_grade(o:GradeRequest=Form(),db=Depends(get_db)):
|
||||
def post_grade(o:GradeRequest,db=Depends(get_db)):
|
||||
d=o.model_dump()
|
||||
r=add_grade_dao(g=d,db=db)
|
||||
if not r:
|
||||
raise HTTPException(status_code=400, detail='学生不存在')
|
||||
return o
|
||||
|
||||
@gradeAPI.put('/{score_id}',summary='成绩修改')
|
||||
@gradeAPI.put("/grade/{score_id}", summary="成绩修改")
|
||||
def put_grade(
|
||||
score_id: int
|
||||
,o:GradeUpdate=Form()
|
||||
,db=Depends(get_db)
|
||||
score_id: int,
|
||||
exam_order: int | None = Body(default=None),
|
||||
score: float | None = Body(default=None),
|
||||
db=Depends(get_db)
|
||||
):
|
||||
# 1. 查询这条成绩记录是否存在(未删除)
|
||||
old_obj = get_score_by_id_dao(score_id=score_id, db=db)
|
||||
if not old_obj:
|
||||
raise HTTPException(status_code=404, detail="成绩记录不存在(已删除)")
|
||||
|
||||
d = o.model_dump(exclude_unset=True)
|
||||
if not d:
|
||||
raise HTTPException(status_code=400,detail='请传入需要修改的字段')
|
||||
if "exam_order" in d:
|
||||
# 2. 组装需要更新的字典,只把不为None的字段放进去
|
||||
update_data = {}
|
||||
if exam_order is not None:
|
||||
update_data["exam_order"] = exam_order
|
||||
if score is not None:
|
||||
update_data["score"] = score
|
||||
|
||||
# 没有传入任何要修改的字段
|
||||
if not update_data:
|
||||
raise HTTPException(status_code=400, detail="请传入需要修改的字段:exam_order 或 score")
|
||||
|
||||
# 3. 如果要修改考核序次,做重复校验:同一个学生不能重复的exam_order
|
||||
if "exam_order" in update_data:
|
||||
exist_obj = get_score_by_stu_exam_order_dao(
|
||||
stu_id=old_obj.stu_id,
|
||||
exam_order=d["exam_order"],
|
||||
exam_order=update_data["exam_order"],
|
||||
db=db
|
||||
)
|
||||
if exist_obj and exist_obj.id != score_id:
|
||||
# 查询到别的记录占用该学生该考核序次
|
||||
if exist_obj and exist_obj.score_id != score_id:
|
||||
raise HTTPException(status_code=409, detail="修改后的考核序次,该学生已有成绩!")
|
||||
|
||||
try:
|
||||
r = update_grade_dao(score_id=score_id, update_data=d, db=db)
|
||||
except Exception:
|
||||
raise HTTPException(status_code=409, detail="数据冲突,重复数据")
|
||||
# 4.执行数据库更新
|
||||
try:
|
||||
rows = update_grade_dao(score_id=score_id, update_data=update_data, db=db)
|
||||
except Exception:
|
||||
raise HTTPException(status_code=409, detail="数据冲突,重复数据")
|
||||
|
||||
if r == 0:
|
||||
return {"code": 200, "totals": r, "detail": "数据未发生变化"}
|
||||
if rows == 0:
|
||||
return {"code": 200, "totals": rows, "detail": "数据未发生变化"}
|
||||
|
||||
return {"code": 200, "totals": r, "detail": "更新成功"}
|
||||
return {"code": 200, "totals": rows, "detail": "更新成功"}
|
||||
|
||||
@gradeAPI.delete('/{score_id}',summary='删除成绩')
|
||||
def delete_grade(score_id:int,db=Depends(get_db)):
|
||||
|
||||
@@ -1,43 +1,42 @@
|
||||
from fastapi import APIRouter,Depends,Query
|
||||
from dao.statistics_dao import *
|
||||
from schema.student_schema import StudentResponse
|
||||
from schema.statistics_schema import *
|
||||
from schema.student_schema import *
|
||||
from util.database import get_db
|
||||
|
||||
StatisticsAPI = APIRouter()
|
||||
StatisticsAPI = APIRouter(tags=['统计分析模块'])
|
||||
|
||||
@StatisticsAPI.get("/age",response_model=list[StudentResponse],tags=['统计分析模块'],summary='根据年龄查询学生信息')
|
||||
@StatisticsAPI.get("/age",response_model=list[StudentResponse],summary='根据年龄查询学生信息')
|
||||
def get_students(min_age:int|None=Query(None,ge=0,le=150),max_age:int|None=Query(None,ge=0,le=150),db=Depends(get_db)):
|
||||
l = select_age(min_age,max_age,db)
|
||||
return l
|
||||
|
||||
@StatisticsAPI.get("/all",response_model=list[AllStuResponse],tags=['统计分析模块'],summary='统计每个班级的学员总数和男女生总数')
|
||||
@StatisticsAPI.get("/all",response_model=list[AllStuResponse],summary='统计每个班级的学员总数和男女生总数')
|
||||
def get_students(db=Depends(get_db)):
|
||||
l = select_all(db)
|
||||
return l
|
||||
|
||||
@StatisticsAPI.get("/score",response_model=StudentResponse,tags=['统计分析模块'],summary='根据成绩查询学生信息')
|
||||
@StatisticsAPI.get("/score",response_model=list[GetScoreResponse],summary='根据成绩查询学生信息')
|
||||
def get_students(min_score:int|None=None,max_score:int|None=None,db=Depends(get_db)):
|
||||
l = select_score(min_score,max_score,db)
|
||||
return [i for i in l]
|
||||
return l
|
||||
|
||||
@StatisticsAPI.get("/avg_score",response_model=list[AcgScoreResponse],tags=['统计分析模块'],summary='统计每次考试每个班级的平均分并排序')
|
||||
@StatisticsAPI.get("/avg_score",response_model=list[AcgScoreResponse],summary='统计每次考试每个班级的平均分并排序')
|
||||
def get_scores(db=Depends(get_db)):
|
||||
l = select_avg_score(db)
|
||||
return l
|
||||
|
||||
@StatisticsAPI.get("/salary",response_model=list[StudentResponse],tags=['统计分析模块'],summary='统计薪资最高的前五名的学员信息')
|
||||
@StatisticsAPI.get("/salary",response_model=list[GetStuResponse],summary='统计薪资最高的前五名的学员信息')
|
||||
def get_scores(db=Depends(get_db)):
|
||||
l = select_salary(db)
|
||||
return l
|
||||
|
||||
@StatisticsAPI.get("/avg_day",response_model=list[AvgDayResponse],tags=['统计分析模块'],summary='统计每个班级的平均就业时长')
|
||||
@StatisticsAPI.get("/avg_day",response_model=list[AvgDayResponse],summary='统计每个班级的平均就业时长')
|
||||
def get_days(db=Depends(get_db)):
|
||||
l = select_days(db)
|
||||
l = select_avg_days(db)
|
||||
return l
|
||||
|
||||
|
||||
@StatisticsAPI.get('/emp',response_model=AllEmpResponse,tags=['统计分析模块'],summary='统计每个学生的就业时长')
|
||||
@StatisticsAPI.get('/emp',response_model=list[AllDayResponse],summary='统计每个学生的就业时长')
|
||||
def get_emp(db=Depends(get_db)):
|
||||
l= select_days2(db)
|
||||
return l
|
||||
l= select_days(db)
|
||||
return l
|
||||
|
||||
@@ -4,9 +4,9 @@ from schema.student_schema import *
|
||||
from util.database import get_db
|
||||
|
||||
|
||||
StudentAPI = APIRouter()
|
||||
StudentAPI = APIRouter(tags=['学生基本信息管理模块'])
|
||||
|
||||
@StudentAPI.get('/students',response_model=StudentPageResponse,tags=['学⽣基本信息管理模块'],summary='学生信息查询接口',description='查询学生信息')
|
||||
@StudentAPI.get('/students',response_model=StudentPageResponse,summary='学生信息查询接口',description='查询学生信息')
|
||||
def get_students(stu_id:int|None=None
|
||||
,stu_name:str|None=None
|
||||
,class_id:int|None=None
|
||||
@@ -27,7 +27,7 @@ def get_students(stu_id:int|None=None
|
||||
totals=total,
|
||||
data=r)
|
||||
|
||||
@StudentAPI.put('/{stu_id}',tags=['学⽣基本信息管理模块'],summary='学生信息更新接口',description='更新学生信息')
|
||||
@StudentAPI.put('/{stu_id}',summary='学生信息更新接口',description='更新学生信息')
|
||||
def update_students(s:StudentRequest
|
||||
,stu_id:int
|
||||
,db=Depends(get_db)):
|
||||
@@ -39,7 +39,7 @@ def update_students(s:StudentRequest
|
||||
raise HTTPException(status_code=500, detail='没有更新')
|
||||
return {'code':200,'totals':r,'detail':'更新成功'}
|
||||
|
||||
@StudentAPI.delete('/{stu_id}',tags=['学⽣基本信息管理模块'],summary='学生信息删除接口',description='删除学生信息')
|
||||
@StudentAPI.delete('/{stu_id}',summary='学生信息删除接口',description='删除学生信息')
|
||||
def del_students(stu_id:int
|
||||
,db=Depends(get_db)):
|
||||
rows=delete_student_dao( stu_id=stu_id,db=db )
|
||||
@@ -47,7 +47,7 @@ def del_students(stu_id:int
|
||||
raise HTTPException(status_code=404,detail='对象已被删除')
|
||||
return {'code':200,'totals':rows,'detail':'删除成功'}
|
||||
|
||||
@StudentAPI.post('/students',tags=['学⽣基本信息管理模块'],response_model=StugetResponse,summary='学生信息新增接口',description='新增学生信息')
|
||||
@StudentAPI.post('/students',response_model=StugetResponse,summary='学生信息新增接口',description='新增学生信息')
|
||||
def add_students(s:StudentRequest
|
||||
,db=Depends(get_db)):
|
||||
d = s.model_dump(exclude_unset=True)
|
||||
|
||||
@@ -6,16 +6,16 @@ from dao.teacher_dao import update_teacher
|
||||
from dao.teacher_dao import delete_teacher
|
||||
from dao.teacher_dao import get_teacher
|
||||
|
||||
teacher_api=APIRouter()
|
||||
teacher_api=APIRouter(tags=['教师基本信息管理模块'])
|
||||
|
||||
@teacher_api.post("/teachers",response_model=Teacher_ResponseModel,tags=['教师基本信息管理模块'],summary='新增教师接口')
|
||||
@teacher_api.post("/teachers",response_model=Teacher_ResponseModel,summary='新增教师接口')
|
||||
def add_teacher1(x1:Teacher_RequestModel,session=Depends(get_db)):
|
||||
y=add_teacher(x1.model_dump(),session)
|
||||
if not y:
|
||||
raise HTTPException(status_code=500,detail='添加异常!')
|
||||
return x1
|
||||
|
||||
@teacher_api.get("/teachers",tags=['教师基本信息管理模块'],summary='查询教师接口')
|
||||
@teacher_api.get("/teachers",summary='查询教师接口')
|
||||
def get_teacher1(teacid:int, session=Depends(get_db)):
|
||||
# r = get_teacher(id=id,session=session)
|
||||
# if not r:
|
||||
@@ -27,7 +27,7 @@ def get_teacher1(teacid:int, session=Depends(get_db)):
|
||||
raise HTTPException(status_code=500,detail='数据库查询异常!')
|
||||
|
||||
|
||||
@teacher_api.put("/teachers/{t_id}",tags=['教师基本信息管理模块'],summary='更新教师接口')
|
||||
@teacher_api.put("/teachers/{t_id}",summary='更新教师接口')
|
||||
def update_teacher1(t_id:int,teacher:Teacher_RequestModel,session=Depends(get_db)):
|
||||
d=teacher.model_dump(exclude_unset=True)
|
||||
r=update_teacher(id=t_id,req=d,session=session)
|
||||
@@ -36,7 +36,7 @@ def update_teacher1(t_id:int,teacher:Teacher_RequestModel,session=Depends(get_db
|
||||
return {'code':200,'detail':'更新成功!','data':teacher}
|
||||
|
||||
|
||||
@teacher_api.delete("/teachers/{t_id}",tags=['教师基本信息管理模块'],summary='删除教师接口')
|
||||
@teacher_api.delete("/teachers/{t_id}",summary='删除教师接口')
|
||||
def delete_teacher1(t_id:int,session=Depends(get_db)):
|
||||
r=delete_teacher(id=t_id,session=session)
|
||||
if not r:
|
||||
|
||||
Reference in New Issue
Block a user