Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1558103dfa | ||
|
|
5c671020d7 |
@@ -25,9 +25,9 @@ def add_scores(score:ScoreRequest=Depends(),db=Depends(get_db)):
|
||||
raise HTTPException(status_code=500,detail='不可以')
|
||||
|
||||
@score_api.put('/Score',summary='成绩更新',description=f'查询条件为学号,班级号,考试序次,考试科目,然后更改这位同学此次科目的成绩')
|
||||
def update_scores(score:ScoreRequest,sid:int,cid:int,num:int,tsub:str,db=Depends(get_db)):
|
||||
a = score.model_dump(exclude_unset=True,exclude={'id','sid','cid','num','tsub'})
|
||||
aa = update_scores_dao(sid = sid,cid = cid,num = num,tsub = tsub,update_data = a,db=db)
|
||||
def update_scores(score:ScoreRequest,sid:int,cid:int,num:int,t_subject:int,db=Depends(get_db)):
|
||||
a = score.model_dump(exclude_unset=True,exclude={'id','sid','cid','num','t_subject'})
|
||||
aa = update_scores_dao(sid = sid,cid = cid,num = num,t_subject = t_subject,update_data = a,db=db)
|
||||
if aa==-1:
|
||||
raise HTTPException(status_code=500,detail='没有更新')
|
||||
if aa==0:
|
||||
@@ -35,8 +35,8 @@ def update_scores(score:ScoreRequest,sid:int,cid:int,num:int,tsub:str,db=Depends
|
||||
return {'message':'更新成功','data':a}
|
||||
|
||||
@score_api.delete('/Score',summary='成绩删除',description=f'查询条件为学号,班级号,考试科目,然后进行删除')
|
||||
def delete_scores(sid:int,cid:int,tsub:str,db=Depends(get_db)):
|
||||
aaa = delete_scores_dao(sid,cid,tsub,db)
|
||||
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:
|
||||
raise HTTPException(status_code=500,detail='删除失败')
|
||||
if aaa==0:
|
||||
|
||||
@@ -13,13 +13,13 @@ def get_scores_dao(s,db):
|
||||
ab = ab.filter(Score.num==s.get('num'))
|
||||
if s.get('score'):
|
||||
ab = ab.filter(Score.score==s.get('score'))
|
||||
if s.get('tsub'):
|
||||
ab = ab.filter(Score.tsub==s.get('tsub'))
|
||||
if s.get('t_subject'):
|
||||
ab = ab.filter(Score.t_subject==s.get('t_subject'))
|
||||
aa = ab.all()
|
||||
if aa:
|
||||
return [{'id':i.id,'sid':i.sid
|
||||
,'cid':i.cid,'num':i.num
|
||||
,'score': i.score,'tsub':i.tsub
|
||||
,'score': i.score,'t_subject':i.tsub
|
||||
,'create_date':i.create_date,'update_date':i.update_date
|
||||
,'is_deleted': i.is_deleted,'deleted_date': i.deleted_date
|
||||
}for i in aa]
|
||||
@@ -29,7 +29,7 @@ def get_scores_dao(s,db):
|
||||
def add_scores_dao(b,db):
|
||||
try:
|
||||
aa = db.query(Score).filter(Score.sid==b['sid']
|
||||
,Score.tsub==b['tsub']).all()
|
||||
,Score.t_subject==b['t_subject']).all()
|
||||
if aa:
|
||||
raise ValueError
|
||||
else:
|
||||
@@ -43,7 +43,7 @@ def add_scores_dao(b,db):
|
||||
db.commit()
|
||||
return True
|
||||
|
||||
def update_scores_dao(sid:int,cid:int,num:int,tsub:str,update_data:dict,db):
|
||||
def update_scores_dao(sid:int,cid:int,num:int,t_subject:int,update_data:dict,db):
|
||||
if not update_data:
|
||||
return 0
|
||||
update_data['update_date']=datetime.now()
|
||||
@@ -51,7 +51,7 @@ def update_scores_dao(sid:int,cid:int,num:int,tsub:str,update_data:dict,db):
|
||||
aa = db.query(Score).filter(Score.sid == sid
|
||||
,Score.cid == cid
|
||||
,Score.num == num
|
||||
,Score.tsub == tsub ).update(update_data)
|
||||
,Score.t_subject == t_subject ).update(update_data)
|
||||
db.commit()
|
||||
return aa
|
||||
except Exception :
|
||||
@@ -59,11 +59,11 @@ def update_scores_dao(sid:int,cid:int,num:int,tsub:str,update_data:dict,db):
|
||||
return -1
|
||||
|
||||
|
||||
def delete_scores_dao(sid:int,cid:int,tsub:str,db):
|
||||
def delete_scores_dao(sid:int,cid:int,t_subject:int,db):
|
||||
try:
|
||||
aaa = db.query(Score).filter(Score.sid ==sid
|
||||
,Score.cid == cid
|
||||
,Score.tsub == tsub
|
||||
,Score.t_subject == t_subject
|
||||
,Score.is_deleted==0
|
||||
).update({'is_deleted':1
|
||||
,'deleted_date':datetime.now()})
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
from scores.database import Base
|
||||
from datetime import datetime
|
||||
from sqlalchemy import DateTime,Column,Integer,String,Float,ForeignKey
|
||||
|
||||
|
||||
|
||||
class Score(Base):
|
||||
__tablename__='scores'
|
||||
id = Column(Integer
|
||||
@@ -20,8 +23,8 @@ class Score(Base):
|
||||
,comment ='考试序次'
|
||||
)
|
||||
score = Column(Integer,nullable = False)
|
||||
tsub = Column(String(100)
|
||||
, ForeignKey('subject.id')
|
||||
t_subject = Column(Integer
|
||||
,ForeignKey('subject.id')
|
||||
,nullable = False
|
||||
)
|
||||
create_date = Column(DateTime
|
||||
|
||||
@@ -6,7 +6,7 @@ class ScoreRequest(BaseModel):
|
||||
cid:int
|
||||
num:int
|
||||
score:int
|
||||
tsub:str
|
||||
t_subject:int
|
||||
|
||||
class ScoreQuery(BaseModel):
|
||||
id:int|None = None
|
||||
@@ -14,7 +14,7 @@ class ScoreQuery(BaseModel):
|
||||
cid:int|None = None
|
||||
num:int|None = None
|
||||
score:int|None = None
|
||||
tsub:str|None = None
|
||||
t_subject:int|None = None
|
||||
|
||||
class ScoreResponse(BaseModel):
|
||||
code:int = 200
|
||||
|
||||
Reference in New Issue
Block a user