全部更新确认,无基础错误,各自测试各自端口bug,暂时没有自动导入数据。
This commit is contained in:
@@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
from fastapi import APIRouter , Depends , HTTPException
|
from fastapi import APIRouter , Depends , HTTPException
|
||||||
from StatCalc.dao.statcalc_dao import *
|
from StatCalc.dao.statcalc_dao import *
|
||||||
from StatCalc.model.statcalc_model import *
|
|
||||||
from StatCalc.schema.statcalc_request import *
|
from StatCalc.schema.statcalc_request import *
|
||||||
from databases import *
|
from databases import *
|
||||||
|
|
||||||
statcalc_api = APIRouter()
|
statcalc_api = APIRouter()
|
||||||
|
|
||||||
@statcalc_api.get("/statcalc"
|
@statcalc_api.get("/statcalc/age"
|
||||||
,summary='人员信息查询'
|
,summary='人员信息查询'
|
||||||
,description=f'查询所有超过30岁的学员的信息。'
|
,description=f'查询所有超过30岁的学员的信息。'
|
||||||
)
|
)
|
||||||
@@ -18,19 +17,19 @@ def get_students(db=Depends(get_db)):
|
|||||||
return result
|
return result
|
||||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||||
|
|
||||||
@statcalc_api.get("/statcalc"
|
@statcalc_api.get("/statcalc/students"
|
||||||
,summary='人数统计'
|
,summary='人数统计'
|
||||||
,description=f'统计每个班级的人数以及男生女生的人数。'
|
,description=f'统计每个班级的人数以及男生女生的人数。'
|
||||||
)
|
)
|
||||||
def get_students(g:get_student_dao = Depends()
|
def get_students(headcount:get_student_dao
|
||||||
,db=Depends(get_db)
|
,db=Depends(get_db)
|
||||||
):
|
):
|
||||||
result = get_class_count( g=g , db=db )
|
result = get_class_count( g=headcount , db=db )
|
||||||
if result:
|
if result:
|
||||||
return result
|
return result
|
||||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||||
|
|
||||||
@statcalc_api.get("/statcalc"
|
@statcalc_api.get("/statcalc/scores"
|
||||||
,summary='80分以上成绩学生信息查询'
|
,summary='80分以上成绩学生信息查询'
|
||||||
,description=f'查询每次考试成绩都在80分以上的学生的编号,姓名和成绩。'
|
,description=f'查询每次考试成绩都在80分以上的学生的编号,姓名和成绩。'
|
||||||
)
|
)
|
||||||
@@ -40,7 +39,7 @@ def get_students(db=Depends(get_db)):
|
|||||||
return result
|
return result
|
||||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||||
|
|
||||||
@statcalc_api.get("/statcalc"
|
@statcalc_api.get("/statcalc/fail"
|
||||||
,summary='不及格成绩查询'
|
,summary='不及格成绩查询'
|
||||||
,description=f'查询有两次以上不及格的学生的姓名,班级和不及格成绩。'
|
,description=f'查询有两次以上不及格的学生的姓名,班级和不及格成绩。'
|
||||||
)
|
)
|
||||||
@@ -50,23 +49,17 @@ def get_students( db=Depends(get_db) ):
|
|||||||
return result
|
return result
|
||||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||||
|
|
||||||
@statcalc_api.get("/statcalc"
|
@statcalc_api.get('/statcalc/average', summary='统计每次考试每个班级的平均分')
|
||||||
,summary='班级平均分查询'
|
def get_class_avg(db=Depends(get_db)):
|
||||||
,description=f'统计每次考试每个班级的平均分,按照从高到低排序。'
|
result = get_class_avg_dao(db)
|
||||||
)
|
if not result:
|
||||||
def get_students( stu:StudentsQuery = Depends()
|
return []
|
||||||
, db=Depends(get_db)
|
return result
|
||||||
):
|
|
||||||
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="没有找到符合条件的学生")
|
|
||||||
|
|
||||||
|
|
||||||
from stu_jiuye.model import *
|
from stu_jiuye.model import *
|
||||||
|
|
||||||
@statcalc_api.get('/Top5',summary='就业薪资Top5')
|
@statcalc_api.get('/statcalc/top',summary='就业薪资Top5')
|
||||||
def salarytop5(db=Depends(get_db)):
|
def salarytop5(db=Depends(get_db)):
|
||||||
q = db.query(Employments,Company.employment_company) \
|
q = db.query(Employments,Company.employment_company) \
|
||||||
.join(Company, Employments.company_id == Company.id) \
|
.join(Company, Employments.company_id == Company.id) \
|
||||||
@@ -75,7 +68,7 @@ def salarytop5(db=Depends(get_db)):
|
|||||||
.limit(5) .all()
|
.limit(5) .all()
|
||||||
return [{'学生姓名':i.sname,'学生班级编号':i.class_num,'就业时间':i.offer_recived_time,'公司':employment_company} for i,employment_company in q]
|
return [{'学生姓名':i.sname,'学生班级编号':i.class_num,'就业时间':i.offer_recived_time,'公司':employment_company} for i,employment_company in q]
|
||||||
|
|
||||||
@statcalc_api.get('/worktime',summary='学生就业时长')
|
@statcalc_api.get('/statcalc/job',summary='学生就业时长')
|
||||||
def worktime(db=Depends(get_db)):
|
def worktime(db=Depends(get_db)):
|
||||||
q = db.query(Employments)\
|
q = db.query(Employments)\
|
||||||
.filter(Employments.is_deleted==0)\
|
.filter(Employments.is_deleted==0)\
|
||||||
@@ -87,7 +80,7 @@ def worktime(db=Depends(get_db)):
|
|||||||
if i.offer_recived_time and i.employment_open_time else '暂无数据'} for i in q
|
if i.offer_recived_time and i.employment_open_time else '暂无数据'} for i in q
|
||||||
]
|
]
|
||||||
|
|
||||||
@statcalc_api.get('/avgworktime',summary='学生平均就业时长')
|
@statcalc_api.get('/statcalc/avgjob',summary='学生平均就业时长')
|
||||||
def avgworktime(db=Depends(get_db)):
|
def avgworktime(db=Depends(get_db)):
|
||||||
q = db.query(Employments)\
|
q = db.query(Employments)\
|
||||||
.filter(Employments.employment_open_time.isnot(None)
|
.filter(Employments.employment_open_time.isnot(None)
|
||||||
|
|||||||
@@ -55,7 +55,22 @@ def get_score_80(db):
|
|||||||
)
|
)
|
||||||
return q
|
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]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from pydantic import BaseModel , Field , field_validator
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import enum
|
import enum
|
||||||
|
|
||||||
class get_student_dao(enum.Enum):
|
class get_student_dao(str , enum.Enum):
|
||||||
get_class = "班级人数"
|
get_class = "班级人数"
|
||||||
get_sex = "男女人数"
|
get_sex = "男女人数"
|
||||||
get_class_sex = "班级中男女人数"
|
get_class_sex = "班级中男女人数"
|
||||||
|
|||||||
+1
-1
@@ -9,9 +9,9 @@ Teachers_API.include_router(tea_api)
|
|||||||
|
|
||||||
# 自测接口
|
# 自测接口
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
app.include_router(tea_api,tags=["老师"])
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
app.include_router(tea_api, tags=["老师"])
|
||||||
Base.metadata.create_all(engine1)
|
Base.metadata.create_all(engine1)
|
||||||
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from scores.main import Scores_API
|
|||||||
from stu_jiuye.main import Shtudent_Jiuye
|
from stu_jiuye.main import Shtudent_Jiuye
|
||||||
from students.main import Students_API
|
from students.main import Students_API
|
||||||
from Teachers.main import Teachers_API
|
from Teachers.main import Teachers_API
|
||||||
# from StatCalc.main import StatCalc_API
|
from StatCalc.main import StatCalc_API
|
||||||
from databases import *
|
from databases import *
|
||||||
app = FastAPI(title="学生管理系统")
|
app = FastAPI(title="学生管理系统")
|
||||||
|
|
||||||
@@ -14,8 +14,7 @@ app.include_router(Scores_API,tags=["scores"])
|
|||||||
app.include_router(Shtudent_Jiuye,tags=["Employments"])
|
app.include_router(Shtudent_Jiuye,tags=["Employments"])
|
||||||
app.include_router(Students_API,tags=["students"])
|
app.include_router(Students_API,tags=["students"])
|
||||||
app.include_router(Teachers_API,tags=["teachers"])
|
app.include_router(Teachers_API,tags=["teachers"])
|
||||||
# app.include_router(StatCalc_API,tags=["StatCalc"])
|
app.include_router(StatCalc_API,tags=["StatCalc"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ def get_failing_students_dao(db):
|
|||||||
.subquery())
|
.subquery())
|
||||||
|
|
||||||
results = (db.query(
|
results = (db.query(
|
||||||
Students.sid,
|
Students.id,
|
||||||
Students.name,
|
Students.name,
|
||||||
ClassInfo.name.label("class_name"),
|
ClassInfo.name.label("class_name"),
|
||||||
Score.num,
|
Score.num,
|
||||||
|
|||||||
+1
-5
@@ -8,14 +8,10 @@ Shtudent_Jiuye = APIRouter()
|
|||||||
Shtudent_Jiuye.include_router(CURD)
|
Shtudent_Jiuye.include_router(CURD)
|
||||||
|
|
||||||
# 自测接口
|
# 自测接口
|
||||||
|
|
||||||
|
|
||||||
app=FastAPI()
|
app=FastAPI()
|
||||||
|
|
||||||
app.include_router(CURD,tags=['就业管理系统'])
|
|
||||||
|
|
||||||
|
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
|
app.include_router(CURD, tags=['就业管理系统'])
|
||||||
Base.metadata.create_all(engine)
|
Base.metadata.create_all(engine)
|
||||||
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|||||||
+9
-9
@@ -9,16 +9,16 @@ Students_API = APIRouter()
|
|||||||
Students_API.include_router(s_api)
|
Students_API.include_router(s_api)
|
||||||
|
|
||||||
|
|
||||||
|
# 自测接口
|
||||||
|
@asynccontextmanager
|
||||||
|
async def S_Fastapi(app: FastAPI):
|
||||||
|
Base.metadata.create_all(engine1)
|
||||||
|
yield
|
||||||
|
engine1.dispose()
|
||||||
|
|
||||||
|
app = FastAPI(title="学生管理系统", lifespan=S_Fastapi) # 这里必须把上面写的加上
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 自测接口
|
|
||||||
@asynccontextmanager
|
|
||||||
async def S_Fastapi(app: FastAPI):
|
|
||||||
Base.metadata.create_all(engine1)
|
|
||||||
yield
|
|
||||||
engine1.dispose()
|
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI(title="学生管理系统", lifespan=S_Fastapi) # 这里必须把上面写的加上
|
|
||||||
app.include_router(s_api, tags=["students"])
|
app.include_router(s_api, tags=["students"])
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from pydantic import BaseModel , Field , field_validator
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import enum
|
import enum
|
||||||
|
|
||||||
class SexEnum(enum.Enum):
|
class SexEnum(str , enum.Enum):
|
||||||
m = '男'
|
m = '男'
|
||||||
f = '女'
|
f = '女'
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ class StudentsQuery(BaseModel):
|
|||||||
# 额外字段
|
# 额外字段
|
||||||
phone:str | None = None
|
phone:str | None = None
|
||||||
|
|
||||||
class EducationEnum(enum.Enum):
|
class EducationEnum(str , enum.Enum):
|
||||||
z = '专科'
|
z = '专科'
|
||||||
ben = '本科'
|
ben = '本科'
|
||||||
s = '硕士'
|
s = '硕士'
|
||||||
|
|||||||
Reference in New Issue
Block a user