2026-09-21 14:06:18 +08:00
|
|
|
from fastapi import Depends,HTTPException
|
2026-09-21 12:50:10 +08:00
|
|
|
|
|
|
|
|
from util.database import get_db
|
|
|
|
|
|
2026-09-21 16:28:55 +08:00
|
|
|
from model.all_model import *
|
2026-09-21 12:50:10 +08:00
|
|
|
|
|
|
|
|
|
2026-09-21 16:53:39 +08:00
|
|
|
def get_grade_dao( stu_id:int , db):
|
2026-09-21 14:06:18 +08:00
|
|
|
|
|
|
|
|
r1 =db.query(WlScore).filter(WlScore.stu_id == stu_id,WlScore.delete_status == 0).all()
|
|
|
|
|
if r1:
|
2026-09-21 21:40:48 +08:00
|
|
|
|
2026-09-21 14:06:18 +08:00
|
|
|
return r1
|
|
|
|
|
else:
|
|
|
|
|
raise HTTPException(status_code=404,detail="学生不存在")
|
2026-09-21 16:28:55 +08:00
|
|
|
|
2026-09-21 16:53:39 +08:00
|
|
|
def add_grade_dao(g,db):
|
2026-09-21 16:28:55 +08:00
|
|
|
try:
|
2026-09-21 16:53:39 +08:00
|
|
|
o1 = WlScore(**g)
|
2026-09-21 16:28:55 +08:00
|
|
|
db.add(o1)
|
|
|
|
|
db.commit()
|
2026-09-21 17:08:46 +08:00
|
|
|
return o1
|
|
|
|
|
except Exception:
|
|
|
|
|
db.rollback()
|
2026-09-21 21:40:48 +08:00
|
|
|
raise HTTPException(status_code=500,detail="学生添加失败")
|
2026-09-21 20:03:17 +08:00
|
|
|
|
|
|
|
|
def update_grade_dao(score_id:int, update_data, db):
|
|
|
|
|
try:
|
|
|
|
|
rows = db.query(WlScore).filter(
|
2026-09-21 21:40:48 +08:00
|
|
|
WlScore.score_id == score_id,
|
2026-09-21 20:03:17 +08:00
|
|
|
WlScore.delete_status == 0
|
|
|
|
|
).update(update_data)
|
2026-09-21 21:40:48 +08:00
|
|
|
except Exception:
|
2026-09-21 20:03:17 +08:00
|
|
|
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
|