Compare commits
13
Commits
geyuan
...
ba2155643b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba2155643b | ||
|
|
a571243415 | ||
|
|
dae4d74e31 | ||
|
|
ff03df7d8d | ||
|
|
133cb530c7 | ||
|
|
98d08cff64 | ||
|
|
180e01e36d | ||
|
|
65bf147fd4 | ||
|
|
9c39c69fa1 | ||
|
|
b068ad6b29 | ||
|
|
9bc57bcbba | ||
|
|
d4d1d4fe2d | ||
|
|
5881afd5cc |
@@ -1,7 +0,0 @@
|
||||
# .env(放项目根目录,每个人自己建,不提交 Git)
|
||||
# 用来修改数据库账户密码
|
||||
DB_USER=root
|
||||
DB_PASSWORD=420821
|
||||
DB_HOST=localhost
|
||||
DB_PORT=3306
|
||||
DB_NAME=student_manage_system
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
from fastapi import APIRouter , Depends , HTTPException
|
||||
from StatCalc.dao.statcalc_dao import *
|
||||
from StatCalc.model.statcalc_model import *
|
||||
from StatCalc.schema.statcalc_request import *
|
||||
from databases import *
|
||||
|
||||
statcalc_api = APIRouter()
|
||||
|
||||
@statcalc_api.get("/statcalc"
|
||||
@statcalc_api.get("/statcalc/age"
|
||||
,summary='人员信息查询'
|
||||
,description=f'查询所有超过30岁的学员的信息。'
|
||||
)
|
||||
@@ -18,95 +17,49 @@ def get_students(db=Depends(get_db)):
|
||||
return result
|
||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||
|
||||
@statcalc_api.get("/statcalc"
|
||||
@statcalc_api.get("/statcalc/students"
|
||||
,summary='人数统计'
|
||||
,description=f'统计每个班级的人数以及男生女生的人数。'
|
||||
)
|
||||
def get_students(g:get_student_dao = Depends()
|
||||
def get_students(headcount:get_student_dao
|
||||
,db=Depends(get_db)
|
||||
):
|
||||
result = get_class_count( g=g , db=db )
|
||||
result = get_class_count( g=headcount , db=db )
|
||||
if result:
|
||||
return result
|
||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||
|
||||
@statcalc_api.get("/statcalc"
|
||||
@statcalc_api.get("/statcalc/scores"
|
||||
,summary='80分以上成绩学生信息查询'
|
||||
,description=f'查询每次考试成绩都在80分以上的学生的编号,姓名和成绩。'
|
||||
)
|
||||
def get_students(db=Depends(get_db)):
|
||||
result = get_student_dao( db=db )
|
||||
result = get_score_80( db=db )
|
||||
if result:
|
||||
return result
|
||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||
|
||||
@statcalc_api.get("/statcalc"
|
||||
@statcalc_api.get("/statcalc/fail"
|
||||
,summary='不及格成绩查询'
|
||||
,description=f'查询有两次以上不及格的学生的姓名,班级和不及格成绩。'
|
||||
)
|
||||
def get_students( stu:StudentsQuery = Depends()
|
||||
, db=Depends(get_db)
|
||||
):
|
||||
s_dict = stu.model_dump(exclude_unset=True) # 没值的不要
|
||||
result = get_student_dao( s=s_dict , db=db )
|
||||
def get_students( db=Depends(get_db) ):
|
||||
result = get_score_80( db=db )
|
||||
if result:
|
||||
return result
|
||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||
|
||||
@statcalc_api.get("/statcalc"
|
||||
,summary='班级平均分查询'
|
||||
,description=f'统计每次考试每个班级的平均分,按照从高到低排序。'
|
||||
)
|
||||
def get_students( stu:StudentsQuery = Depends()
|
||||
, db=Depends(get_db)
|
||||
):
|
||||
s_dict = stu.model_dump(exclude_unset=True) # 没值的不要
|
||||
result = get_student_dao( s=s_dict , db=db )
|
||||
if result:
|
||||
return result
|
||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||
|
||||
@statcalc_api.get("/statcalc"
|
||||
,summary='排名前五的学生信息'
|
||||
,description=f'统计就业薪资最高的前五名学生的姓名,班级和就业时间,就业公司。'
|
||||
)
|
||||
def get_students( stu:StudentsQuery = Depends()
|
||||
, db=Depends(get_db)
|
||||
):
|
||||
s_dict = stu.model_dump(exclude_unset=True) # 没值的不要
|
||||
result = get_student_dao( s=s_dict , db=db )
|
||||
if result:
|
||||
return result
|
||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||
|
||||
@statcalc_api.get("/statcalc"
|
||||
,summary='就业时长统计'
|
||||
,description=f'统计每个学生的就业时长(offer下发时间-就业开放时间)。'
|
||||
)
|
||||
def get_students( stu:StudentsQuery = Depends()
|
||||
, db=Depends(get_db)
|
||||
):
|
||||
s_dict = stu.model_dump(exclude_unset=True) # 没值的不要
|
||||
result = get_student_dao( s=s_dict , db=db )
|
||||
if result:
|
||||
return result
|
||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||
|
||||
@statcalc_api.get("/statcalc"
|
||||
,summary='班级的平均就业时长'
|
||||
,description=f'统计每个班级的平均就业时长(只统计进入就业阶段的学生,也就是有就业开放时间)'
|
||||
)
|
||||
def get_students( stu:StudentsQuery = Depends()
|
||||
, db=Depends(get_db)
|
||||
):
|
||||
s_dict = stu.model_dump(exclude_unset=True) # 没值的不要
|
||||
result = get_student_dao( s=s_dict , db=db )
|
||||
if result:
|
||||
return result
|
||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||
@statcalc_api.get('/statcalc/average', summary='统计每次考试每个班级的平均分')
|
||||
def get_class_avg(db=Depends(get_db)):
|
||||
result = get_class_avg_dao(db)
|
||||
if not result:
|
||||
return []
|
||||
return result
|
||||
|
||||
|
||||
@CURD.get('/Top5',summary='就业薪资Top5')
|
||||
from stu_jiuye.model import *
|
||||
|
||||
@statcalc_api.get('/statcalc/top',summary='就业薪资Top5')
|
||||
def salarytop5(db=Depends(get_db)):
|
||||
q = db.query(Employments,Company.employment_company) \
|
||||
.join(Company, Employments.company_id == Company.id) \
|
||||
@@ -115,16 +68,19 @@ def salarytop5(db=Depends(get_db)):
|
||||
.limit(5) .all()
|
||||
return [{'学生姓名':i.sname,'学生班级编号':i.class_num,'就业时间':i.offer_recived_time,'公司':employment_company} for i,employment_company in q]
|
||||
|
||||
@CURD.get('/worktime',summary='学生就业时常')
|
||||
@statcalc_api.get('/statcalc/job',summary='学生就业时长')
|
||||
def worktime(db=Depends(get_db)):
|
||||
q = db.query(Employments)\
|
||||
.filter(Employments.is_deleted==0)\
|
||||
.all()
|
||||
|
||||
return [{'学生姓名':i.sname,'就业时常':f'{i.offer_recived_time-i.employment_open_time}' if i.offer_recived_time and i.employment_open_time else '暂无数据'} for i in q]
|
||||
return [
|
||||
{'学生姓名':i.sname
|
||||
,'就业时常':f'{i.offer_recived_time-i.employment_open_time}'
|
||||
if i.offer_recived_time and i.employment_open_time else '暂无数据'} for i in q
|
||||
]
|
||||
|
||||
|
||||
@CURD.get('/avgworktime',summary='学生平均就业时常')
|
||||
@statcalc_api.get('/statcalc/avgjob',summary='学生平均就业时长')
|
||||
def avgworktime(db=Depends(get_db)):
|
||||
q = db.query(Employments)\
|
||||
.filter(Employments.employment_open_time.isnot(None)
|
||||
@@ -139,3 +95,4 @@ def avgworktime(db=Depends(get_db)):
|
||||
'人数': len(q),
|
||||
'平均就业时常(天)': round(avg_days, 2)
|
||||
}
|
||||
|
||||
|
||||
@@ -39,10 +39,38 @@ def get_class_count(g , db):
|
||||
from scores.model.score_model import Score
|
||||
|
||||
def get_score_80(db):
|
||||
q = (db.query(Score)
|
||||
.filter(Score.score>=80)
|
||||
.all())
|
||||
sq = ( db.query(Students.id)
|
||||
.join(Score, Score.sid == Students.id)
|
||||
.filer(Score.score < 80 )
|
||||
.group_by(Students.id)
|
||||
.having(func.count(Score.id) > 2 )
|
||||
.sq()
|
||||
)
|
||||
|
||||
q = ( db.query(Students.name,ClassInfo.name,Score.score )
|
||||
.join(ClassInfo, ClassInfo.id == Students.class_id)
|
||||
.join(Score, Score.sid == Students.id)
|
||||
.filer(Students.id.in_(sq),Score.score < 80)
|
||||
.all()
|
||||
)
|
||||
return q
|
||||
|
||||
def get_class_avg_dao(db):
|
||||
results = (db.query(Score.num,
|
||||
Score.cid,
|
||||
ClassInfo.name.label("class_name"),
|
||||
func.avg(Score.score).label("avg_score"))
|
||||
.join(ClassInfo, Score.cid == ClassInfo.id)
|
||||
.filter(Score.is_deleted == 0)
|
||||
.group_by(Score.num, Score.cid, ClassInfo.name)
|
||||
.order_by(func.avg(Score.score).desc())
|
||||
.all())
|
||||
|
||||
return [ {"num": r.num,
|
||||
"cid": r.cid,
|
||||
"class_name": r.class_name,
|
||||
"avg_score": round(float(r.avg_score), 2),}
|
||||
for r in results]
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from fastapi import FastAPI,APIRouter
|
||||
from StatCalc.api.statcalc_api import statcalc_api
|
||||
from databases import *
|
||||
from StatCalc.model import statcalc_model
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
StatCalc_API = APIRouter()
|
||||
|
||||
@@ -4,7 +4,7 @@ from pydantic import BaseModel , Field , field_validator
|
||||
from datetime import datetime
|
||||
import enum
|
||||
|
||||
class get_student_dao(enum.Enum):
|
||||
class get_student_dao(str , enum.Enum):
|
||||
get_class = "班级人数"
|
||||
get_sex = "男女人数"
|
||||
get_class_sex = "班级中男女人数"
|
||||
|
||||
+3
-3
@@ -9,11 +9,11 @@ Teachers_API.include_router(tea_api)
|
||||
|
||||
# 自测接口
|
||||
app = FastAPI()
|
||||
app.include_router(tea_api,tags=["老师"])
|
||||
|
||||
Base.metadata.create_all(engine1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.include_router(tea_api, tags=["老师"])
|
||||
Base.metadata.create_all(engine1)
|
||||
|
||||
import uvicorn
|
||||
uvicorn.run('main:app', host='0.0.0.0', port=57000)
|
||||
"""
|
||||
|
||||
@@ -7,24 +7,52 @@ from class_management.schema.class_management_request import ClassCreate, ClassR
|
||||
class_api = APIRouter(prefix='/classes')
|
||||
# ,tags=['班级管理模块']
|
||||
|
||||
|
||||
#新增接口
|
||||
@class_api.post("",summary='新增班级')
|
||||
def add_class(cla:ClassCreate,db=Depends(get_db)):
|
||||
c_dict = cla.model_dump()
|
||||
r = add_class_dao(c=c_dict,db=db)
|
||||
if not r:
|
||||
raise HTTPException(status_code=500,detail='服务器繁忙,请稍后添加!')
|
||||
return ClassResponse(totals=1,data=c_dict)
|
||||
res = add_class_dao(c=c_dict,db=db)
|
||||
if not res:
|
||||
raise HTTPException(status_code=400,detail='新增失败,班级已存在')
|
||||
return ClassResponse(detail='新增成功',totals=1,data=c_dict)
|
||||
|
||||
|
||||
@class_api.get('/{id}',summary='根据id查询班级')
|
||||
def get_one_class(id:int,db=Depends(get_db)):
|
||||
res = get_class_dao(c={'id':id},db=db)
|
||||
#更新接口
|
||||
@class_api.put("/{class_id}",summary='修改班级信息')
|
||||
def update_class(class_id:int
|
||||
,update_info:ClassUpdate
|
||||
,db=Depends(get_db)
|
||||
):
|
||||
update_dict=update_info.model_dump(exclude_unset=True)
|
||||
if not update_dict:
|
||||
raise HTTPException(status_code=400, detail="没有传入要修改的字段")
|
||||
row_count = update_class_dao(cid=class_id, update_data=update_dict, db=db)
|
||||
if not row_count :
|
||||
raise HTTPException(status_code=404, detail="班级不存在,修改失败")
|
||||
return ClassResponse(detail="修改成功", data={"id": class_id})
|
||||
|
||||
|
||||
#删除接口
|
||||
@class_api.delete('/{class_id}',summary='逻辑删除班级')
|
||||
def remove_class(class_id:int,db=Depends(get_db)):
|
||||
del_rows = delete_class_dao(cid = class_id,db=db)
|
||||
if not del_rows:
|
||||
raise HTTPException(status_code=404, detail="班级不存在,删除失败")
|
||||
return ClassResponse(detail='删除成功',data={'id':class_id})
|
||||
|
||||
|
||||
|
||||
#单条查询接口
|
||||
@class_api.get('/{class_id}',summary='根据id查询班级')
|
||||
def get_one_class(class_id:int,db=Depends(get_db)):
|
||||
res = get_class_dao(c={'id':class_id},db=db)
|
||||
if not res:
|
||||
raise HTTPException(status_code=404, detail="该班级不存在或已删除")
|
||||
return ClassResponse(totals=1,data=res[0])
|
||||
|
||||
@class_api.get('',summary='多字段查询班级')
|
||||
|
||||
#分类查询
|
||||
@class_api.get('',summary='多字段分页查询班级')
|
||||
def get_some_classes( num:str|None = Query(None,description='班级编号')
|
||||
,name:str|None = Query(None,description='班级名称')
|
||||
,head_teacher_id:int|None = Query(None,description='班主任')
|
||||
@@ -33,10 +61,9 @@ def get_some_classes( num:str|None = Query(None,description='班级编号')
|
||||
,class_start_time:date|None = Query(None, description="开班日期,格式YYYY‑MM‑DD")
|
||||
,class_end_time: date|None = Query(None, description="结课日期,格式YYYY‑MM‑DD")
|
||||
,page:int = Query(1,ge=1,description='页码,从1开始')
|
||||
,page_size:int = Query(5,ge=1,le=50,description='每页信息条数')
|
||||
,page_size:int = Query(5,ge=1,le=20,description='每页信息条数')
|
||||
,db=Depends(get_db)
|
||||
):
|
||||
|
||||
c_dict = {
|
||||
'num': num,
|
||||
'name': name,
|
||||
@@ -52,7 +79,7 @@ def get_some_classes( num:str|None = Query(None,description='班级编号')
|
||||
res = get_class_dao(c=c_dict,db=db)
|
||||
total = len(res)
|
||||
|
||||
#内存分页
|
||||
#分页
|
||||
start_index = (page-1)*page_size
|
||||
page_data = res[start_index:start_index + page_size]
|
||||
|
||||
@@ -61,23 +88,3 @@ def get_some_classes( num:str|None = Query(None,description='班级编号')
|
||||
|
||||
|
||||
|
||||
@class_api.put("/{class_id}",summary='修改班级信息')
|
||||
def update_class(class_id:int
|
||||
,update_info:ClassUpdate
|
||||
,db=Depends(get_db)
|
||||
):
|
||||
update_dict=update_info.model_dump(exclude_unset=True)
|
||||
if not update_dict:
|
||||
raise HTTPException(status_code=400, detail="没有传入要修改的字段")
|
||||
row_count = update_class_dao(cid=class_id, update_data=update_dict, db=db)
|
||||
if row_count <= 0:
|
||||
raise HTTPException(status_code=404, detail="班级不存在,修改失败")
|
||||
return ClassResponse(detail="修改成功", data={"class_id": id})
|
||||
|
||||
|
||||
@class_api.delete('/{id}',summary='逻辑删除班级')
|
||||
def remove_class(id:int,db=Depends(get_db)):
|
||||
del_rows = delete_class_dao(id,db)
|
||||
if del_rows <= 0:
|
||||
raise HTTPException(status_code=404, detail="班级不存在,删除失败")
|
||||
return ClassResponse(detail='删除成功',data={'id':id})
|
||||
|
||||
@@ -1,6 +1,46 @@
|
||||
from class_management.model.class_management_model import ClassInfo
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
#新增班级
|
||||
def add_class_dao(c,db):
|
||||
try:
|
||||
c1 = ClassInfo(**c)
|
||||
db.add(c1)
|
||||
except:
|
||||
db.rollback()
|
||||
return False
|
||||
else:
|
||||
db.commit()
|
||||
return True
|
||||
|
||||
|
||||
#更新班级信息
|
||||
def update_class_dao(cid,update_data,db):
|
||||
try:
|
||||
rows = db.query(ClassInfo)\
|
||||
.filter(ClassInfo.id == cid
|
||||
,ClassInfo.is_delete==0)\
|
||||
.update(update_data)
|
||||
except :
|
||||
db.rollback()
|
||||
return False
|
||||
else:
|
||||
db.commit()
|
||||
return rows
|
||||
|
||||
|
||||
#删除(逻辑删除)
|
||||
def delete_class_dao(cid,db):
|
||||
try:
|
||||
rows = db.query(ClassInfo)\
|
||||
.filter(ClassInfo.id == cid,ClassInfo.is_delete==0)\
|
||||
.update({'is_delete':1})
|
||||
db.commit()
|
||||
return rows
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
print('删除失败',e)
|
||||
return 0
|
||||
|
||||
|
||||
#查询
|
||||
@@ -34,64 +74,6 @@ def get_class_dao(c:dict,db:Session) :
|
||||
,'tutor_teacher_id':i.tutor_teacher_id
|
||||
,'class_start_time':i.class_start_time
|
||||
,'class_end_time':i.class_end_time
|
||||
,"is_delete": i.is_delete
|
||||
,"create_time": i.create_time
|
||||
,"update_time": i.update_time
|
||||
} for i in res
|
||||
]
|
||||
|
||||
|
||||
#新增班级
|
||||
def add_class_dao(c:dict,db:Session):
|
||||
try:
|
||||
exist_class = db.query(ClassInfo)\
|
||||
.filter(ClassInfo.name == c['name']
|
||||
,ClassInfo.is_delete == 0)\
|
||||
.first()
|
||||
if exist_class:
|
||||
msg = '班级名称已存在'
|
||||
print(msg)
|
||||
return (False,msg)
|
||||
c1 = ClassInfo(**c)
|
||||
db.add(c1)
|
||||
db.commit()
|
||||
db.refresh(c1)
|
||||
return (True,None)
|
||||
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
err_msg = f'数据库异常:{str(e)}'
|
||||
print(err_msg)
|
||||
return (False,err_msg)
|
||||
|
||||
|
||||
#修改
|
||||
def update_class_dao(cid:int,update_data,db):
|
||||
try:
|
||||
rows = db.query(ClassInfo)\
|
||||
.filter(ClassInfo.id == cid
|
||||
,ClassInfo.is_delete==0)\
|
||||
.update(update_data)
|
||||
db.commit()
|
||||
return rows
|
||||
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
print(f"update_class_dao异常:{e}")
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
#删除(逻辑删除)
|
||||
def delete_class_dao(cid,db):
|
||||
try:
|
||||
rows = db.query(ClassInfo)\
|
||||
.filter(ClassInfo.id == cid,ClassInfo.is_delete==0)\
|
||||
.update({'is_delete':1})
|
||||
db.commit()
|
||||
return rows
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
print(f"delete_class_dao异常:{e}")
|
||||
rows = 0
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ SessionLocal = sessionmaker(bind=engine,autocommit=False, autoflush=False)
|
||||
Base = declarative_base()
|
||||
|
||||
# 获取数据库会话依赖
|
||||
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try :
|
||||
|
||||
@@ -7,14 +7,12 @@ from class_management.database import Base,engine
|
||||
Classes_API = APIRouter()
|
||||
Classes_API.include_router(class_api)
|
||||
|
||||
# 自测接口
|
||||
app = FastAPI()
|
||||
|
||||
app.include_router(class_api)
|
||||
|
||||
|
||||
|
||||
if __name__ =='__main__':
|
||||
# 自测接口
|
||||
app = FastAPI()
|
||||
|
||||
app.include_router(class_api)
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
import uvicorn
|
||||
|
||||
@@ -14,6 +14,7 @@ class ClassInfo(Base_all):
|
||||
)
|
||||
num = Column(String(50)
|
||||
,nullable=False
|
||||
,unique=True
|
||||
,comment='班级编号'
|
||||
)
|
||||
name = Column(String(50)
|
||||
@@ -21,26 +22,18 @@ class ClassInfo(Base_all):
|
||||
,comment='班级名称'
|
||||
)
|
||||
head_teacher_id = Column(Integer
|
||||
# ,ForeignKey('teacher.id')
|
||||
,ForeignKey('teacher.id')
|
||||
,comment='班主任编号'
|
||||
)
|
||||
|
||||
coach_teacher_id = Column(Integer
|
||||
# ,ForeignKey('teacher.id')
|
||||
,ForeignKey('teacher.id')
|
||||
,comment='授课老师编号'
|
||||
)
|
||||
tutor_teacher_id = Column(Integer
|
||||
# ,ForeignKey('teacher.id')
|
||||
,ForeignKey('teacher.id')
|
||||
,comment='助教老师编号'
|
||||
)
|
||||
# class_teacher = Column(String(50)
|
||||
# ,nullable=False
|
||||
# ,comment='班主任'
|
||||
# )
|
||||
# class_lecturer = Column(String(50)
|
||||
# ,nullable=False
|
||||
# ,comment='授课老师'
|
||||
# )
|
||||
class_start_time = Column(Date
|
||||
,comment='开班日期'
|
||||
)
|
||||
|
||||
@@ -12,17 +12,14 @@ class ClassBase(BaseModel):
|
||||
class_start_time:date|None = Field(None,description='开班日期 YYYY‑MM‑DD')
|
||||
class_end_time:date|None = Field(None,description='结课日期 YYYY‑MM‑DD')
|
||||
|
||||
#新增班级请求体:num,name必填,其余继承父类ClassBase
|
||||
#新增班级请求体:继承父类ClassBase
|
||||
class ClassCreate(ClassBase):
|
||||
num:str = Field(...,description='班级编号')
|
||||
name:str = Field(...,description='班级名称')
|
||||
pass
|
||||
|
||||
#修改班级请求体,继承ClassBase,全部字段可选,传哪个就更新哪个
|
||||
class ClassUpdate(ClassBase):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class ClassResponse(BaseModel):
|
||||
code:int = 200
|
||||
detail:str = 'OK'
|
||||
|
||||
@@ -4,7 +4,7 @@ from scores.main import Scores_API
|
||||
from stu_jiuye.main import Shtudent_Jiuye
|
||||
from students.main import Students_API
|
||||
from Teachers.main import Teachers_API
|
||||
# from StatCalc.main import StatCalc_API
|
||||
from StatCalc.main import StatCalc_API
|
||||
from databases import *
|
||||
app = FastAPI(title="学生管理系统")
|
||||
|
||||
@@ -14,12 +14,12 @@ app.include_router(Scores_API,tags=["scores"])
|
||||
app.include_router(Shtudent_Jiuye,tags=["Employments"])
|
||||
app.include_router(Students_API,tags=["students"])
|
||||
app.include_router(Teachers_API,tags=["teachers"])
|
||||
# app.include_router(StatCalc_API,tags=["StatCalc"])
|
||||
app.include_router(StatCalc_API,tags=["StatCalc"])
|
||||
|
||||
|
||||
Base_all.metadata.create_all(bind=engine_all)
|
||||
|
||||
if __name__ == "__main__":
|
||||
Base_all.metadata.create_all(bind=engine_all)
|
||||
|
||||
def main():
|
||||
print("Hello from student-manage-system!")
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ def update_scores(score:ScoreRequest,sid:int,cid:int,num:int,t_subject:int,db=De
|
||||
@score_api.delete('/Score',summary='成绩删除',description=f'查询条件为学号,班级号,考试科目,然后进行删除')
|
||||
def delete_scores(sid:int,cid:int,t_subject:int,db=Depends(get_db)):
|
||||
aaa = delete_scores_dao(sid,cid,t_subject,db)
|
||||
if aaa==1:
|
||||
if aaa==-1:
|
||||
raise HTTPException(status_code=500,detail='删除失败')
|
||||
if aaa==0:
|
||||
raise HTTPException(status_code=404,detail='记录不存在')
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from scores.database import get_db
|
||||
from scores.dao.statistic_dao import get_top_students_dao,get_failing_students_dao,get_class_avg_dao
|
||||
|
||||
statistic_api = APIRouter()
|
||||
|
||||
@statistic_api.get('/statistic', summary='查询每次考试都在80分以上的学生')
|
||||
def get_top_students(db=Depends(get_db)):
|
||||
q = get_top_students_dao(db)
|
||||
if not q:
|
||||
return []
|
||||
return q
|
||||
|
||||
@statistic_api.get('/Score/failing', summary='查询两次以上不及格的学生')
|
||||
def get_failing_students(db=Depends(get_db)):
|
||||
result = get_failing_students_dao(db)
|
||||
if not result:
|
||||
return []
|
||||
return result
|
||||
|
||||
@statistic_api.get('/Score/class-avg', summary='统计每次考试每个班级的平均分')
|
||||
def get_class_avg(db=Depends(get_db)):
|
||||
result = get_class_avg_dao(db)
|
||||
if not result:
|
||||
return []
|
||||
return result
|
||||
@@ -19,7 +19,7 @@ def get_scores_dao(s,db):
|
||||
if aa:
|
||||
return [{'id':i.id,'sid':i.sid
|
||||
,'cid':i.cid,'num':i.num
|
||||
,'score': i.score,'t_subject':i.tsub
|
||||
,'score': i.score,'t_subject':i.t_subject
|
||||
,'create_date':i.create_date,'update_date':i.update_date
|
||||
,'is_deleted': i.is_deleted,'deleted_date': i.deleted_date
|
||||
}for i in aa]
|
||||
@@ -28,8 +28,7 @@ def get_scores_dao(s,db):
|
||||
|
||||
def add_scores_dao(b,db):
|
||||
try:
|
||||
aa = db.query(Score).filter(Score.sid==b['sid']
|
||||
,Score.t_subject==b['t_subject']).all()
|
||||
aa = db.query(Score).filter(Score.t_subject==b['t_subject']).all()
|
||||
if aa:
|
||||
raise ValueError
|
||||
else:
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
from sqlalchemy import func
|
||||
from scores.model.score_model import Score
|
||||
from students.model.students_model import Students
|
||||
from class_management.model.class_management_model import ClassInfo
|
||||
|
||||
def get_top_students_dao(db):
|
||||
top_sids = (db.query(Score.sid)
|
||||
.filter(Score.is_deleted == 0)
|
||||
.group_by(Score.sid, Score.num)
|
||||
.having(func.min(Score.score) >= 80)
|
||||
.subquery() )
|
||||
|
||||
results = (db.query(Students.id,
|
||||
Students.name,
|
||||
Score.num,
|
||||
Score.t_subject,
|
||||
Score.score,)
|
||||
.join(Score, Students.id == Score.sid)
|
||||
.filter( Score.sid.in_(top_sids),
|
||||
Score.is_deleted == 0,)
|
||||
.order_by(Students.id, Score.num)
|
||||
.all())
|
||||
|
||||
return [{"sid": r.sid,
|
||||
"name": r.name,
|
||||
"score": r.score,}
|
||||
for r in results]
|
||||
|
||||
|
||||
def get_failing_students_dao(db):
|
||||
failing_sids = (db.query(Score.sid)
|
||||
.filter(Score.score < 60,
|
||||
Score.is_deleted == 0,)
|
||||
.group_by(Score.sid)
|
||||
.having(func.count() >= 2)
|
||||
.subquery())
|
||||
|
||||
results = (db.query(
|
||||
Students.id,
|
||||
Students.name,
|
||||
ClassInfo.name.label("class_name"),
|
||||
Score.num,
|
||||
Score.t_subject,
|
||||
Score.score,)
|
||||
.join(Score, Students.id == Score.sid)
|
||||
.join(ClassInfo, Score.cid == ClassInfo.id)
|
||||
.filter(Score.sid.in_(failing_sids),
|
||||
Score.score < 60,
|
||||
Score.is_deleted == 0,)
|
||||
.order_by(ClassInfo.id, Score.num)
|
||||
.all())
|
||||
|
||||
return [{"sid": r.sid,
|
||||
"name": r.name,
|
||||
"class_name": r.class_name,
|
||||
"num": r.num,
|
||||
"t_subject": r.tsub,
|
||||
"score": r.score,}
|
||||
for r in results]
|
||||
|
||||
|
||||
|
||||
def get_class_avg_dao(db):
|
||||
results = (db.query(Score.num,
|
||||
Score.cid,
|
||||
ClassInfo.name.label("class_name"),
|
||||
func.avg(Score.score).label("avg_score"))
|
||||
.join(ClassInfo, Score.cid == ClassInfo.id)
|
||||
.filter(Score.is_deleted == 0)
|
||||
.group_by(Score.num, Score.cid, ClassInfo.name)
|
||||
.order_by(func.avg(Score.score).desc())
|
||||
.all())
|
||||
|
||||
return [ {"num": r.num,
|
||||
"cid": r.cid,
|
||||
"class_name": r.class_name,
|
||||
"avg_score": round(float(r.avg_score), 2),}
|
||||
for r in results]
|
||||
+7
-3
@@ -1,17 +1,21 @@
|
||||
from fastapi import FastAPI,APIRouter
|
||||
from scores.api.score_api import score_api
|
||||
from scores.database import engine,Base
|
||||
from scores.api.statistic_api import statistic_api
|
||||
|
||||
# 合并接口
|
||||
Scores_API = APIRouter()
|
||||
Scores_API.include_router(score_api)
|
||||
|
||||
# 自测接口
|
||||
app = FastAPI(tags=['成绩'],title='成绩管理系统')
|
||||
app = FastAPI(tags=['成绩'], title='成绩管理系统')
|
||||
app.include_router(score_api)
|
||||
app.include_router(statistic_api)
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
import uvicorn
|
||||
uvicorn.run('main:app',host='127.0.0.1',port=12346)
|
||||
uvicorn.run('scores.main:app',host='127.0.0.1',port=12346)
|
||||
+3
-6
@@ -8,15 +8,12 @@ Shtudent_Jiuye = APIRouter()
|
||||
Shtudent_Jiuye.include_router(CURD)
|
||||
|
||||
# 自测接口
|
||||
|
||||
|
||||
app=FastAPI()
|
||||
Base.metadata.create_all(engine)
|
||||
app.include_router(CURD,tags=['就业管理系统'])
|
||||
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
app.include_router(CURD, tags=['就业管理系统'])
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
import uvicorn
|
||||
uvicorn.run('main:app', host='127.0.0.1', port=12395)
|
||||
|
||||
|
||||
+4
-3
@@ -8,6 +8,7 @@ from contextlib import asynccontextmanager
|
||||
Students_API = APIRouter()
|
||||
Students_API.include_router(s_api)
|
||||
|
||||
|
||||
# 自测接口
|
||||
@asynccontextmanager
|
||||
async def S_Fastapi(app: FastAPI):
|
||||
@@ -15,11 +16,11 @@ async def S_Fastapi(app: FastAPI):
|
||||
yield
|
||||
engine1.dispose()
|
||||
|
||||
app = FastAPI(title="学生管理系统",lifespan=S_Fastapi) # 这里必须把上面写的加上
|
||||
app.include_router(s_api,tags=["students"])
|
||||
|
||||
app = FastAPI(title="学生管理系统", lifespan=S_Fastapi) # 这里必须把上面写的加上
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.include_router(s_api, tags=["students"])
|
||||
|
||||
def main():
|
||||
print("Hello from student-manage-system!")
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from pydantic import BaseModel , Field , field_validator
|
||||
from datetime import datetime
|
||||
import enum
|
||||
|
||||
class SexEnum(enum.Enum):
|
||||
class SexEnum(str , enum.Enum):
|
||||
m = '男'
|
||||
f = '女'
|
||||
|
||||
@@ -27,7 +27,7 @@ class StudentsQuery(BaseModel):
|
||||
# 额外字段
|
||||
phone:str | None = None
|
||||
|
||||
class EducationEnum(enum.Enum):
|
||||
class EducationEnum(str , enum.Enum):
|
||||
z = '专科'
|
||||
ben = '本科'
|
||||
s = '硕士'
|
||||
|
||||
Reference in New Issue
Block a user