第五版_完整
This commit is contained in:
+30
-5
@@ -3,6 +3,7 @@
|
||||
from fastapi import HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from model import Teacher
|
||||
from model.cls_mgmt_model import ClsMgmt
|
||||
from scheme.cls_mgmt_scheme import ClsMgmtResponse, ClsMgmtCreate
|
||||
from typing import Optional, List
|
||||
@@ -36,7 +37,9 @@ class ClsMgmtDAO:
|
||||
根据主键 ID 获取单个班级
|
||||
:return: 班级对象或 None
|
||||
"""
|
||||
return db.query(ClsMgmt).filter(ClsMgmt.id == class_id,ClsMgmt.is_deleted == 0).first()
|
||||
return (db.query(ClsMgmt)
|
||||
.filter(ClsMgmt.id == class_id,ClsMgmt.is_deleted == 0)
|
||||
.first())
|
||||
|
||||
|
||||
|
||||
@@ -68,6 +71,18 @@ class ClsMgmtDAO:
|
||||
id 根据开课时间自动生成,不再自增
|
||||
"""
|
||||
class_id = ClsMgmtDAO.generate_class_id(cls_data.cls_start_date)
|
||||
head_tea = db.query(Teacher).filter(
|
||||
Teacher.type == "班主任",
|
||||
Teacher.id == cls_data.head_tea_id
|
||||
).first()
|
||||
lecturer = db.query(Teacher).filter(
|
||||
Teacher.type == "授课老师",
|
||||
Teacher.id == cls_data.lecturer_id
|
||||
).first()
|
||||
if not head_tea:
|
||||
raise HTTPException(status_code=404, detail=f"班主任id{cls_data.head_tea_id}不存在")
|
||||
elif not lecturer:
|
||||
raise HTTPException(status_code=404, detail=f"授课老师id{cls_data.lecturer_id}不存在")
|
||||
new_cls = ClsMgmt(
|
||||
id=class_id, # 手动赋值班级id
|
||||
cls_start_date=cls_data.cls_start_date,
|
||||
@@ -109,13 +124,23 @@ class ClsMgmtDAO:
|
||||
ClsMgmt.id == class_id,
|
||||
ClsMgmt.is_deleted == 0 # 只查未删除的
|
||||
).first()
|
||||
|
||||
head_tea = db.query(Teacher).filter(
|
||||
Teacher.type == "班主任",
|
||||
Teacher.id == cls_data.head_tea_id
|
||||
).first()
|
||||
lecturer = db.query(Teacher).filter(
|
||||
Teacher.type == "授课老师",
|
||||
Teacher.id == cls_data.lecturer_id
|
||||
).first()
|
||||
if update_cls:
|
||||
update_cls.head_tea_id=cls_data.head_tea_id
|
||||
update_cls.lecturer_id=cls_data.lecturer_id
|
||||
if not head_tea:
|
||||
raise HTTPException(status_code=404, detail=f"班主任id{cls_data.head_tea_id}不存在")
|
||||
elif not lecturer:
|
||||
raise HTTPException(status_code=404, detail=f"授课老师id{cls_data.lecturer_id}不存在")
|
||||
update_cls.head_tea_id = cls_data.head_tea_id
|
||||
update_cls.lecturer_id = cls_data.lecturer_id
|
||||
db.commit()
|
||||
return update_cls
|
||||
|
||||
raise HTTPException(status_code=404, detail=f"班级{class_id}不存在")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user