Compare commits
21
Commits
acd04828a1
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79da6dc3a0 | ||
|
|
1af01f94ee | ||
|
|
fd1f9f71de | ||
|
|
4849e73771 | ||
|
|
4e99cfd3b1 | ||
|
|
739c8887fc | ||
|
|
30ae0af56e | ||
|
|
5b10d0e868 | ||
|
|
6ff3d5974d | ||
|
|
de67f868cb | ||
|
|
a132eb47b2 | ||
|
|
847b908c4f | ||
|
|
664741e52f | ||
|
|
7a25cf6f68 | ||
|
|
0a7fd06d83 | ||
|
|
40a6d79b37 | ||
|
|
da935f93bd | ||
|
|
92b98226d8 | ||
|
|
e13ace8616 | ||
|
|
46faa300a8 | ||
|
|
26429d6b6f |
@@ -7,15 +7,15 @@ from typing import Optional
|
||||
emp_api = APIRouter(tags=['学生就业管理模块'])
|
||||
|
||||
@emp_api.get('/employment/class/{class_id}',response_model=list[EmploymentResponse],summary='获取班级学生就业信息')
|
||||
def get_emp_info2(class_id: Optional[int]=Path(description='班级编号')
|
||||
def get_emp_info1(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
|
||||
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_info3(stu_id:int = Path(description='学生编号')
|
||||
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='最高工资')
|
||||
|
||||
@@ -6,7 +6,7 @@ from util.database import get_db
|
||||
|
||||
StatisticsAPI = APIRouter(tags=['统计分析模块'])
|
||||
|
||||
@StatisticsAPI.get("/age",response_model=list[StudentResponse],summary='根据年龄查询学生信息')
|
||||
@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
|
||||
@@ -45,3 +45,8 @@ def get_emp(db=Depends(get_db)):
|
||||
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
|
||||
|
||||
@@ -19,7 +19,7 @@ def get_students(stu_id:int|None=None
|
||||
,page=page
|
||||
,page_size=page_size
|
||||
,db=db)
|
||||
return StudentPageResponse(page=page,
|
||||
return StuPageResponse(page=page,
|
||||
page_size=page_size,
|
||||
totals=total,
|
||||
data=r)
|
||||
@@ -46,15 +46,13 @@ def update_students(stu_id:int
|
||||
if not d:
|
||||
raise HTTPException(status_code=400, detail='更新内容不能为空')
|
||||
r = update_student_dao( stu_id=stu_id,update_data=d,db=db )
|
||||
if r == 'conflict':
|
||||
raise HTTPException(status_code=409, detail = '身份证号已被其他学生占用')
|
||||
if r == 'error':
|
||||
raise HTTPException(status_code=500, detail='更新失败,请稍后重试')
|
||||
if not r:
|
||||
raise HTTPException(status_code=404, detail='学生不存在或已被删除,更新失败')
|
||||
return {'code':200,'totals':r,'detail':'更新成功'}
|
||||
|
||||
@StudentAPI.delete('/students/{stu_id}',response_model= StugetResponse,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 )
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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):
|
||||
@@ -34,7 +35,7 @@ def update_class_dao(id:int,req:claRequest,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="删除异常,请重新核对之后删除!")
|
||||
|
||||
@@ -38,8 +38,11 @@ def select_all(db):
|
||||
"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="查询异常")
|
||||
|
||||
@@ -66,7 +69,10 @@ def select_score(min_score,max_score,db):
|
||||
db = db.filter(WlScore.score >= min_score)
|
||||
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:
|
||||
@@ -80,7 +86,11 @@ def select_avg_score(db):
|
||||
.filter(WlScore.delete_status==0,Student_Model.delete_status == 0)\
|
||||
.group_by(Student_Model.class_id)\
|
||||
.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="查询异常")
|
||||
|
||||
@@ -102,7 +112,11 @@ def select_salary(db):
|
||||
.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="查询异常")
|
||||
|
||||
@@ -123,19 +137,27 @@ def select_avg_days(db):
|
||||
Employment_info.offer_issuance_date.isnot(None),)\
|
||||
.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_days(db):
|
||||
try:
|
||||
l2 =db.query(Employment_info.stu_id
|
||||
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()
|
||||
return l2
|
||||
if not l1:
|
||||
raise HTTPException(status_code=404, detail="没有数据")
|
||||
return l1
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500, detail="查询异常")
|
||||
|
||||
@@ -156,7 +178,19 @@ def classify_salary(db):
|
||||
c+=1
|
||||
else:
|
||||
d+=1
|
||||
return {'5k以下': a, '5k-10k': b, '10k-15k': c, '15k': d}
|
||||
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='统计异常!')
|
||||
|
||||
|
||||
@@ -38,15 +38,6 @@ def delete_student_dao(stu_id, db):
|
||||
def update_student_dao(stu_id, update_data, db):
|
||||
if not update_data:
|
||||
return 0
|
||||
id_card = update_data.get('id_card')
|
||||
if id_card:
|
||||
conflict = (db.query(Student_Model)
|
||||
.filter(Student_Model.id_card == id_card,
|
||||
Student_Model.stu_id != stu_id,
|
||||
Student_Model.delete_status == 0)
|
||||
.first())
|
||||
if conflict:
|
||||
return 'conflict'
|
||||
try:
|
||||
rows = (db.query(Student_Model)
|
||||
.filter(Student_Model.stu_id == stu_id,
|
||||
@@ -59,7 +50,6 @@ def update_student_dao(stu_id, update_data, db):
|
||||
except Exception:
|
||||
db.rollback()
|
||||
return 'error'
|
||||
|
||||
return rows
|
||||
|
||||
def get_student_dao(stu_id:Optional[int]
|
||||
|
||||
@@ -10,7 +10,6 @@ def add_teacher(teacher,session):
|
||||
return teacher
|
||||
except:
|
||||
session.rollback()
|
||||
# raise HTTPException(status_code=500,detail='添加异常!')
|
||||
return None
|
||||
|
||||
def get_teacher(id,session):
|
||||
|
||||
@@ -14,7 +14,7 @@ tags_metadata = [
|
||||
{"name": "学生就业管理模块"},
|
||||
{"name": "统计分析模块"},
|
||||
]
|
||||
app = FastAPI(title='沃林学⽣管理系统',openapi_tags=tags_metadata)
|
||||
app = FastAPI(title='沃林学生管理系统',openapi_tags=tags_metadata)
|
||||
|
||||
app.include_router(StudentAPI)
|
||||
|
||||
|
||||
@@ -99,4 +99,10 @@ class StuPageResponse(BaseModel):
|
||||
totals: int
|
||||
data: List[StugetResponse]
|
||||
|
||||
class StudelResponse(BaseModel):
|
||||
code: int = 200
|
||||
detail: str = "ok"
|
||||
totals: int
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user