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