62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
from fastapi import Depends,HTTPException
|
|
|
|
from util.database import get_db
|
|
|
|
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
|
|
).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()
|
|
|
|
def get_grade_dao( stu_id:int , db):
|
|
|
|
r1 =db.query(WlScore).filter(WlScore.stu_id == stu_id,WlScore.delete_status == 0).all()
|
|
if r1:
|
|
|
|
return r1
|
|
else:
|
|
raise HTTPException(status_code=404,detail="学生不存在")
|
|
|
|
def add_grade_dao(g,db):
|
|
try:
|
|
o1 = WlScore(**g)
|
|
db.add(o1)
|
|
db.commit()
|
|
return o1
|
|
except Exception:
|
|
db.rollback()
|
|
raise HTTPException(status_code=500,detail="学生添加失败")
|
|
|
|
def update_grade_dao(score_id:int, update_data, db):
|
|
try:
|
|
rows = db.query(WlScore).filter(
|
|
WlScore.score_id == score_id,
|
|
WlScore.delete_status == 0
|
|
).update(update_data)
|
|
except Exception:
|
|
db.rollback()
|
|
return False
|
|
else:
|
|
db.commit()
|
|
return rows
|
|
|
|
def delete_grade_dao(stu_id:int,db):
|
|
try:
|
|
rows = db.query(WlScore).filter(
|
|
WlScore.stu_id == stu_id,
|
|
WlScore.delete_status == 0
|
|
).update({'delete_status':1})
|
|
except:
|
|
db.rollback()
|
|
return False
|
|
else:
|
|
db.commit()
|
|
return rows
|