Compare commits
85
Commits
28e3738968
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79da6dc3a0 | ||
|
|
1af01f94ee | ||
|
|
fd1f9f71de | ||
|
|
4849e73771 | ||
|
|
4e99cfd3b1 | ||
|
|
739c8887fc | ||
|
|
30ae0af56e | ||
|
|
5b10d0e868 | ||
|
|
6ff3d5974d | ||
|
|
de67f868cb | ||
|
|
a132eb47b2 | ||
|
|
847b908c4f | ||
|
|
664741e52f | ||
|
|
7a25cf6f68 | ||
|
|
0a7fd06d83 | ||
|
|
40a6d79b37 | ||
|
|
acd04828a1 | ||
|
|
85b0d97a3d | ||
|
|
b829e4063f | ||
|
|
5a191c291e | ||
|
|
0c099b5f9c | ||
|
|
4341606d65 | ||
|
|
4f8114c9a1 | ||
|
|
13278d38c7 | ||
|
|
a67828a29f | ||
|
|
5cc1565225 | ||
|
|
55d99e17e0 | ||
|
|
3df20541be | ||
|
|
4dbb23e5c5 | ||
|
|
6c04e1b306 | ||
|
|
0813204469 | ||
|
|
ae2af187e7 | ||
|
|
957e826e0f | ||
|
|
acb4036589 | ||
|
|
2a3d1be2e3 | ||
|
|
43c558d5bc | ||
|
|
f7911c8911 | ||
|
|
d7083402aa | ||
|
|
e9086e842b | ||
|
|
7d8971fc83 | ||
|
|
bf44ac9450 | ||
|
|
14e792885a | ||
|
|
a4136ea648 | ||
|
|
fba5750c6d | ||
|
|
63da43df1e | ||
|
|
d9fc0b97a0 | ||
|
|
6cb4c4a1af | ||
|
|
476e75118a | ||
|
|
601e3b7d39 | ||
|
|
da935f93bd | ||
|
|
e57476f741 | ||
|
|
5a85014b64 | ||
|
|
7eb33e633b | ||
|
|
5a39567f47 | ||
|
|
bb32be8f99 | ||
|
|
d270bd7ad1 | ||
|
|
d650cfe928 | ||
|
|
bff10de7fa | ||
|
|
4681652172 | ||
|
|
4198e0af4e | ||
|
|
751d430e3e | ||
|
|
3223836126 | ||
|
|
3ee3c2e850 | ||
|
|
f52f598a21 | ||
|
|
9132c17fb4 | ||
|
|
7ae2f0009b | ||
|
|
abfb7bf448 | ||
|
|
5ff7e0620e | ||
|
|
2c9d9d1d1c | ||
|
|
603fee7fd4 | ||
|
|
59f81833a3 | ||
|
|
9e13a01c76 | ||
|
|
dccc0b6092 | ||
|
|
42e8130166 | ||
|
|
ffc07d3f38 | ||
|
|
abf6e3829d | ||
|
|
b31b3f055c | ||
|
|
2d9ddd051a | ||
|
|
359542b373 | ||
|
|
ed51aecf76 | ||
|
|
2b2b4b658f | ||
|
|
92b98226d8 | ||
|
|
e13ace8616 | ||
|
|
46faa300a8 | ||
|
|
26429d6b6f |
@@ -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,54 @@
|
||||
from fastapi import APIRouter,Query,Depends,HTTPException
|
||||
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 schema.employment_schema import EmploymentRequest,EmploymentResponse
|
||||
from dao.employment_dao import add_emp_dao, update_emp_dao, delete_emp_dao
|
||||
from schema.employment_schema import EmploymentRequest,UpdateEmpRequest,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='获取学生就业信息')
|
||||
def get_emp_info1(stu_id: Optional[int]=Query(None,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)]
|
||||
raise HTTPException(status_code=404, detail='该学生就业信息不存在')
|
||||
emp_api = APIRouter(tags=['学生就业管理模块'])
|
||||
|
||||
@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)
|
||||
@emp_api.get('/employment/class/{class_id}',response_model=list[EmploymentResponse],summary='获取班级学生就业信息')
|
||||
def get_emp_info1(class_id: Optional[int]=Path(description='班级编号')
|
||||
,db=Depends(get_db)):
|
||||
e1 = employment_dao.get_emp_dao(class_id=class_id, db=db)
|
||||
if e1:
|
||||
return e1
|
||||
raise HTTPException(status_code=404, detail='该班级就业信息不存在')
|
||||
|
||||
@emp_api.get('/employment/students/{stu_id}',response_model=list[EmploymentResponse],summary='按照学⽣编号,公司名字,⼯资范围查询学⽣就业信息')
|
||||
def get_emp_info2(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='最高工资')
|
||||
,db=Depends(get_db)):
|
||||
if min_salary and max_salary:
|
||||
if min_salary > max_salary:
|
||||
raise HTTPException(status_code=404, detail='最低工资不能大于最高工资')
|
||||
l1 = employment_dao.get_emp_dao(db, stu_id=stu_id
|
||||
, company_name=company_name
|
||||
, min_salary=min_salary
|
||||
, max_salary=max_salary)
|
||||
if not l1:
|
||||
raise HTTPException(status_code=404,detail='该学生就业信息不存在!')
|
||||
return l1
|
||||
|
||||
@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)):
|
||||
d = emp.model_dump(exclude_unset=True)
|
||||
r = update_emp_dao(stu_id,d,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='更新失败!')
|
||||
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)):
|
||||
@gradeAPI.post('/grade',summary='添加学生成绩')
|
||||
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,52 @@
|
||||
from fastapi import APIRouter,Depends
|
||||
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='根据年龄查询学生信息')
|
||||
def get_students(min_age:int|None=None,max_age:int|None=None,db=Depends(get_db)):
|
||||
@StatisticsAPI.get("/age",response_model=list[StugetResponse],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
|
||||
|
||||
@StatisticsAPI.get('/salaries',summary='统计薪资分布')
|
||||
def get_salaries(db=Depends(get_db)):
|
||||
s=classify_salary(db)
|
||||
return s
|
||||
|
||||
@StatisticsAPI.get('/avg_salaries',summary='统计每个班级平均薪资')
|
||||
def get_avg_salaries(db=Depends(get_db)):
|
||||
s=avg_salary(db)
|
||||
return s
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
from fastapi import APIRouter,Depends,HTTPException
|
||||
from fastapi import APIRouter,HTTPException,Depends
|
||||
from dao.student_dao import *
|
||||
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=StuPageResponse,summary='学生信息查询接口',description='查询学生信息')
|
||||
def get_students(stu_id:int|None=None
|
||||
,stu_name:str|None=None
|
||||
,class_id:int|None=None
|
||||
@@ -19,39 +19,43 @@ def get_students(stu_id:int|None=None
|
||||
,page=page
|
||||
,page_size=page_size
|
||||
,db=db)
|
||||
|
||||
if not r:
|
||||
raise HTTPException(status_code=404,detail='学生不存在')
|
||||
return StudentPageResponse(page=page,
|
||||
return StuPageResponse(page=page,
|
||||
page_size=page_size,
|
||||
total=total,
|
||||
totals=total,
|
||||
data=r)
|
||||
|
||||
@StudentAPI.put('/{stu_id}',tags=['学⽣基本信息管理模块'],summary='学生信息更新接口',description='更新学生信息')
|
||||
def update_students(s:StudentRequest
|
||||
,stu_id:int
|
||||
,db=Depends(get_db)):
|
||||
@StudentAPI.post('/students',response_model=StugetResponse,summary='学生信息新增接口',description='新增学生信息')
|
||||
def add_students(s:StudentRequest
|
||||
,db=Depends(get_db)):
|
||||
d = s.model_dump(exclude_unset=True)
|
||||
if not d:
|
||||
raise HTTPException(status_code=400, detail='更新内容不能为空!')
|
||||
raise HTTPException(status_code=400, detail='添加内容不能为空')
|
||||
r = add_student_dao( o=d, db=db)
|
||||
if r == 'conflict':
|
||||
raise HTTPException(status_code=409, detail='身份证号已存在,请勿重复添加')
|
||||
if r == 'error':
|
||||
raise HTTPException(status_code=500, detail='添加失败,请稍后重试')
|
||||
return r
|
||||
|
||||
@StudentAPI.put('/students/{stu_id}',summary='学生信息更新接口',description='更新学生信息')
|
||||
def update_students(stu_id:int
|
||||
,s:StuUpdateRequest
|
||||
,db=Depends(get_db)):
|
||||
d = s.model_dump(exclude_unset=True)
|
||||
d.pop('stu_id', None)
|
||||
if not d:
|
||||
raise HTTPException(status_code=400, detail='更新内容不能为空')
|
||||
r = update_student_dao( stu_id=stu_id,update_data=d,db=db )
|
||||
if r == 'error':
|
||||
raise HTTPException(status_code=500, detail='更新失败,请稍后重试')
|
||||
if not r:
|
||||
raise HTTPException(status_code=500, detail='没有更新!')
|
||||
raise HTTPException(status_code=404, detail='学生不存在或已被删除,更新失败')
|
||||
return {'code':200,'totals':r,'detail':'更新成功'}
|
||||
|
||||
@StudentAPI.delete('/{stu_id}',tags=['学⽣基本信息管理模块'],summary='学生信息删除接口',description='删除学生信息')
|
||||
@StudentAPI.delete('/students/{stu_id}',response_model= StudelResponse,summary='学生信息删除接口',description='删除学生信息')
|
||||
def del_students(stu_id:int
|
||||
,db=Depends(get_db)):
|
||||
rows=delete_student_dao( stu_id=stu_id,db=db )
|
||||
if not rows:
|
||||
raise HTTPException(status_code=500,detail='没有删除')
|
||||
raise HTTPException(status_code=404,detail='学生不存在或已被删除')
|
||||
return {'code':200,'totals':rows,'detail':'删除成功'}
|
||||
|
||||
@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)
|
||||
stu_new=add_student_dao(o=d,db=db)
|
||||
if not stu_new:
|
||||
raise HTTPException(status_code=500,detail='添加失败')
|
||||
return stu_new
|
||||
|
||||
@@ -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,18 +27,18 @@ 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)
|
||||
if not r:
|
||||
raise HTTPException(status_code=500, detail='更新异常!')
|
||||
return {'code':200,'detail':'cg'}
|
||||
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:
|
||||
raise HTTPException(status_code=500,detail='删除异常!')
|
||||
return {'code': 200, 'detail':'成功!'}
|
||||
return {'code': 200, 'detail':'删除成功!'}
|
||||
@@ -1,19 +1,20 @@
|
||||
from model.all_model import ClassManagement
|
||||
from fastapi import HTTPException
|
||||
from schema.cla_schema import claRequest
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def add_class_dao(c:claRequest,session):
|
||||
def add_class_dao(c: claRequest, session):
|
||||
try:
|
||||
data = c.model_dump()
|
||||
d = ClassManagement(**data)
|
||||
session.add(d)
|
||||
session.commit()
|
||||
session.refresh(d)
|
||||
return d
|
||||
except:
|
||||
session.rollback()
|
||||
return '输入有误,请重新添加班级!'
|
||||
else:
|
||||
session.commit()
|
||||
return '添加成功!'
|
||||
raise HTTPException(400, "输入有误,请重新添加班级!")
|
||||
|
||||
def get_class_dao(n,m,session):
|
||||
try:
|
||||
@@ -22,7 +23,7 @@ def get_class_dao(n,m,session):
|
||||
except:
|
||||
raise HTTPException(status_code=406,detail="输入查询信息有误,请重新输入!")
|
||||
|
||||
def update_class_dao(id:int,req:ClassManagement,session):
|
||||
def update_class_dao(id:int,req:claRequest,session):
|
||||
try:
|
||||
session.query(ClassManagement).filter(ClassManagement.class_id==id)\
|
||||
.filter(ClassManagement.delete_status==0).update(req.model_dump(exclude_unset=True))
|
||||
@@ -34,50 +35,13 @@ def update_class_dao(id:int,req:ClassManagement,session):
|
||||
def delete_class_dao(id:int,session):
|
||||
try:
|
||||
session.query(ClassManagement).filter(ClassManagement.class_id==id,ClassManagement.delete_status==0)\
|
||||
.update({'delete_status': 1})
|
||||
.update({'delete_status': 1,'delete_time': datetime.now()})
|
||||
session.commit()
|
||||
except:
|
||||
raise HTTPException(status_code=404, detail="删除异常,请重新核对之后删除!")
|
||||
return '删除成功,请核对信息!'
|
||||
|
||||
def get_class_for_delete(id: int, session):
|
||||
try:
|
||||
obj = (
|
||||
session.query(ClassManagement).filter(ClassManagement.class_id == id,ClassManagement.delete_status == 0).first()
|
||||
)
|
||||
if not obj:
|
||||
raise HTTPException(status_code=404, detail="班级不存在")
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500, detail="查询异常,请重新核对!")
|
||||
|
||||
return {
|
||||
"class_id": obj.class_id,
|
||||
"class_name": obj.class_name,
|
||||
"start_class_date": obj.start_class_date,
|
||||
"head_teacher_id": obj.head_teacher_id,
|
||||
"class_teacher_id": obj.class_teacher_id,
|
||||
}
|
||||
|
||||
def hard_delete_class(id: int, session):
|
||||
try:
|
||||
obj = (
|
||||
session.query(ClassManagement).filter(ClassManagement.class_id == id,ClassManagement.delete_status == 0)
|
||||
.first()
|
||||
)
|
||||
if not obj:
|
||||
raise HTTPException(status_code=404, detail="班级不存在")
|
||||
|
||||
session.delete(obj)
|
||||
session.commit()
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
session.rollback()
|
||||
raise HTTPException(status_code=500, detail="删除异常,请重新核对之后删除!")
|
||||
|
||||
return '删除成功,请核对信息!'
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,46 +1,51 @@
|
||||
from fastapi import HTTPException
|
||||
from model.all_model import Employment_info, ClassManagement, Student_Model
|
||||
from datetime import datetime
|
||||
|
||||
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
|
||||
,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)
|
||||
|
||||
def get_emp_dao(stu_id=None,class_id=None,company_name=None,min_salary=None,max_salary=None,db=None):
|
||||
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)
|
||||
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()
|
||||
r = q.all()
|
||||
return r
|
||||
|
||||
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()
|
||||
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())
|
||||
if exist:
|
||||
raise HTTPException(status_code=409, detail='该学生已有就业信息,请勿重复增加!')
|
||||
|
||||
e1 = Employment_info(**o)
|
||||
db.add(e1)
|
||||
db.commit()
|
||||
@@ -49,13 +54,11 @@ def add_emp_dao(o,db):
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500, detail=f'新增就业信息失败: {e}')
|
||||
|
||||
def check_stu_dao(stu_id,db):
|
||||
stu = db.query(Student_Model).filter(Student_Model.stu_id == stu_id,Student_Model.delete_status == 0).first()
|
||||
return stu
|
||||
|
||||
def update_emp_dao(stu_id,o,db):
|
||||
def update_emp_dao(emp_id,emp,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)\
|
||||
.update(emp)
|
||||
db.commit()
|
||||
return rows
|
||||
except:
|
||||
@@ -63,9 +66,12 @@ 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).delete()
|
||||
rows = db.query(Employment_info)\
|
||||
.filter(Employment_info.emp_id == emp_id
|
||||
,Employment_info.delete_status == 0)\
|
||||
.update({'delete_status':1,'delete_time': datetime.now()})
|
||||
db.commit()
|
||||
except:
|
||||
db.rollback()
|
||||
|
||||
@@ -7,20 +7,38 @@ from model.all_model import *
|
||||
# 根据id查询单条有效成绩
|
||||
def get_score_by_id_dao(score_id:int, db):
|
||||
return db.query(WlScore).filter(
|
||||
WlScore.id == score_id
|
||||
,WlScore.delete_status==1
|
||||
WlScore.score_id == score_id
|
||||
,WlScore.delete_status==0
|
||||
).first()
|
||||
|
||||
# 根据stu_id+exam_order查重(新增、修改时校验重复)
|
||||
def get_score_by_stu_exam_order_dao(stu_id:str,exam_order:int,db):
|
||||
return db.query(WlScore).filter(WlScore.stu_id==stu_id,WlScore.exam_order==exam_order,WlScore.delete_status==0).first()
|
||||
return db.query(WlScore).filter(WlScore.stu_id==stu_id
|
||||
,WlScore.exam_order==exam_order
|
||||
,WlScore.delete_status==0).first()
|
||||
|
||||
def get_grade_dao( stu_id:int , db):
|
||||
|
||||
r1 =db.query(WlScore).filter(WlScore.stu_id == stu_id,WlScore.delete_status == 0).all()
|
||||
r1 =(db.query( WlScore.score_id
|
||||
,WlScore.stu_id
|
||||
,Student_Model.stu_name
|
||||
,WlScore.exam_order
|
||||
,WlScore.score
|
||||
)
|
||||
.join(Student_Model,WlScore.stu_id == Student_Model.stu_id)
|
||||
.filter(WlScore.stu_id == stu_id,WlScore.delete_status == 0,Student_Model.delete_status == 0)
|
||||
.all())
|
||||
if r1:
|
||||
|
||||
return r1
|
||||
data_list = []
|
||||
for row in r1:
|
||||
data_list.append({
|
||||
"score_id": row.score_id,
|
||||
"stu_id": row.stu_id,
|
||||
"stu_name": row.stu_name,
|
||||
"exam_order": row.exam_order,
|
||||
"score": row.score
|
||||
})
|
||||
return data_list
|
||||
else:
|
||||
raise HTTPException(status_code=404,detail="学生不存在")
|
||||
|
||||
@@ -52,7 +70,7 @@ def delete_grade_dao(stu_id:int,db):
|
||||
rows = db.query(WlScore).filter(
|
||||
WlScore.stu_id == stu_id,
|
||||
WlScore.delete_status == 0
|
||||
).update({'delete_status':1})
|
||||
).update({'delete_status':1,'delete_time':datetime.now()})
|
||||
except:
|
||||
db.rollback()
|
||||
return False
|
||||
|
||||
@@ -12,7 +12,6 @@ def select_age(min_age,max_age,db):
|
||||
db = db.filter(Student_Model.age >= min_age,Student_Model.delete_status == 0)
|
||||
if max_age is not None:
|
||||
db = db.filter(Student_Model.age <= max_age,Student_Model.delete_status == 0)
|
||||
print('abc',db.all())
|
||||
return db.all()
|
||||
except HTTPException:
|
||||
raise
|
||||
@@ -24,7 +23,26 @@ def select_all(db):
|
||||
try:
|
||||
l1 = db.query(Student_Model.class_id,Student_Model.gender,func.count(1).label('cnt'))\
|
||||
.group_by(Student_Model.class_id,Student_Model.gender).all()
|
||||
return l1
|
||||
|
||||
d1 = {}
|
||||
for i in l1:
|
||||
if i.class_id not in d1:
|
||||
d1[i.class_id] = 0
|
||||
d1[i.class_id] += i.cnt
|
||||
|
||||
l2 = []
|
||||
for i in l1:
|
||||
l2.append({
|
||||
"all_cnt": d1[i.class_id],
|
||||
"class_id": i.class_id,
|
||||
"gender": i.gender,
|
||||
"cnt": i.cnt
|
||||
})
|
||||
if not l2:
|
||||
raise HTTPException(status_code=404, detail="没有数据")
|
||||
return l2
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
|
||||
@@ -33,14 +51,28 @@ def select_score(min_score,max_score,db):
|
||||
try:
|
||||
if min_score is None and max_score is None:
|
||||
raise HTTPException(status_code=400, detail="请至少传入一个参数")
|
||||
db = db.query(Student_Model,WlScore.score,WlScore.score)\
|
||||
db = db.query(WlScore.score
|
||||
,Student_Model.stu_name
|
||||
,Student_Model.age
|
||||
,Student_Model.gender
|
||||
,Student_Model.native_place
|
||||
,Student_Model.school
|
||||
,Student_Model.major
|
||||
,Student_Model.degree
|
||||
,Student_Model.admission_date
|
||||
,Student_Model.graduation_date
|
||||
,Student_Model.progress
|
||||
)\
|
||||
.join(WlScore,WlScore.stu_id == Student_Model.stu_id)\
|
||||
.filter(WlScore.delete_status==0,Student_Model.delete_status == 0)
|
||||
if min_score is not None:
|
||||
db = db.filter(WlScore.score >= min_score)
|
||||
if min_score is not None:
|
||||
if max_score is not None:
|
||||
db = db.filter(WlScore.score <= max_score)
|
||||
return db.all()
|
||||
l1 = db.all()
|
||||
if not l1:
|
||||
raise HTTPException(status_code=404, detail="没有数据")
|
||||
return l1
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
@@ -49,29 +81,47 @@ def select_score(min_score,max_score,db):
|
||||
# 实现统计每次考试每个班级的平均分并排序的功能
|
||||
def select_avg_score(db):
|
||||
try:
|
||||
l1 = db.query(Student_Model.class_id,func.avg(WlScore.score).label('avg_score'))\
|
||||
l1 = db.query(Student_Model.class_id,func.round(func.avg(WlScore.score),1).label('avg_score'))\
|
||||
.join(Student_Model,WlScore.stu_id == Student_Model.stu_id)\
|
||||
.filter(WlScore.delete_status==0,Student_Model.delete_status == 0)\
|
||||
.group_by(Student_Model.class_id)\
|
||||
.order_by(func.avg(WlScore.score)).all()
|
||||
.order_by(func.round(func.avg(WlScore.score),1)).all()
|
||||
if not l1:
|
||||
raise HTTPException(status_code=404, detail="没有数据")
|
||||
return l1
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
|
||||
# 实现统计薪资最高的前五名的学员信息
|
||||
def select_salary(db):
|
||||
try:
|
||||
l1 = db.query(Student_Model,Employment_info.salary)\
|
||||
l1 = db.query(Employment_info.salary
|
||||
,Student_Model.stu_name
|
||||
,Student_Model.age
|
||||
,Student_Model.gender
|
||||
,Student_Model.native_place
|
||||
,Student_Model.school
|
||||
,Student_Model.major
|
||||
,Student_Model.degree
|
||||
,Student_Model.admission_date
|
||||
,Student_Model.graduation_date
|
||||
,Student_Model.progress)\
|
||||
.join(Employment_info,Employment_info.stu_id==Student_Model.stu_id)\
|
||||
.filter(Employment_info.delete_status==0,Student_Model.delete_status == 0)\
|
||||
.order_by(Employment_info.salary.desc())\
|
||||
.limit(5).all()
|
||||
if not l1:
|
||||
raise HTTPException(status_code=404, detail="没有数据")
|
||||
return l1
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
|
||||
# 实现统计每个班级的平均就业时长
|
||||
def select_days(db):
|
||||
def select_avg_days(db):
|
||||
try:
|
||||
l1 = db.query(Student_Model.class_id,
|
||||
func.coalesce(
|
||||
@@ -85,27 +135,62 @@ def select_days(db):
|
||||
Employment_info.delete_status == 0,
|
||||
Employment_info.employment_opening_date.isnot(None),
|
||||
Employment_info.offer_issuance_date.isnot(None),)\
|
||||
.group_by( Student_Model.class_id)\
|
||||
.group_by(Student_Model.class_id)\
|
||||
.order_by(func.avg(func.datediff(Employment_info.offer_issuance_date,Student_Model.admission_date)).desc()).all()
|
||||
if not l1:
|
||||
raise HTTPException(status_code=404, detail="没有数据")
|
||||
return l1
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500, detail="查询异常")
|
||||
|
||||
#统计每个学⽣的就业时⻓
|
||||
def select_days2(db):
|
||||
def select_days(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
|
||||
l1 =db.query(Employment_info.stu_id
|
||||
,func.coalesce(func.datediff(Employment_info.offer_issuance_date
|
||||
,Employment_info.employment_opening_date),0)\
|
||||
.label("diff_days")
|
||||
).filter(Employment_info.delete_status == 0).all()
|
||||
if not l1:
|
||||
raise HTTPException(status_code=404, detail="没有数据")
|
||||
return l1
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500, detail="查询异常")
|
||||
raise HTTPException(status_code=500, detail="查询异常")
|
||||
|
||||
|
||||
# 薪资区间分布:统计薪资在5k以下、5k-10k、10k-15k、15k以上的人数分布,反映学生的整体就业质量。
|
||||
def classify_salary(db):
|
||||
try:
|
||||
a=b=c=d=0
|
||||
l=db.query(Employment_info).filter(Employment_info.delete_status==0).all()
|
||||
for i in l:
|
||||
if i.salary is None:
|
||||
continue
|
||||
elif i.salary<5000:
|
||||
a+=1
|
||||
elif 5000<=i.salary<10000:
|
||||
b+=1
|
||||
elif 10000<=i.salary<15000:
|
||||
c+=1
|
||||
else:
|
||||
d+=1
|
||||
return {'5k以下': a, '5k-10k': b, '10k-15k': c, '15k以上': d}
|
||||
except:
|
||||
raise HTTPException(status_code=500,detail='查询异常!')
|
||||
|
||||
#统计每个班的平均就业薪资
|
||||
def avg_salary(db):
|
||||
try:
|
||||
l=db.query(Student_Model.class_id,func.avg(Employment_info.salary).label('avg_salaries'))\
|
||||
.join(Employment_info,Employment_info.stu_id == Student_Model.stu_id)\
|
||||
.filter(Employment_info.salary>0,Employment_info.delete_status==0,Student_Model.delete_status==0)\
|
||||
.group_by(Student_Model.class_id)\
|
||||
.order_by(func.avg(Employment_info.salary).desc()).all()
|
||||
return [{'class_id':i[0],'avg_salaries':i[1]} for i in l]
|
||||
except:
|
||||
raise HTTPException(status_code=500,detail='统计异常!')
|
||||
|
||||
|
||||
@@ -1,40 +1,56 @@
|
||||
from fastapi import Depends
|
||||
from util.database import get_db
|
||||
from model.all_model import Student_Model
|
||||
from typing import List, Optional, Dict, Any
|
||||
from datetime import datetime
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
def add_student_dao(o,db):
|
||||
if o.get('id_card'):
|
||||
conflict = (db.query(Student_Model)
|
||||
.filter(Student_Model.id_card == o['id_card'],
|
||||
Student_Model.delete_status == 0)
|
||||
.first())
|
||||
if conflict:
|
||||
return 'conflict'
|
||||
try:
|
||||
o1 = Student_Model( **o)
|
||||
db.add(o1)
|
||||
o2 = Student_Model(**o)
|
||||
db.add(o2)
|
||||
db.commit()
|
||||
stu_id=o1.stu_id
|
||||
return db.query(Student_Model).filter(Student_Model.stu_id == stu_id).first()
|
||||
except:
|
||||
return o2
|
||||
except IntegrityError:
|
||||
db.rollback()
|
||||
return None
|
||||
return 'conflict'
|
||||
except Exception:
|
||||
db.rollback()
|
||||
return 'error'
|
||||
|
||||
def delete_student_dao(stu_id,db):
|
||||
def delete_student_dao(stu_id, db):
|
||||
try:
|
||||
rows = db.query(Student_Model).filter(Student_Model.stu_id == stu_id,Student_Model.delete_status == 0)\
|
||||
.update({'delete_status':1,'delete_time': datetime.now()})
|
||||
db.commit()
|
||||
except:
|
||||
db.rollback()
|
||||
rows = 0
|
||||
finally:
|
||||
return rows
|
||||
|
||||
def update_student_dao(stu_id,update_data,db):
|
||||
try:
|
||||
rows = db.query( Student_Model ).filter( Student_Model.stu_id == stu_id,Student_Model.delete_status == 0).update( update_data )
|
||||
except:
|
||||
db.rollback()
|
||||
return False
|
||||
else:
|
||||
rows = (db.query(Student_Model)
|
||||
.filter(Student_Model.stu_id == stu_id,
|
||||
Student_Model.delete_status == 0)
|
||||
.update({'delete_status': 1, 'delete_time': datetime.now()}))
|
||||
db.commit()
|
||||
return rows
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise
|
||||
|
||||
def update_student_dao(stu_id, update_data, db):
|
||||
if not update_data:
|
||||
return 0
|
||||
try:
|
||||
rows = (db.query(Student_Model)
|
||||
.filter(Student_Model.stu_id == stu_id,
|
||||
Student_Model.delete_status == 0)
|
||||
.update(update_data))
|
||||
db.commit()
|
||||
except IntegrityError:
|
||||
db.rollback()
|
||||
return 'conflict'
|
||||
except Exception:
|
||||
db.rollback()
|
||||
return 'error'
|
||||
return rows
|
||||
|
||||
def get_student_dao(stu_id:Optional[int]
|
||||
,stu_name:Optional[str]
|
||||
@@ -43,17 +59,13 @@ def get_student_dao(stu_id:Optional[int]
|
||||
,page_size: int
|
||||
,db
|
||||
) -> tuple[List[Dict[str, Any]], int]:
|
||||
try:
|
||||
q = db.query(Student_Model)
|
||||
if stu_id:
|
||||
q = q.filter(Student_Model.stu_id == stu_id,Student_Model.delete_status == 0)
|
||||
if stu_name and stu_name.strip() != "":
|
||||
q = q.filter(Student_Model.stu_name.like(f"%{stu_name}%"),Student_Model.delete_status == 0)
|
||||
if class_id:
|
||||
q= q.filter(Student_Model.class_id == class_id,Student_Model.delete_status == 0)
|
||||
total = q.count()
|
||||
r = q.offset((page - 1) * page_size).limit(page_size).all()
|
||||
return r,total
|
||||
except:
|
||||
db.rollback()
|
||||
return [],0
|
||||
q = db.query(Student_Model).filter(Student_Model.delete_status == 0)
|
||||
if stu_id:
|
||||
q = q.filter(Student_Model.stu_id == stu_id)
|
||||
if stu_name and stu_name.strip() != "":
|
||||
q = q.filter(Student_Model.stu_name.like(f"%{stu_name}%"))
|
||||
if class_id:
|
||||
q = q.filter(Student_Model.class_id == class_id)
|
||||
total = q.count()
|
||||
r = q.offset((page - 1) * page_size).limit(page_size).all()
|
||||
return r, total
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
from fastapi import HTTPException,Depends
|
||||
from schema.teacher_schema import Teacher_RequestModel
|
||||
from model.all_model import *
|
||||
from fastapi import HTTPException
|
||||
from model.all_model import Teacher_Model
|
||||
from datetime import datetime
|
||||
|
||||
def add_teacher(teacher,session):
|
||||
try:
|
||||
print(teacher)
|
||||
x=Teacher_Model(**teacher)
|
||||
session.add(x)
|
||||
session.commit()
|
||||
return teacher
|
||||
except:
|
||||
session.rollback()
|
||||
# raise HTTPException(status_code=500,detail='添加异常!')
|
||||
return None
|
||||
|
||||
def get_teacher(id,session):
|
||||
@@ -36,7 +34,7 @@ def update_teacher(id:int,req,session):
|
||||
def delete_teacher(id:int,session):
|
||||
try:
|
||||
r=session.query(Teacher_Model).filter(Teacher_Model.teac_id==id,Teacher_Model.delete_status==0)\
|
||||
.update({'delete_status':1})
|
||||
.update({'delete_status':1,'delete_time':datetime.now()})
|
||||
except:
|
||||
session.rollback()
|
||||
return False
|
||||
|
||||
+10
-1
@@ -5,7 +5,16 @@ from api.statistics_api import StatisticsAPI
|
||||
from api.teacher_api import teacher_api
|
||||
from api.grade_api import gradeAPI
|
||||
from api.cla_api import claAPI
|
||||
app = FastAPI(title='沃林学⽣管理系统')
|
||||
|
||||
tags_metadata = [
|
||||
{"name": "教师基本信息管理模块"},
|
||||
{"name": "班级管理模块"},
|
||||
{"name": "学生基本信息管理模块"},
|
||||
{"name": "学生考核成绩管理模块"},
|
||||
{"name": "学生就业管理模块"},
|
||||
{"name": "统计分析模块"},
|
||||
]
|
||||
app = FastAPI(title='沃林学生管理系统',openapi_tags=tags_metadata)
|
||||
|
||||
app.include_router(StudentAPI)
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from sqlalchemy import DATETIME,Column,Integer,String,DATE,ForeignKey,Numeric
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
from sqlalchemy import DATETIME,Column,Integer,String,DATE,ForeignKey,Numeric,Date
|
||||
from datetime import datetime,date
|
||||
from util.database import Base,engine
|
||||
|
||||
class Student_Model(Base):
|
||||
@@ -23,6 +25,8 @@ class Student_Model(Base):
|
||||
|
||||
native_place=Column(String(200),comment='籍贯')
|
||||
|
||||
id_card=Column(String(18),unique=True,comment='身份证号')
|
||||
|
||||
birthday=Column(DATE,comment='生日')
|
||||
|
||||
school=Column(String(100),comment='毕业学校')
|
||||
@@ -47,16 +51,16 @@ class Student_Model(Base):
|
||||
delete_status = Column(
|
||||
Integer,default=0,comment='删除状态:0未删除,1已删除')
|
||||
|
||||
delete_time = Column(DATETIME,default=datetime.now,onupdate=datetime.now,comment='删除时间')
|
||||
delete_time = Column(DATETIME,comment='删除时间')
|
||||
|
||||
class ClassManagement(Base):
|
||||
__tablename__ = "wl_class"
|
||||
|
||||
class_id= Column(Integer, primary_key=True, autoincrement=True,comment='班级编号')
|
||||
|
||||
class_name = Column(String(100), comment='班级姓名')
|
||||
class_name = Column(String(100), comment='班级名字')
|
||||
|
||||
start_class_date = Column(DATE,comment='开课时间')
|
||||
start_class_date = Column(Date,default=date.today,comment='开课时间')
|
||||
|
||||
head_teacher_id= Column(Integer,ForeignKey('wl_teacher.teac_id'),comment='班主任')
|
||||
|
||||
@@ -68,7 +72,7 @@ class ClassManagement(Base):
|
||||
|
||||
delete_status = Column(Integer,default=0,comment='删除状态:0未删除,1已删除')
|
||||
|
||||
delete_time = Column(DATETIME,default=datetime.now,onupdate=datetime.now,comment='删除时间')
|
||||
delete_time = Column(DATETIME,comment='删除时间')
|
||||
|
||||
class Teacher_Model(Base):
|
||||
__tablename__ = 'wl_teacher'
|
||||
@@ -87,10 +91,9 @@ class Teacher_Model(Base):
|
||||
|
||||
update_date=Column(DATETIME,default=datetime.now,onupdate=datetime.now)
|
||||
|
||||
delete_status = Column(
|
||||
Integer,default=0,comment='删除状态:0未删除,1已删除')
|
||||
delete_status = Column(Integer,default=0,comment='删除状态:0未删除,1已删除')
|
||||
|
||||
delete_time = Column(DATETIME,default=datetime.now,onupdate=datetime.now,comment='删除时间')
|
||||
delete_time = Column(DATETIME,comment='删除时间')
|
||||
|
||||
class Employment_info(Base):
|
||||
__tablename__ = 'wl_employment'
|
||||
@@ -146,7 +149,7 @@ class Employment_info(Base):
|
||||
delete_status = Column(
|
||||
Integer,default=0,comment='删除状态:0未删除,1已删除')
|
||||
|
||||
delete_time = Column(DATETIME,default=datetime.now,onupdate=datetime.now,comment='删除时间')
|
||||
delete_time = Column(DATETIME,comment='删除时间')
|
||||
|
||||
class WlScore(Base):
|
||||
__tablename__ = 'wl_score'
|
||||
@@ -182,6 +185,6 @@ class WlScore(Base):
|
||||
delete_status = Column(
|
||||
Integer,default=0,comment='删除状态:0未删除,1已删除')
|
||||
|
||||
delete_time = Column(DATETIME,default=datetime.now,onupdate=datetime.now,comment='删除时间')
|
||||
|
||||
delete_time = Column(DATETIME,comment='删除时间')
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
@@ -1,40 +1,48 @@
|
||||
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
|
||||
employment_opening_date:date
|
||||
offer_issuance_date:date
|
||||
company_name:str
|
||||
company_address:str|None
|
||||
salary:float
|
||||
|
||||
@field_validator('stu_id')
|
||||
@classmethod
|
||||
def check_stu_id(cls,v):
|
||||
if v <= 0:
|
||||
raise ValueError('输入有误,学生ID必须大于0')
|
||||
return v
|
||||
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):
|
||||
if self.employment_opening_date > self.offer_issuance_date:
|
||||
raise ValueError('offer下发日期不能早于就业开放日期')
|
||||
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 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'
|
||||
emp_id:int
|
||||
stu_id: int
|
||||
stu_name:Optional[str] = None
|
||||
class_id:int
|
||||
email: str | None
|
||||
employment_opening_date: date
|
||||
offer_issuance_date: date
|
||||
company_name: str
|
||||
company_address: str | None
|
||||
salary: float
|
||||
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
|
||||
company_name:str|None = None
|
||||
company_address:str|None = None
|
||||
salary:float|None = None
|
||||
|
||||
@@ -1,21 +1,29 @@
|
||||
|
||||
from model.all_model import *
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
from fastapi import HTTPException,Form
|
||||
|
||||
|
||||
class GradeRequest(BaseModel):
|
||||
stu_id:int = Form(description="学生编号")
|
||||
exam_order:int = Form(description='考核序次')
|
||||
score:float = Form(description='成绩')
|
||||
stu_id:int = Field(description="学生编号")
|
||||
exam_order:int = Field(description='考核序次')
|
||||
score:float = Field(description='成绩')
|
||||
|
||||
@field_validator("score")
|
||||
def check_score(cls, v):
|
||||
if not (0 <= v <= 100):
|
||||
raise ValueError("成绩必须在0~100之间")
|
||||
return v
|
||||
|
||||
@field_validator("exam_order")
|
||||
def check_exam_order(cls, v):
|
||||
if v <= 0:
|
||||
raise ValueError("考核序次必须大于0")
|
||||
return v
|
||||
|
||||
class GradeResponse(BaseModel):
|
||||
code: int = 200
|
||||
detail: str = 'OK'
|
||||
score_id: float
|
||||
stu_id:int
|
||||
exam_order:int
|
||||
score:float
|
||||
|
||||
class GradeUpdate(BaseModel):
|
||||
exam_order: int | None = Form( description="考核序次")
|
||||
score: float | None = Form( description="成绩")
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from pydantic import BaseModel,Field
|
||||
from pydantic import BaseModel,field_serializer
|
||||
from datetime import date
|
||||
from typing import List, Optional
|
||||
|
||||
class AllStuResponse(BaseModel):
|
||||
all_cnt: int
|
||||
class_id: int
|
||||
gender: str | None
|
||||
cnt: int
|
||||
@@ -11,21 +11,61 @@ class AcgScoreResponse(BaseModel):
|
||||
class_id: int
|
||||
avg_score: float
|
||||
|
||||
class GetScoreResponse(BaseModel):
|
||||
code:int = 200
|
||||
detail:str = 'ok'
|
||||
score:float
|
||||
stu_name: str | None = None
|
||||
age: int | None = None
|
||||
gender: str | None = None
|
||||
native_place: str | None = None
|
||||
school: str | None = None
|
||||
major: str | None = None
|
||||
degree: str | None = None
|
||||
admission_date: date | None = None
|
||||
graduation_date: date | None = None
|
||||
progress: int = 0
|
||||
|
||||
@field_serializer('progress')
|
||||
def int_to_string(self, progress: int):
|
||||
d1 = {
|
||||
0: '学习中',
|
||||
1: '求职中',
|
||||
2: '已就业'
|
||||
}
|
||||
return d1.get(progress, '暂不明确')
|
||||
|
||||
class GetStuResponse(BaseModel):
|
||||
code:int = 200
|
||||
detail:str = 'ok'
|
||||
salary:float
|
||||
stu_name: str | None = None
|
||||
age: int | None = None
|
||||
gender: str | None = None
|
||||
native_place: str | None = None
|
||||
school: str | None = None
|
||||
major: str | None = None
|
||||
degree: str | None = None
|
||||
admission_date: date | None = None
|
||||
graduation_date: date | None = None
|
||||
progress: int = 0
|
||||
|
||||
@field_serializer('progress')
|
||||
def int_to_string(self, progress: int):
|
||||
d1 = {
|
||||
0: '学习中',
|
||||
1: '求职中',
|
||||
2: '已就业'
|
||||
}
|
||||
return d1.get(progress, '暂不明确')
|
||||
|
||||
class AvgDayResponse(BaseModel):
|
||||
class_id: int
|
||||
avg_days: str | None
|
||||
avg_days: float | None
|
||||
|
||||
class EmpRequest(BaseModel):
|
||||
class AllDayResponse(BaseModel):
|
||||
code:int = 200
|
||||
detail:str = 'ok'
|
||||
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]
|
||||
diff_days: int | None
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from datetime import date
|
||||
from typing import Self,List
|
||||
from pydantic import BaseModel, field_serializer, field_validator,model_validator
|
||||
from pydantic import BaseModel, field_serializer, field_validator,model_validator,ConfigDict
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ class StudentRequest(BaseModel):
|
||||
stu_name:str
|
||||
age:int |None = None
|
||||
gender:str |None = None
|
||||
id_card:str
|
||||
native_place:str |None = None
|
||||
birthday:date |None = None
|
||||
school:str |None = None
|
||||
@@ -30,31 +31,12 @@ class StudentRequest(BaseModel):
|
||||
raise ValueError ('入学日期不能晚于毕业日期')
|
||||
return self
|
||||
|
||||
|
||||
class StudentResponse(BaseModel):
|
||||
code:int = 200
|
||||
detail:str = 'ok'
|
||||
stu_name:str
|
||||
age:int
|
||||
gender:str
|
||||
progress:int
|
||||
|
||||
@field_serializer('progress')
|
||||
def int_to_string(cls,progress:int):
|
||||
d1 ={
|
||||
0:'学习中',
|
||||
1:'求职中',
|
||||
2:'已就业'
|
||||
}
|
||||
return d1.get(progress,'暂不明确')
|
||||
|
||||
class StugetResponse(BaseModel):
|
||||
code:int = 200
|
||||
detail:str = 'ok'
|
||||
class StuUpdateRequest(BaseModel):
|
||||
class_id: int | None = None
|
||||
stu_name: str | None = None
|
||||
age: int | None = None
|
||||
gender: str | None = None
|
||||
id_card: str | None = None
|
||||
native_place: str | None = None
|
||||
birthday: date | None = None
|
||||
school: str | None = None
|
||||
@@ -62,21 +44,65 @@ class StugetResponse(BaseModel):
|
||||
degree: str | None = None
|
||||
admission_date: date | None = None
|
||||
graduation_date: date | None = None
|
||||
progress: int = 0
|
||||
progress: int | None = None
|
||||
|
||||
@field_validator('age')
|
||||
@classmethod
|
||||
def check_age(cls, v):
|
||||
if v is not None and v < 0:
|
||||
raise ValueError('年龄不能为负数')
|
||||
return v
|
||||
|
||||
@model_validator(mode='after')
|
||||
def check_admission_graduation(self) -> Self:
|
||||
if self.admission_date and self.graduation_date:
|
||||
if self.admission_date > self.graduation_date:
|
||||
raise ValueError('入学日期不能晚于毕业日期')
|
||||
return self
|
||||
|
||||
class StugetResponse(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
code:int = 200
|
||||
detail:str = 'ok'
|
||||
stu_id:int | None = None
|
||||
class_id: int | None = None
|
||||
stu_name: str | None = None
|
||||
age: int | None = None
|
||||
gender: str | None = None
|
||||
id_card: str | None = None
|
||||
native_place: str | None = None
|
||||
birthday: date | None = None
|
||||
school: str | None = None
|
||||
major: str | None = None
|
||||
degree: str | None = None
|
||||
admission_date: date | None = None
|
||||
graduation_date: date | None = None
|
||||
progress: int
|
||||
|
||||
@field_serializer('progress')
|
||||
def int_to_string(cls, progress: int):
|
||||
def progress_to_label(self, progress):
|
||||
d1 = {
|
||||
0: '学习中',
|
||||
1: '求职中',
|
||||
2: '已就业'
|
||||
}
|
||||
return d1.get(progress, '暂不明确')
|
||||
try:
|
||||
return d1.get(int(progress), '暂不明确')
|
||||
except (TypeError, ValueError):
|
||||
return progress
|
||||
|
||||
class StudentPageResponse(BaseModel):
|
||||
class StuPageResponse(BaseModel):
|
||||
code: int = 200
|
||||
detail: str = "ok"
|
||||
page: int
|
||||
page_size: int
|
||||
totals: int
|
||||
data: List[StugetResponse]
|
||||
data: List[StugetResponse]
|
||||
|
||||
class StudelResponse(BaseModel):
|
||||
code: int = 200
|
||||
detail: str = "ok"
|
||||
totals: int
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user