整体bug修改。
This commit is contained in:
@@ -16,7 +16,6 @@ def add_class(cla:ClassCreate,db=Depends(get_db)):
|
|||||||
raise HTTPException(status_code=400,detail='新增失败,班级已存在')
|
raise HTTPException(status_code=400,detail='新增失败,班级已存在')
|
||||||
return ClassResponse(detail='新增成功',totals=1,data=c_dict)
|
return ClassResponse(detail='新增成功',totals=1,data=c_dict)
|
||||||
|
|
||||||
|
|
||||||
#更新接口
|
#更新接口
|
||||||
@class_api.put("/{class_id}",summary='修改班级信息')
|
@class_api.put("/{class_id}",summary='修改班级信息')
|
||||||
def update_class(class_id:int
|
def update_class(class_id:int
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ def add_class_dao(c,db):
|
|||||||
db.refresh(c1)
|
db.refresh(c1)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
#更新班级信息
|
#更新班级信息
|
||||||
def update_class_dao(cid,update_data,db):
|
def update_class_dao(cid,update_data,db):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ DB_HOST = os.getenv("DB_HOST", "localhost")
|
|||||||
DB_PORT = os.getenv("DB_PORT", "3306")
|
DB_PORT = os.getenv("DB_PORT", "3306")
|
||||||
DB_NAME = os.getenv("DB_NAME", "student_manage_system")
|
DB_NAME = os.getenv("DB_NAME", "student_manage_system")
|
||||||
|
|
||||||
class_management_url = "mysql+pymysql://root:123456@localhost:3306/student_manage_system?charset=utf8mb4"
|
class_management_url = f"mysql+pymysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}?charset=utf8mb4"
|
||||||
|
|
||||||
engine = create_engine(class_management_url)
|
engine = create_engine(class_management_url)
|
||||||
SessionLocal = sessionmaker(bind=engine,autocommit=False, autoflush=False)
|
SessionLocal = sessionmaker(bind=engine,autocommit=False, autoflush=False)
|
||||||
|
|||||||
+11
-7
@@ -14,15 +14,19 @@ def get_scores(score:ScoreQuery=Depends(),db=Depends(get_db)):
|
|||||||
return aa
|
return aa
|
||||||
raise HTTPException(status_code=404,detail='不存在')
|
raise HTTPException(status_code=404,detail='不存在')
|
||||||
|
|
||||||
@score_api.post('/Score',response_model=ScoreResponse
|
@score_api.post('/Score'
|
||||||
,summary='成绩添加')
|
,summary='成绩添加')
|
||||||
def add_scores(score:ScoreRequest=Depends(),db=Depends(get_db)):
|
def add_scores(score:ScoreRequest=Depends(),db=Depends(get_db)):
|
||||||
a = score.model_dump()
|
# try:
|
||||||
# print(a,type(a))
|
a = score.model_dump()
|
||||||
aa = add_scores_dao(b=a,db=db)
|
# print(a,type(a))
|
||||||
if aa:
|
aa = add_scores_dao(b=a,db=db)
|
||||||
return ScoreResponse(data=a)
|
if aa:
|
||||||
raise HTTPException(status_code=500,detail='不可以')
|
return aa
|
||||||
|
# except ValueError as e:
|
||||||
|
# raise HTTPException(status_code=400, detail="数据库已有该成绩")
|
||||||
|
# except Exception as e:
|
||||||
|
# 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,t_subject:int,db=Depends(get_db)):
|
def update_scores(score:ScoreRequest,sid:int,cid:int,num:int,t_subject:int,db=Depends(get_db)):
|
||||||
|
|||||||
+37
-9
@@ -1,3 +1,5 @@
|
|||||||
|
from zipfile import sizeCentralDir
|
||||||
|
|
||||||
from scores.model.score_model import Score
|
from scores.model.score_model import Score
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@@ -28,19 +30,45 @@ 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.t_subject==b['t_subject']).all()
|
aa = db.query(Score).filter(Score.sid == b['sid']
|
||||||
|
,Score.cid == b['cid']
|
||||||
|
,Score.t_subject == b['t_subject']
|
||||||
|
,Score.is_deleted == 0
|
||||||
|
).first()
|
||||||
if aa:
|
if aa:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
else:
|
|
||||||
z = Score(**b)
|
deleted = db.query(Score).filter(
|
||||||
db.add(z)
|
Score.sid == b['sid'],
|
||||||
|
Score.cid == b['cid'],
|
||||||
|
Score.t_subject == b['t_subject'],
|
||||||
|
Score.is_deleted == 1
|
||||||
|
).first()
|
||||||
|
|
||||||
|
if deleted.is_deleted and deleted.is_deleted == True:
|
||||||
|
deleted.sid = b['sid']
|
||||||
|
deleted.cid = b['cid']
|
||||||
|
deleted.num = b['num']
|
||||||
|
deleted.score = b['score']
|
||||||
|
deleted.t_subject = b['t_subject']
|
||||||
|
|
||||||
|
deleted.create_date = datetime.now()
|
||||||
|
deleted.update_date = datetime.now()
|
||||||
|
deleted.is_deleted = False
|
||||||
|
deleted.deleted_date = None
|
||||||
|
db.commit()
|
||||||
|
db.refresh(deleted) # 从数据库再拉一次数据
|
||||||
|
return b
|
||||||
|
z = Score(**b)
|
||||||
|
db.add(z)
|
||||||
|
db.commit()
|
||||||
|
db.refresh(z)
|
||||||
|
return z
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
db.rollback()
|
db.rollback()
|
||||||
print(e)
|
# print(e)
|
||||||
return False
|
raise e
|
||||||
else:
|
|
||||||
db.commit()
|
|
||||||
return True
|
|
||||||
|
|
||||||
def update_scores_dao(sid:int,cid:int,num:int,t_subject:int,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:
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel,Field
|
||||||
|
|
||||||
class ScoreRequest(BaseModel):
|
class ScoreRequest(BaseModel):
|
||||||
# id:int
|
# id:int
|
||||||
sid:int
|
sid:int = Field(ge=1, le=20, description="学生ID:1-20")
|
||||||
cid:int
|
cid:int = Field(ge=1, le=8, description="班级ID:1-8")
|
||||||
num:int
|
num:int
|
||||||
score:int
|
score:int
|
||||||
t_subject:int
|
t_subject:int = Field(ge=1, le=6, description="科目ID:1-6")
|
||||||
|
|
||||||
class ScoreQuery(BaseModel):
|
class ScoreQuery(BaseModel):
|
||||||
id:int|None = None
|
id:int|None = None
|
||||||
|
|||||||
Reference in New Issue
Block a user