nb
This commit is contained in:
@@ -7,11 +7,15 @@ 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)):
|
def get_grade(stu_id: int,db=Depends(get_db)):
|
||||||
try:
|
try:
|
||||||
res=get_grade_dao(stu_id,db)
|
res=get_grade_dao(stu_id,db)
|
||||||
return res
|
return {
|
||||||
|
"code": 200,
|
||||||
|
"detail": "查询成功",
|
||||||
|
"data": res
|
||||||
|
}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500,detail=f'数据库查询异常:{str(e)}')
|
raise HTTPException(status_code=500,detail=f'数据库查询异常:{str(e)}')
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,26 @@ def get_score_by_stu_exam_order_dao(stu_id:str,exam_order:int,db):
|
|||||||
|
|
||||||
def get_grade_dao( stu_id:int , db):
|
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:
|
if r1:
|
||||||
|
data_list = []
|
||||||
return r1
|
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:
|
else:
|
||||||
raise HTTPException(status_code=404,detail="学生不存在")
|
raise HTTPException(status_code=404,detail="学生不存在")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user