Merge pull request 'Ck' (#11) from ck into main
Reviewed-on: #11
This commit was merged in pull request #11.
This commit is contained in:
@@ -1,37 +1,37 @@
|
||||
from fastapi import APIRouter,HTTPException,Depends
|
||||
from database import Session
|
||||
from model.e_model import Employment
|
||||
from schema.e_schema import EmploymentRequest
|
||||
from dao.e_dao import get_employment_dao,wq_employment_dao,upd_employment_dao,del_employment_dao
|
||||
employment_api = APIRouter()
|
||||
|
||||
|
||||
def get_db():
|
||||
db = Session()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
@employment_api.get('/',summary='查询就业信息')
|
||||
def get_employment(db=Depends(get_db)):
|
||||
r = get_employment_dao(db)
|
||||
return {'code':200,'detail':'查询成功!','data':r}
|
||||
|
||||
|
||||
@employment_api.post('/',summary='新增就业信息')
|
||||
def add_employment(e:EmploymentRequest,db=Depends(get_db)):
|
||||
d= e.model_dump()
|
||||
r = wq_employment_dao(d,db)
|
||||
return {'code':200,'detail':'添加成功!','total':r}
|
||||
#
|
||||
#
|
||||
@employment_api.put('/',summary='更新就业信息')
|
||||
def update_employment(e:EmploymentRequest,db=Depends(get_db)):
|
||||
e1 = e.model_dump()
|
||||
r = upd_employment_dao(e1,db)
|
||||
return {'code':200,'msg':'更新成功','total':r}
|
||||
#
|
||||
@employment_api.delete('/',summary='删除就业信息')
|
||||
def delete_employment(stu_id:str,db=Depends(get_db)):
|
||||
r =del_employment_dao(stu_id,db)
|
||||
return {'code':200,'totals':r,'detail':'删除成功!'}
|
||||
from fastapi import APIRouter,HTTPException,Depends
|
||||
from database import Session
|
||||
from model.e_model import Employment
|
||||
from schema.e_schema import EmploymentRequest
|
||||
from dao.e_dao import get_employment_dao,wq_employment_dao,upd_employment_dao,del_employment_dao
|
||||
employment_api = APIRouter()
|
||||
|
||||
|
||||
def get_db():
|
||||
db = Session()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
@employment_api.get('/',summary='查询就业信息')
|
||||
def get_employment(db=Depends(get_db)):
|
||||
r = get_employment_dao(db)
|
||||
return {'code':200,'detail':'查询成功!','data':r}
|
||||
|
||||
|
||||
@employment_api.post('/',summary='新增就业信息')
|
||||
def add_employment(e:EmploymentRequest,db=Depends(get_db)):
|
||||
d= e.model_dump()
|
||||
r = wq_employment_dao(d,db)
|
||||
return {'code':200,'detail':'添加成功!','total':r}
|
||||
#
|
||||
#
|
||||
@employment_api.put('/',summary='更新就业信息')
|
||||
def update_employment(e:EmploymentRequest,db=Depends(get_db)):
|
||||
e1 = e.model_dump()
|
||||
r = upd_employment_dao(e1,db)
|
||||
return {'code':200,'msg':'更新成功','total':r}
|
||||
#
|
||||
@employment_api.delete('/',summary='删除就业信息')
|
||||
def delete_employment(stu_id:str,db=Depends(get_db)):
|
||||
r =del_employment_dao(stu_id,db)
|
||||
return {'code':200,'totals':r,'detail':'删除成功!'}
|
||||
@@ -1,45 +1,45 @@
|
||||
from dao import get_db
|
||||
from schema import Test
|
||||
from fastapi import APIRouter,Depends
|
||||
from dao import a,a1,a2,a3,a4,a5
|
||||
|
||||
ScoreAPI=APIRouter()
|
||||
ScoreAPI1=APIRouter()
|
||||
@ScoreAPI.post('/scores',tags=['增'])
|
||||
def scores(s:Test,db=Depends(get_db)):
|
||||
a(s,db)
|
||||
return {'code':200,'detail':'添加成功!',}
|
||||
@ScoreAPI.delete('/scores',tags=['删'])
|
||||
def scores1(stu_id:int,db=Depends(get_db)):
|
||||
r = a1(stu_id,db)
|
||||
if r==0:
|
||||
return '没有该学生'
|
||||
else:
|
||||
return f'已删除学生编号为{stu_id}的学生'
|
||||
@ScoreAPI.put('/scores',tags=['改'])
|
||||
def scores2(stu_id:int,exam_seq:int,s:Test,db=Depends(get_db)):
|
||||
r=a2(stu_id,exam_seq,s,db)
|
||||
if r!=0:
|
||||
return '更新成功'
|
||||
else:
|
||||
return '没有该数据'
|
||||
@ScoreAPI.get('/scores',tags=['查'])
|
||||
def Scores3(stu_id:int,exam_seq:int,db=Depends(get_db)):
|
||||
r=a3(stu_id,exam_seq,db)
|
||||
try:
|
||||
return {'成绩编号':r.id,'学生编号':r.stu_id,f'第{exam_seq}次成绩:':r.score,'创建日期':r.create_date,'更新日期':r.update_date}
|
||||
except:
|
||||
return '没有该学生'
|
||||
@ScoreAPI1.put('/scores/{stu_id}',tags=['软删除'])
|
||||
def scores4(stu_id:int,exam_seq:int,db=Depends(get_db)):
|
||||
r=a4(stu_id, exam_seq, db)
|
||||
if r ==0:
|
||||
return '没有该数据'
|
||||
else:
|
||||
return '已删除'
|
||||
@ScoreAPI1.get('/scores/{stu_id}',tags=['总分,平均分,最大值,最小值'])
|
||||
def scores5(stu_id:int,db=Depends(get_db)):
|
||||
s,r,a=a5(stu_id,db)
|
||||
|
||||
return f'总分:{s},平均分:{s/len(r)},最大值:{max(a)},最小值:{min(a)}'
|
||||
|
||||
from dao import get_db
|
||||
from schema import Test
|
||||
from fastapi import APIRouter,Depends
|
||||
from dao import a,a1,a2,a3,a4,a5
|
||||
|
||||
ScoreAPI=APIRouter()
|
||||
ScoreAPI1=APIRouter()
|
||||
@ScoreAPI.post('/scores',tags=['增'])
|
||||
def scores(s:Test,db=Depends(get_db)):
|
||||
a(s,db)
|
||||
return {'code':200,'detail':'添加成功!',}
|
||||
@ScoreAPI.delete('/scores',tags=['删'])
|
||||
def scores1(stu_id:int,db=Depends(get_db)):
|
||||
r = a1(stu_id,db)
|
||||
if r==0:
|
||||
return '没有该学生'
|
||||
else:
|
||||
return f'已删除学生编号为{stu_id}的学生'
|
||||
@ScoreAPI.put('/scores',tags=['改'])
|
||||
def scores2(stu_id:int,exam_seq:int,s:Test,db=Depends(get_db)):
|
||||
r=a2(stu_id,exam_seq,s,db)
|
||||
if r!=0:
|
||||
return '更新成功'
|
||||
else:
|
||||
return '没有该数据'
|
||||
@ScoreAPI.get('/scores',tags=['查'])
|
||||
def Scores3(stu_id:int,exam_seq:int,db=Depends(get_db)):
|
||||
r=a3(stu_id,exam_seq,db)
|
||||
try:
|
||||
return {'成绩编号':r.id,'学生编号':r.stu_id,f'第{exam_seq}次成绩:':r.score,'创建日期':r.create_date,'更新日期':r.update_date}
|
||||
except:
|
||||
return '没有该学生'
|
||||
@ScoreAPI1.put('/scores/{stu_id}',tags=['软删除'])
|
||||
def scores4(stu_id:int,exam_seq:int,db=Depends(get_db)):
|
||||
r=a4(stu_id, exam_seq, db)
|
||||
if r ==0:
|
||||
return '没有该数据'
|
||||
else:
|
||||
return '已删除'
|
||||
@ScoreAPI1.get('/scores/{stu_id}',tags=['总分,平均分,最大值,最小值'])
|
||||
def scores5(stu_id:int,db=Depends(get_db)):
|
||||
s,r,a=a5(stu_id,db)
|
||||
|
||||
return f'总分:{s},平均分:{s/len(r)},最大值:{max(a)},最小值:{min(a)}'
|
||||
|
||||
+168
-168
@@ -1,168 +1,168 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from database import get_db
|
||||
from dao.student_dao import create_student, get_student_by_id, get_student_list, update_student, delete_student_logic
|
||||
from schema.student_schema import (
|
||||
StudentCreateRequest,
|
||||
StudentUpdateRequest,
|
||||
StudentQuery,
|
||||
StudentResponse,
|
||||
StudentPageResponse
|
||||
)
|
||||
|
||||
# 创建路由对象 API Router1
|
||||
router = APIRouter( tags=["学生管理模块"])
|
||||
@router.post("/", response_model=StudentResponse,summary="新增学生")
|
||||
def add_student(
|
||||
student_req: StudentCreateRequest,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
db_stu = create_student(db, student_req)
|
||||
# 手动转字典:model的stu_id映射响应体的id
|
||||
stu_dict = {
|
||||
"id": db_stu.id,
|
||||
"stu_id": db_stu.stu_id,
|
||||
"class_id": db_stu.class_id,
|
||||
"stu_name": db_stu.stu_name,
|
||||
"native_place": db_stu.native_place,
|
||||
"graduate_school": db_stu.graduate_school,
|
||||
"major": db_stu.major,
|
||||
"enroll_date": db_stu.enroll_date,
|
||||
"graduate_date": db_stu.graduate_date,
|
||||
"education": db_stu.education,
|
||||
"advisor_no": db_stu.advisor_no,
|
||||
"age": db_stu.age,
|
||||
"gender": db_stu.gender,
|
||||
"is_deleted": db_stu.is_deleted
|
||||
}
|
||||
return StudentResponse(**stu_dict)
|
||||
|
||||
|
||||
@router.get("/", response_model=StudentPageResponse,summary="根据学号姓名班级查询")
|
||||
def get_student_page(
|
||||
query: StudentQuery = Depends(),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
|
||||
total, db_stu_list = get_student_list(
|
||||
db,
|
||||
stu_id=query.stu_id,
|
||||
stu_name=query.stu_name,
|
||||
class_id=query.class_id,
|
||||
page=query.page,
|
||||
page_size=query.page_size
|
||||
)
|
||||
item_list = []
|
||||
for db_stu in db_stu_list:
|
||||
stu_dict = {
|
||||
"id": db_stu.id,
|
||||
"stu_id": db_stu.stu_id,
|
||||
"class_id": db_stu.class_id,
|
||||
"stu_name": db_stu.stu_name,
|
||||
"native_place": db_stu.native_place,
|
||||
"graduate_school": db_stu.graduate_school,
|
||||
"major": db_stu.major,
|
||||
"enroll_date": db_stu.enroll_date,
|
||||
"graduate_date": db_stu.graduate_date,
|
||||
"education": db_stu.education,
|
||||
"advisor_no": db_stu.advisor_no,
|
||||
"age": db_stu.age,
|
||||
"gender": db_stu.gender,
|
||||
"is_deleted": db_stu.is_deleted
|
||||
}
|
||||
item_list.append(StudentResponse(**stu_dict))
|
||||
|
||||
return StudentPageResponse(
|
||||
total=total,
|
||||
page=query.page,
|
||||
page_size=query.page_size,
|
||||
items=item_list
|
||||
)
|
||||
|
||||
|
||||
@router.get("/{stu_id}", response_model=StudentResponse,summary="根据id查询")
|
||||
def get_one_student(
|
||||
stu_id: int,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
#根据主键stu_id查询单个学生
|
||||
db_stu = get_student_by_id(db, stu_id)
|
||||
if db_stu is None:
|
||||
raise HTTPException(status_code=404, detail="该学生不存在")
|
||||
|
||||
stu_dict = {
|
||||
"id": db_stu.id,
|
||||
"stu_id": db_stu.stu_id,
|
||||
"class_id": db_stu.class_id,
|
||||
"stu_name": db_stu.stu_name,
|
||||
"native_place": db_stu.native_place,
|
||||
"graduate_school": db_stu.graduate_school,
|
||||
"major": db_stu.major,
|
||||
"enroll_date": db_stu.enroll_date,
|
||||
"graduate_date": db_stu.graduate_date,
|
||||
"education": db_stu.education,
|
||||
"advisor_no": db_stu.advisor_no,
|
||||
"age": db_stu.age,
|
||||
"gender": db_stu.gender,
|
||||
"is_deleted": db_stu.is_deleted
|
||||
}
|
||||
return StudentResponse(**stu_dict)
|
||||
|
||||
|
||||
@router.put("/{stu_id}", response_model=StudentResponse,summary="修改学生信息")
|
||||
def edit_student(
|
||||
stu_id: int,
|
||||
update_req: StudentUpdateRequest,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
#修改学生信息
|
||||
db_stu = update_student(db, stu_id, update_req)
|
||||
if db_stu is None:
|
||||
raise HTTPException(status_code=404, detail="该学生不存在")
|
||||
|
||||
stu_dict = {
|
||||
"id": db_stu.id,
|
||||
"stu_id": db_stu.stu_id,
|
||||
"class_id": db_stu.class_id,
|
||||
"stu_name": db_stu.stu_name,
|
||||
"native_place": db_stu.native_place,
|
||||
"graduate_school": db_stu.graduate_school,
|
||||
"major": db_stu.major,
|
||||
"enroll_date": db_stu.enroll_date,
|
||||
"graduate_date": db_stu.graduate_date,
|
||||
"education": db_stu.education,
|
||||
"advisor_no": db_stu.advisor_no,
|
||||
"age": db_stu.age,
|
||||
"gender": db_stu.gender,
|
||||
"is_deleted": db_stu.is_deleted
|
||||
}
|
||||
return StudentResponse(**stu_dict)
|
||||
|
||||
|
||||
@router.delete("/{stu_id}", response_model=StudentResponse,summary="删除学生信息")
|
||||
def remove_student(
|
||||
stu_id: int,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
#逻辑删除学生
|
||||
db_stu = delete_student_logic(db, stu_id)
|
||||
if db_stu is None:
|
||||
raise HTTPException(status_code=404, detail="该学生不存在")
|
||||
|
||||
stu_dict = {
|
||||
"id": db_stu.id,
|
||||
"stu_id": db_stu.stu_id,
|
||||
"stu_name": db_stu.stu_name,
|
||||
"class_id": db_stu.class_id,
|
||||
"native_place": db_stu.native_place,
|
||||
"graduate_school": db_stu.graduate_school,
|
||||
"major": db_stu.major,
|
||||
"enroll_date": db_stu.enroll_date,
|
||||
"graduate_date": db_stu.graduate_date,
|
||||
"education": db_stu.education,
|
||||
"advisor_no": db_stu.advisor_no,
|
||||
"age": db_stu.age,
|
||||
"gender": db_stu.gender,
|
||||
"is_deleted": db_stu.is_deleted
|
||||
}
|
||||
return StudentResponse(**stu_dict)
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from database import get_db
|
||||
from dao.student_dao import create_student, get_student_by_id, get_student_list, update_student, delete_student_logic
|
||||
from schema.student_schema import (
|
||||
StudentCreateRequest,
|
||||
StudentUpdateRequest,
|
||||
StudentQuery,
|
||||
StudentResponse,
|
||||
StudentPageResponse
|
||||
)
|
||||
|
||||
# 创建路由对象 API Router1
|
||||
router = APIRouter( tags=["学生管理模块"])
|
||||
@router.post("/", response_model=StudentResponse,summary="新增学生")
|
||||
def add_student(
|
||||
student_req: StudentCreateRequest,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
db_stu = create_student(db, student_req)
|
||||
# 手动转字典:model的stu_id映射响应体的id
|
||||
stu_dict = {
|
||||
"id": db_stu.id,
|
||||
"stu_id": db_stu.stu_id,
|
||||
"class_id": db_stu.class_id,
|
||||
"stu_name": db_stu.stu_name,
|
||||
"native_place": db_stu.native_place,
|
||||
"graduate_school": db_stu.graduate_school,
|
||||
"major": db_stu.major,
|
||||
"enroll_date": db_stu.enroll_date,
|
||||
"graduate_date": db_stu.graduate_date,
|
||||
"education": db_stu.education,
|
||||
"advisor_no": db_stu.advisor_no,
|
||||
"age": db_stu.age,
|
||||
"gender": db_stu.gender,
|
||||
"is_deleted": db_stu.is_deleted
|
||||
}
|
||||
return StudentResponse(**stu_dict)
|
||||
|
||||
|
||||
@router.get("/", response_model=StudentPageResponse,summary="根据学号姓名班级查询")
|
||||
def get_student_page(
|
||||
query: StudentQuery = Depends(),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
|
||||
total, db_stu_list = get_student_list(
|
||||
db,
|
||||
stu_id=query.stu_id,
|
||||
stu_name=query.stu_name,
|
||||
class_id=query.class_id,
|
||||
page=query.page,
|
||||
page_size=query.page_size
|
||||
)
|
||||
item_list = []
|
||||
for db_stu in db_stu_list:
|
||||
stu_dict = {
|
||||
"id": db_stu.id,
|
||||
"stu_id": db_stu.stu_id,
|
||||
"class_id": db_stu.class_id,
|
||||
"stu_name": db_stu.stu_name,
|
||||
"native_place": db_stu.native_place,
|
||||
"graduate_school": db_stu.graduate_school,
|
||||
"major": db_stu.major,
|
||||
"enroll_date": db_stu.enroll_date,
|
||||
"graduate_date": db_stu.graduate_date,
|
||||
"education": db_stu.education,
|
||||
"advisor_no": db_stu.advisor_no,
|
||||
"age": db_stu.age,
|
||||
"gender": db_stu.gender,
|
||||
"is_deleted": db_stu.is_deleted
|
||||
}
|
||||
item_list.append(StudentResponse(**stu_dict))
|
||||
|
||||
return StudentPageResponse(
|
||||
total=total,
|
||||
page=query.page,
|
||||
page_size=query.page_size,
|
||||
items=item_list
|
||||
)
|
||||
|
||||
|
||||
@router.get("/{stu_id}", response_model=StudentResponse,summary="根据id查询")
|
||||
def get_one_student(
|
||||
stu_id: int,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
#根据主键stu_id查询单个学生
|
||||
db_stu = get_student_by_id(db, stu_id)
|
||||
if db_stu is None:
|
||||
raise HTTPException(status_code=404, detail="该学生不存在")
|
||||
|
||||
stu_dict = {
|
||||
"id": db_stu.id,
|
||||
"stu_id": db_stu.stu_id,
|
||||
"class_id": db_stu.class_id,
|
||||
"stu_name": db_stu.stu_name,
|
||||
"native_place": db_stu.native_place,
|
||||
"graduate_school": db_stu.graduate_school,
|
||||
"major": db_stu.major,
|
||||
"enroll_date": db_stu.enroll_date,
|
||||
"graduate_date": db_stu.graduate_date,
|
||||
"education": db_stu.education,
|
||||
"advisor_no": db_stu.advisor_no,
|
||||
"age": db_stu.age,
|
||||
"gender": db_stu.gender,
|
||||
"is_deleted": db_stu.is_deleted
|
||||
}
|
||||
return StudentResponse(**stu_dict)
|
||||
|
||||
|
||||
@router.put("/{stu_id}", response_model=StudentResponse,summary="修改学生信息")
|
||||
def edit_student(
|
||||
stu_id: int,
|
||||
update_req: StudentUpdateRequest,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
#修改学生信息
|
||||
db_stu = update_student(db, stu_id, update_req)
|
||||
if db_stu is None:
|
||||
raise HTTPException(status_code=404, detail="该学生不存在")
|
||||
|
||||
stu_dict = {
|
||||
"id": db_stu.id,
|
||||
"stu_id": db_stu.stu_id,
|
||||
"class_id": db_stu.class_id,
|
||||
"stu_name": db_stu.stu_name,
|
||||
"native_place": db_stu.native_place,
|
||||
"graduate_school": db_stu.graduate_school,
|
||||
"major": db_stu.major,
|
||||
"enroll_date": db_stu.enroll_date,
|
||||
"graduate_date": db_stu.graduate_date,
|
||||
"education": db_stu.education,
|
||||
"advisor_no": db_stu.advisor_no,
|
||||
"age": db_stu.age,
|
||||
"gender": db_stu.gender,
|
||||
"is_deleted": db_stu.is_deleted
|
||||
}
|
||||
return StudentResponse(**stu_dict)
|
||||
|
||||
|
||||
@router.delete("/{stu_id}", response_model=StudentResponse,summary="删除学生信息")
|
||||
def remove_student(
|
||||
stu_id: int,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
#逻辑删除学生
|
||||
db_stu = delete_student_logic(db, stu_id)
|
||||
if db_stu is None:
|
||||
raise HTTPException(status_code=404, detail="该学生不存在")
|
||||
|
||||
stu_dict = {
|
||||
"id": db_stu.id,
|
||||
"stu_id": db_stu.stu_id,
|
||||
"stu_name": db_stu.stu_name,
|
||||
"class_id": db_stu.class_id,
|
||||
"native_place": db_stu.native_place,
|
||||
"graduate_school": db_stu.graduate_school,
|
||||
"major": db_stu.major,
|
||||
"enroll_date": db_stu.enroll_date,
|
||||
"graduate_date": db_stu.graduate_date,
|
||||
"education": db_stu.education,
|
||||
"advisor_no": db_stu.advisor_no,
|
||||
"age": db_stu.age,
|
||||
"gender": db_stu.gender,
|
||||
"is_deleted": db_stu.is_deleted
|
||||
}
|
||||
return StudentResponse(**stu_dict)
|
||||
@@ -1,67 +1,67 @@
|
||||
from fastapi import APIRouter,Depends,UploadFile,File,Query
|
||||
from model.teaModel import Session
|
||||
from dao.teaDao import insert_teachers_dao,update_teachers_dao,delete_teachers_dao,get_teachers_limit_dao,get_teachers_name_dao
|
||||
from schema.teaSchema import RequestModel, ResponseModel
|
||||
|
||||
t_router = APIRouter()
|
||||
|
||||
def get_db():
|
||||
db = Session()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@t_router.get("/teachers",tags=['教师接口信息'],summary='分页查询教师接口')
|
||||
def get_teachers(p:int=Query(default=0,ge=0,description='页码,0表示查询全部'),
|
||||
n:int=Query(default=0,ge=0,description='每页条数,0表示查询全部'),
|
||||
db=Depends(get_db)):
|
||||
db_teachers = get_teachers_limit_dao(p,n,db)
|
||||
return ResponseModel(data=db_teachers,total=len(db_teachers))
|
||||
|
||||
@t_router.get("/teachers/{name}",tags=['教师接口信息'],summary='分页查询教师接口')
|
||||
def get_name_teachers(name:str,db=Depends(get_db)):
|
||||
db_teachers = get_teachers_name_dao(name,db)
|
||||
return ResponseModel(data=db_teachers,total=len(db_teachers))
|
||||
|
||||
@t_router.post("/teachers",tags=['教师接口信息'],summary='新增教师接口')
|
||||
def insert_teachers(req:RequestModel,db=Depends(get_db)):
|
||||
rq= req.model_dump()
|
||||
n,m = insert_teachers_dao(rq,db)
|
||||
# print('打印获取的值:',n,m)
|
||||
return ResponseModel(total=n,msg=m)
|
||||
|
||||
@t_router.put("/teachers/{t_id}",tags=['教师接口信息'],summary='更新教师接口')
|
||||
def update_teachers(req:RequestModel,t_id:int,db=Depends(get_db),):
|
||||
rq= req.model_dump()
|
||||
n,m = update_teachers_dao(rq,db,t_id)
|
||||
return ResponseModel(total=n,msg=m)
|
||||
|
||||
@t_router.delete("/teachers/{t_id}",tags=['教师接口信息'],summary='删除教师接口')
|
||||
def delete_teachers(t_id:int,db=Depends(get_db)):
|
||||
n,m =delete_teachers_dao(t_id,db)
|
||||
return ResponseModel(msg=m,total=n)
|
||||
|
||||
@t_router.post('/files',tags=['文件接口信息'],summary='上传文件接口')
|
||||
async def upload_files(f:UploadFile=File(),db=Depends(get_db)):
|
||||
# print('UploadFile上传文件,读取该对象:',f)
|
||||
text =await f.read()
|
||||
l =text.decode('utf-8').split('\n')
|
||||
lg = 0
|
||||
dt = []
|
||||
print('长度为',lg,l)
|
||||
for i in l:
|
||||
if '名字' in i:
|
||||
continue
|
||||
p = i.split()
|
||||
if not p: # 判断如果p为[],跳过
|
||||
continue
|
||||
l2 = ['t_name','t_age','t_phone','t_sex','class_id']
|
||||
d =dict()
|
||||
for j in range(len(p)):
|
||||
d[l2[j]]=p[j]
|
||||
insert_teachers_dao(d,db)
|
||||
lg = lg + 1
|
||||
dt.append(d)
|
||||
return ResponseModel(msg='上传成功',total=lg,data=dt)
|
||||
from fastapi import APIRouter,Depends,UploadFile,File,Query
|
||||
from model.teaModel import Session
|
||||
from dao.teaDao import insert_teachers_dao,update_teachers_dao,delete_teachers_dao,get_teachers_limit_dao,get_teachers_name_dao
|
||||
from schema.teaSchema import RequestModel, ResponseModel
|
||||
|
||||
t_router = APIRouter()
|
||||
|
||||
def get_db():
|
||||
db = Session()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@t_router.get("/teachers",tags=['教师接口信息'],summary='分页查询教师接口')
|
||||
def get_teachers(p:int=Query(default=0,ge=0,description='页码,0表示查询全部'),
|
||||
n:int=Query(default=0,ge=0,description='每页条数,0表示查询全部'),
|
||||
db=Depends(get_db)):
|
||||
db_teachers = get_teachers_limit_dao(p,n,db)
|
||||
return ResponseModel(data=db_teachers,total=len(db_teachers))
|
||||
|
||||
@t_router.get("/teachers/{name}",tags=['教师接口信息'],summary='分页查询教师接口')
|
||||
def get_name_teachers(name:str,db=Depends(get_db)):
|
||||
db_teachers = get_teachers_name_dao(name,db)
|
||||
return ResponseModel(data=db_teachers,total=len(db_teachers))
|
||||
|
||||
@t_router.post("/teachers",tags=['教师接口信息'],summary='新增教师接口')
|
||||
def insert_teachers(req:RequestModel,db=Depends(get_db)):
|
||||
rq= req.model_dump()
|
||||
n,m = insert_teachers_dao(rq,db)
|
||||
# print('打印获取的值:',n,m)
|
||||
return ResponseModel(total=n,msg=m)
|
||||
|
||||
@t_router.put("/teachers/{t_id}",tags=['教师接口信息'],summary='更新教师接口')
|
||||
def update_teachers(req:RequestModel,t_id:int,db=Depends(get_db),):
|
||||
rq= req.model_dump()
|
||||
n,m = update_teachers_dao(rq,db,t_id)
|
||||
return ResponseModel(total=n,msg=m)
|
||||
|
||||
@t_router.delete("/teachers/{t_id}",tags=['教师接口信息'],summary='删除教师接口')
|
||||
def delete_teachers(t_id:int,db=Depends(get_db)):
|
||||
n,m =delete_teachers_dao(t_id,db)
|
||||
return ResponseModel(msg=m,total=n)
|
||||
|
||||
@t_router.post('/files',tags=['文件接口信息'],summary='上传文件接口')
|
||||
async def upload_files(f:UploadFile=File(),db=Depends(get_db)):
|
||||
# print('UploadFile上传文件,读取该对象:',f)
|
||||
text =await f.read()
|
||||
l =text.decode('utf-8').split('\n')
|
||||
lg = 0
|
||||
dt = []
|
||||
print('长度为',lg,l)
|
||||
for i in l:
|
||||
if '名字' in i:
|
||||
continue
|
||||
p = i.split()
|
||||
if not p: # 判断如果p为[],跳过
|
||||
continue
|
||||
l2 = ['t_name','t_age','t_phone','t_sex','class_id']
|
||||
d =dict()
|
||||
for j in range(len(p)):
|
||||
d[l2[j]]=p[j]
|
||||
insert_teachers_dao(d,db)
|
||||
lg = lg + 1
|
||||
dt.append(d)
|
||||
return ResponseModel(msg='上传成功',total=lg,data=dt)
|
||||
@@ -1,52 +1,52 @@
|
||||
from http.client import HTTPException
|
||||
|
||||
from model.e_model import Employment
|
||||
from fastapi import HTTPException
|
||||
|
||||
def get_employment_dao(db):
|
||||
try:
|
||||
r = db.query(Employment).all()
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500, detail=f'查询失败:str(e)')
|
||||
else:
|
||||
db.commit()
|
||||
return [{'stu_id':i.stu_id,'class_name':i.class_name} for i in r ]
|
||||
|
||||
|
||||
def wq_employment_dao(o,db):
|
||||
try:
|
||||
o1 = Employment(**o)
|
||||
db.add(o1)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500, detail=f'添加失败:str(e)')
|
||||
else:
|
||||
db.commit()
|
||||
return 1
|
||||
|
||||
def upd_employment_dao(e,db):
|
||||
try:
|
||||
rows = db.query(Employment).filter(Employment.stu_id == e['stu_id']).update(e)
|
||||
except:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500, detail='更新异常,请稍后再执行!')
|
||||
else:
|
||||
db.commit()
|
||||
return 1
|
||||
|
||||
def del_employment_dao(stu_id,db):
|
||||
try:
|
||||
row = db.query(Employment).filter(Employment.stu_id == stu_id).all()
|
||||
if not row:
|
||||
raise HTTPException(status_code=404,detail='记录不存在')
|
||||
for i in row:
|
||||
if i.deleted == 0:
|
||||
db.query(Employment).filter(Employment.stu_id == i.stu_id).update({'deleted':1})
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500,detail=f'删除失败:{str(e)}')
|
||||
else:
|
||||
db.commit()
|
||||
return 1
|
||||
|
||||
from http.client import HTTPException
|
||||
|
||||
from model.e_model import Employment
|
||||
from fastapi import HTTPException
|
||||
|
||||
def get_employment_dao(db):
|
||||
try:
|
||||
r = db.query(Employment).all()
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500, detail=f'查询失败:str(e)')
|
||||
else:
|
||||
db.commit()
|
||||
return [{'stu_id':i.stu_id,'class_name':i.class_name} for i in r ]
|
||||
|
||||
|
||||
def wq_employment_dao(o,db):
|
||||
try:
|
||||
o1 = Employment(**o)
|
||||
db.add(o1)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500, detail=f'添加失败:str(e)')
|
||||
else:
|
||||
db.commit()
|
||||
return 1
|
||||
|
||||
def upd_employment_dao(e,db):
|
||||
try:
|
||||
rows = db.query(Employment).filter(Employment.stu_id == e['stu_id']).update(e)
|
||||
except:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500, detail='更新异常,请稍后再执行!')
|
||||
else:
|
||||
db.commit()
|
||||
return 1
|
||||
|
||||
def del_employment_dao(stu_id,db):
|
||||
try:
|
||||
row = db.query(Employment).filter(Employment.stu_id == stu_id).all()
|
||||
if not row:
|
||||
raise HTTPException(status_code=404,detail='记录不存在')
|
||||
for i in row:
|
||||
if i.deleted == 0:
|
||||
db.query(Employment).filter(Employment.stu_id == i.stu_id).update({'deleted':1})
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500,detail=f'删除失败:{str(e)}')
|
||||
else:
|
||||
db.commit()
|
||||
return 1
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
from model import Session
|
||||
from model import Scores
|
||||
def get_db():
|
||||
db = Session()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
# @ScoreAPI.post('/scores')
|
||||
def a(s,db):
|
||||
d = s.model_dump()
|
||||
o = Scores(**d)
|
||||
db.add(o)
|
||||
db.commit()
|
||||
# @ScoreAPI.delete('/scores')
|
||||
def a1(stu_id,db):
|
||||
r=db.query(Scores).filter(Scores.stu_id==stu_id).delete()
|
||||
db.commit()
|
||||
return r
|
||||
# @ScoreAPI.put('/scores')
|
||||
def a2(stu_id,exam_seq,s,db):
|
||||
r = db.query(Scores).filter((Scores.stu_id == stu_id) & (Scores.exam_seq == exam_seq)).update(
|
||||
s.model_dump(exclude={'stu_id', 'exam_seq'}))
|
||||
db.commit()
|
||||
return r
|
||||
#@ScoreAPI.get('/scores')
|
||||
def a3(stu_id,exam_seq,db):
|
||||
r=db.query(Scores).filter((Scores.stu_id==stu_id)&(Scores.exam_seq==exam_seq)).first()
|
||||
return r
|
||||
# @ScoreAPI1.put('/scores/{stu_id}',tags=['软删除'])
|
||||
def a4(stu_id, exam_seq, db):
|
||||
r=db.query(Scores).filter((Scores.stu_id==stu_id)&(Scores.exam_seq==exam_seq)).update({Scores.deleted:0})
|
||||
db.commit()
|
||||
return r
|
||||
# @ScoreAPI1.get('/scores/{stu_id}',tags=['总分,平均分,最大值,最小值'])
|
||||
def a5(stu_id,db):
|
||||
r = db.query(Scores).filter((Scores.stu_id == stu_id)).all()
|
||||
s = 0
|
||||
a = []
|
||||
for i in r:
|
||||
s += i.score
|
||||
a.append(i.score)
|
||||
return s,r,a
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
from model import Session
|
||||
from model import Scores
|
||||
def get_db():
|
||||
db = Session()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
# @ScoreAPI.post('/scores')
|
||||
def a(s,db):
|
||||
d = s.model_dump()
|
||||
o = Scores(**d)
|
||||
db.add(o)
|
||||
db.commit()
|
||||
# @ScoreAPI.delete('/scores')
|
||||
def a1(stu_id,db):
|
||||
r=db.query(Scores).filter(Scores.stu_id==stu_id).delete()
|
||||
db.commit()
|
||||
return r
|
||||
# @ScoreAPI.put('/scores')
|
||||
def a2(stu_id,exam_seq,s,db):
|
||||
r = db.query(Scores).filter((Scores.stu_id == stu_id) & (Scores.exam_seq == exam_seq)).update(
|
||||
s.model_dump(exclude={'stu_id', 'exam_seq'}))
|
||||
db.commit()
|
||||
return r
|
||||
#@ScoreAPI.get('/scores')
|
||||
def a3(stu_id,exam_seq,db):
|
||||
r=db.query(Scores).filter((Scores.stu_id==stu_id)&(Scores.exam_seq==exam_seq)).first()
|
||||
return r
|
||||
# @ScoreAPI1.put('/scores/{stu_id}',tags=['软删除'])
|
||||
def a4(stu_id, exam_seq, db):
|
||||
r=db.query(Scores).filter((Scores.stu_id==stu_id)&(Scores.exam_seq==exam_seq)).update({Scores.deleted:0})
|
||||
db.commit()
|
||||
return r
|
||||
# @ScoreAPI1.get('/scores/{stu_id}',tags=['总分,平均分,最大值,最小值'])
|
||||
def a5(stu_id,db):
|
||||
r = db.query(Scores).filter((Scores.stu_id == stu_id)).all()
|
||||
s = 0
|
||||
a = []
|
||||
for i in r:
|
||||
s += i.score
|
||||
a.append(i.score)
|
||||
return s,r,a
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from model.student_model import Student
|
||||
from schema.student_schema import StudentCreateRequest,StudentUpdateRequest
|
||||
def create_student(db: Session, student_create: StudentCreateRequest):
|
||||
"""
|
||||
新增学生
|
||||
: db: 数据库会话
|
||||
:student_c reate: 前端传来的新增请求体
|
||||
"""
|
||||
db_student = Student(**student_create.model_dump())#请求体转为字典,再解包创建实体对象
|
||||
db.add(db_student)#添加
|
||||
db.commit()#提交事务
|
||||
new_student=db.query(Student).filter(
|
||||
Student.stu_id==student_create.stu_id,
|
||||
Student.is_deleted==False).first()
|
||||
#查询 Student 表,取第一条,没有则返回 None
|
||||
return new_student
|
||||
def get_student_by_id(db: Session, stu_id: int):#根据stu_id查询单个学生
|
||||
query = db.query(Student).filter(
|
||||
Student.stu_id == stu_id,
|
||||
Student.is_deleted == False)
|
||||
return query.first()
|
||||
def get_student_list(db: Session, stu_id:None,
|
||||
class_id:str=None, page:int=1, page_size:int=10, stu_name:str=None):#查询学生列表,支持按照编号/姓名/班级删选
|
||||
# 基础查询:只查未逻辑删除的学生
|
||||
query = db.query(Student).filter(Student.is_deleted == False)
|
||||
if stu_id:
|
||||
query = query.filter(Student.stu_id == stu_id)
|
||||
if stu_name:
|
||||
query = query.filter(Student.stu_name == stu_name)
|
||||
if class_id:
|
||||
query = query.filter(Student.class_id == class_id)
|
||||
total = query.count()#统计满足条件的记录
|
||||
offset = (page - 1) * page_size# 计算分页偏移量:跳过前面 (page-1)*page_size 条
|
||||
db_student_list = query.offset(offset).limit(page_size).all()# 执行分页查询:跳过offset条,取page_size条
|
||||
return total, db_student_list
|
||||
def update_student(db: Session, stu_id:int,student_update: StudentUpdateRequest):
|
||||
"""修改学生信息
|
||||
db: 数据库会话stu_id: 要修改的学生主键student_update: 前端传来的修改请求体:
|
||||
"""
|
||||
db_student = get_student_by_id(db=db,stu_id=stu_id)
|
||||
if not db_student:
|
||||
return None#先查学生,查不到报错
|
||||
update_data=student_update.model_dump(exclude_unset=True)#只解析前端输入的键值对,默认值不会解析
|
||||
for k,v in update_data.items():
|
||||
setattr(db_student,k,v)#把 value 赋给 db_student 的 key 属性。
|
||||
db.commit()
|
||||
updated_student=get_student_by_id(db, stu_id)
|
||||
return updated_student
|
||||
def delete_student_logic(db: Session, stu_id:int):
|
||||
db_student = get_student_by_id(db, stu_id)
|
||||
if not db_student:
|
||||
return None
|
||||
db_student.is_deleted = True#把逻辑删除标记改成True
|
||||
db.commit()#重新查询,返回标记已删除的这条记录
|
||||
deleted_student = db.query(Student).filter(Student.stu_id == stu_id).first()
|
||||
return deleted_student
|
||||
from sqlalchemy.orm import Session
|
||||
from model.student_model import Student
|
||||
from schema.student_schema import StudentCreateRequest,StudentUpdateRequest
|
||||
def create_student(db: Session, student_create: StudentCreateRequest):
|
||||
"""
|
||||
新增学生
|
||||
: db: 数据库会话
|
||||
:student_c reate: 前端传来的新增请求体
|
||||
"""
|
||||
db_student = Student(**student_create.model_dump())#请求体转为字典,再解包创建实体对象
|
||||
db.add(db_student)#添加
|
||||
db.commit()#提交事务
|
||||
new_student=db.query(Student).filter(
|
||||
Student.stu_id==student_create.stu_id,
|
||||
Student.is_deleted==False).first()
|
||||
#查询 Student 表,取第一条,没有则返回 None
|
||||
return new_student
|
||||
def get_student_by_id(db: Session, stu_id: int):#根据stu_id查询单个学生
|
||||
query = db.query(Student).filter(
|
||||
Student.stu_id == stu_id,
|
||||
Student.is_deleted == False)
|
||||
return query.first()
|
||||
def get_student_list(db: Session, stu_id:None,
|
||||
class_id:str=None, page:int=1, page_size:int=10, stu_name:str=None):#查询学生列表,支持按照编号/姓名/班级删选
|
||||
# 基础查询:只查未逻辑删除的学生
|
||||
query = db.query(Student).filter(Student.is_deleted == False)
|
||||
if stu_id:
|
||||
query = query.filter(Student.stu_id == stu_id)
|
||||
if stu_name:
|
||||
query = query.filter(Student.stu_name == stu_name)
|
||||
if class_id:
|
||||
query = query.filter(Student.class_id == class_id)
|
||||
total = query.count()#统计满足条件的记录
|
||||
offset = (page - 1) * page_size# 计算分页偏移量:跳过前面 (page-1)*page_size 条
|
||||
db_student_list = query.offset(offset).limit(page_size).all()# 执行分页查询:跳过offset条,取page_size条
|
||||
return total, db_student_list
|
||||
def update_student(db: Session, stu_id:int,student_update: StudentUpdateRequest):
|
||||
"""修改学生信息
|
||||
db: 数据库会话stu_id: 要修改的学生主键student_update: 前端传来的修改请求体:
|
||||
"""
|
||||
db_student = get_student_by_id(db=db,stu_id=stu_id)
|
||||
if not db_student:
|
||||
return None#先查学生,查不到报错
|
||||
update_data=student_update.model_dump(exclude_unset=True)#只解析前端输入的键值对,默认值不会解析
|
||||
for k,v in update_data.items():
|
||||
setattr(db_student,k,v)#把 value 赋给 db_student 的 key 属性。
|
||||
db.commit()
|
||||
updated_student=get_student_by_id(db, stu_id)
|
||||
return updated_student
|
||||
def delete_student_logic(db: Session, stu_id:int):
|
||||
db_student = get_student_by_id(db, stu_id)
|
||||
if not db_student:
|
||||
return None
|
||||
db_student.is_deleted = True#把逻辑删除标记改成True
|
||||
db.commit()#重新查询,返回标记已删除的这条记录
|
||||
deleted_student = db.query(Student).filter(Student.stu_id == stu_id).first()
|
||||
return deleted_student
|
||||
@@ -1,63 +1,63 @@
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from fastapi import HTTPException
|
||||
from model.teaModel import Teacher
|
||||
|
||||
def get_teachers_limit_dao(p,n,db):
|
||||
if p == 0 and n == 0:
|
||||
r = db.query(Teacher).all()
|
||||
else:
|
||||
if p < 1:
|
||||
p = 1
|
||||
r = db.query(Teacher).offset((p-1)*n).limit(n).all()
|
||||
return [ {'id':i.id,'t_name':i.t_name,'t_sex':i.t_sex,'t_age':i.t_age} for i in r]
|
||||
|
||||
|
||||
def get_teachers_name_dao(name,db):
|
||||
try:
|
||||
r = db.query(Teacher).filter(Teacher.t_name==name).all()
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500, detail=f'查询失败:{str(e)}')
|
||||
else:
|
||||
return [ {'id':i.id,'t_name':i.t_name,'t_sex':i.t_sex,'t_age':i.t_age} for i in r]
|
||||
|
||||
def insert_teachers_dao(req,db):
|
||||
try:
|
||||
exist = db.query(Teacher).filter(Teacher.t_phone==req['t_phone']).first()
|
||||
if exist:
|
||||
raise HTTPException(status_code=400,detail='该手机号码已存在,不可重复使用')
|
||||
t = Teacher(**req)
|
||||
db.add(t)
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500,detail=f'添加失败:{str(e)}')
|
||||
else:
|
||||
db.commit()
|
||||
return True,'添加成功'
|
||||
|
||||
def update_teachers_dao(req,db,t_id):
|
||||
try:
|
||||
db.query(Teacher).filter(Teacher.id == t_id).update(req)
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500,detail=f'更新失败:{str(e)}')
|
||||
else:
|
||||
db.commit()
|
||||
return True,'更新成功'
|
||||
|
||||
def delete_teachers_dao(t_id,db):
|
||||
try:
|
||||
r = db.query(Teacher).filter(Teacher.id == t_id).all()
|
||||
if not r:
|
||||
raise HTTPException(status_code=404,detail='记录不存在')
|
||||
for i in r:
|
||||
if i.is_delete == 0:
|
||||
db.query(Teacher).filter(Teacher.id == i.id).update({'is_delete':True})
|
||||
else:
|
||||
raise HTTPException(status_code=400,detail='该记录已删除,不可重复删除')
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500,detail=f'删除失败:{str(e)}')
|
||||
else:
|
||||
db.commit()
|
||||
return True,'删除成功'
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from fastapi import HTTPException
|
||||
from model.teaModel import Teacher
|
||||
|
||||
def get_teachers_limit_dao(p,n,db):
|
||||
if p == 0 and n == 0:
|
||||
r = db.query(Teacher).all()
|
||||
else:
|
||||
if p < 1:
|
||||
p = 1
|
||||
r = db.query(Teacher).offset((p-1)*n).limit(n).all()
|
||||
return [ {'id':i.id,'t_name':i.t_name,'t_sex':i.t_sex,'t_age':i.t_age} for i in r]
|
||||
|
||||
|
||||
def get_teachers_name_dao(name,db):
|
||||
try:
|
||||
r = db.query(Teacher).filter(Teacher.t_name==name).all()
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500, detail=f'查询失败:{str(e)}')
|
||||
else:
|
||||
return [ {'id':i.id,'t_name':i.t_name,'t_sex':i.t_sex,'t_age':i.t_age} for i in r]
|
||||
|
||||
def insert_teachers_dao(req,db):
|
||||
try:
|
||||
exist = db.query(Teacher).filter(Teacher.t_phone==req['t_phone']).first()
|
||||
if exist:
|
||||
raise HTTPException(status_code=400,detail='该手机号码已存在,不可重复使用')
|
||||
t = Teacher(**req)
|
||||
db.add(t)
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500,detail=f'添加失败:{str(e)}')
|
||||
else:
|
||||
db.commit()
|
||||
return True,'添加成功'
|
||||
|
||||
def update_teachers_dao(req,db,t_id):
|
||||
try:
|
||||
db.query(Teacher).filter(Teacher.id == t_id).update(req)
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500,detail=f'更新失败:{str(e)}')
|
||||
else:
|
||||
db.commit()
|
||||
return True,'更新成功'
|
||||
|
||||
def delete_teachers_dao(t_id,db):
|
||||
try:
|
||||
r = db.query(Teacher).filter(Teacher.id == t_id).all()
|
||||
if not r:
|
||||
raise HTTPException(status_code=404,detail='记录不存在')
|
||||
for i in r:
|
||||
if i.is_delete == 0:
|
||||
db.query(Teacher).filter(Teacher.id == i.id).update({'is_delete':True})
|
||||
else:
|
||||
raise HTTPException(status_code=400,detail='该记录已删除,不可重复删除')
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=500,detail=f'删除失败:{str(e)}')
|
||||
else:
|
||||
db.commit()
|
||||
return True,'删除成功'
|
||||
@@ -0,0 +1,9 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
|
||||
tea_url ='mysql+pymysql://root:123456@127.0.0.1:3306/ai0824_stu?charset=utf8'
|
||||
|
||||
engine = create_engine(tea_url,pool_size=100, echo=False)
|
||||
|
||||
Session = sessionmaker(bind=engine,autoflush=False,autocommit=False)
|
||||
@@ -1,45 +1,45 @@
|
||||
from sqlalchemy import *
|
||||
from datetime import datetime
|
||||
from sqlalchemy.orm import declarative_base,sessionmaker
|
||||
|
||||
db_url = "mysql+pymysql://root:123456@127.0.0.1:3306/ai0824_stu?charset=utf8"
|
||||
|
||||
engine = create_engine(db_url, pool_size=100,echo=False)
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
class Employment(Base):
|
||||
__tablename__ = 's_employment'
|
||||
id = Column(Integer
|
||||
, primary_key=True
|
||||
, autoincrement=True
|
||||
, comment='编号,自增主键')
|
||||
stu_id = Column(String(20)
|
||||
# , ForeingKey('s_student.stu_id')
|
||||
, unique=True
|
||||
, nullable=True
|
||||
, comment='学生学号,唯一')
|
||||
class_name = Column(String(32))
|
||||
company = Column(String(100))
|
||||
salary = Column(Integer
|
||||
, default=0)
|
||||
open_date = Column(DATETIME
|
||||
, default=datetime.now())
|
||||
offer_date = Column(DATETIME
|
||||
, default=datetime.now())
|
||||
work_date = Column(DATETIME
|
||||
, default=datetime.now()
|
||||
, onupdate=datetime.now)
|
||||
is_delete = Column(Integer
|
||||
, default=0
|
||||
)
|
||||
|
||||
|
||||
Session = sessionmaker( bind = engine, autoflush = False, autocommit = False )
|
||||
|
||||
def get_db():
|
||||
db = Session()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
from sqlalchemy import *
|
||||
from datetime import datetime
|
||||
from sqlalchemy.orm import declarative_base,sessionmaker
|
||||
|
||||
db_url = "mysql+pymysql://root:123456@127.0.0.1:3306/ai0824_stu?charset=utf8"
|
||||
|
||||
engine = create_engine(db_url, pool_size=100,echo=False)
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
class Employment(Base):
|
||||
__tablename__ = 's_employment'
|
||||
id = Column(Integer
|
||||
, primary_key=True
|
||||
, autoincrement=True
|
||||
, comment='编号,自增主键')
|
||||
stu_id = Column(String(20)
|
||||
# , ForeingKey('s_student.stu_id')
|
||||
, unique=True
|
||||
, nullable=True
|
||||
, comment='学生学号,唯一')
|
||||
class_name = Column(String(32))
|
||||
company = Column(String(100))
|
||||
salary = Column(Integer
|
||||
, default=0)
|
||||
open_date = Column(DATETIME
|
||||
, default=datetime.now())
|
||||
offer_date = Column(DATETIME
|
||||
, default=datetime.now())
|
||||
work_date = Column(DATETIME
|
||||
, default=datetime.now()
|
||||
, onupdate=datetime.now)
|
||||
is_delete = Column(Integer
|
||||
, default=0
|
||||
)
|
||||
|
||||
|
||||
Session = sessionmaker( bind = engine, autoflush = False, autocommit = False )
|
||||
|
||||
def get_db():
|
||||
db = Session()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
@@ -1,45 +1,45 @@
|
||||
from sqlalchemy import *
|
||||
from datetime import datetime
|
||||
from sqlalchemy.orm import declarative_base,sessionmaker
|
||||
db_url='mysql+pymysql://root:123456@127.0.0.1:3306/ai0824?charset=utf8'
|
||||
engine=create_engine(db_url , pool_size=50,echo=True)
|
||||
Base=declarative_base()
|
||||
class Scores(Base):
|
||||
__tablename__ = 's_scores'
|
||||
id=Column( Integer
|
||||
, primary_key=True
|
||||
,autoincrement=True
|
||||
,comment='成绩编号'
|
||||
)
|
||||
stu_id=Column(Integer
|
||||
,comment='学生编号'
|
||||
, nullable=False
|
||||
)
|
||||
exam_seq=Column(Integer
|
||||
|
||||
, nullable=True
|
||||
,comment='考试序次'
|
||||
)
|
||||
score=Column(Float
|
||||
,comment='分数'
|
||||
)
|
||||
create_date=Column(DATETIME
|
||||
, default=datetime.now
|
||||
,comment='创建时间'
|
||||
)
|
||||
update_date=Column(DATETIME
|
||||
, default=datetime.now
|
||||
,onupdate=datetime.now
|
||||
,comment='更新时间'
|
||||
)
|
||||
deleted=Column(Integer
|
||||
,default=1
|
||||
, comment='软删除'
|
||||
)
|
||||
Base.metadata.create_all(engine)
|
||||
Session = sessionmaker( bind=engine
|
||||
,autoflush=False
|
||||
,autocommit = False
|
||||
)
|
||||
|
||||
|
||||
from sqlalchemy import *
|
||||
from datetime import datetime
|
||||
from sqlalchemy.orm import declarative_base,sessionmaker
|
||||
db_url='mysql+pymysql://root:123456@127.0.0.1:3306/ai0824?charset=utf8'
|
||||
engine=create_engine(db_url , pool_size=50,echo=True)
|
||||
Base=declarative_base()
|
||||
class Scores(Base):
|
||||
__tablename__ = 's_scores'
|
||||
id=Column( Integer
|
||||
, primary_key=True
|
||||
,autoincrement=True
|
||||
,comment='成绩编号'
|
||||
)
|
||||
stu_id=Column(Integer
|
||||
,comment='学生编号'
|
||||
, nullable=False
|
||||
)
|
||||
exam_seq=Column(Integer
|
||||
|
||||
, nullable=True
|
||||
,comment='考试序次'
|
||||
)
|
||||
score=Column(Float
|
||||
,comment='分数'
|
||||
)
|
||||
create_date=Column(DATETIME
|
||||
, default=datetime.now
|
||||
,comment='创建时间'
|
||||
)
|
||||
update_date=Column(DATETIME
|
||||
, default=datetime.now
|
||||
,onupdate=datetime.now
|
||||
,comment='更新时间'
|
||||
)
|
||||
deleted=Column(Integer
|
||||
,default=1
|
||||
, comment='软删除'
|
||||
)
|
||||
Base.metadata.create_all(engine)
|
||||
Session = sessionmaker( bind=engine
|
||||
,autoflush=False
|
||||
,autocommit = False
|
||||
)
|
||||
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
from database import Base
|
||||
from sqlalchemy import Column,Integer,String,Date,Boolean, Enum as SQLEnum
|
||||
from enum import Enum
|
||||
class Sex(Enum):
|
||||
m= "男"
|
||||
w= "女"
|
||||
class Student(Base):
|
||||
__tablename__ = 's_student'
|
||||
id=Column(Integer, primary_key=True,autoincrement=True,comment="数据库主键id")
|
||||
stu_id=Column(String(50),unique=True,nullable=False,comment='学生id')
|
||||
class_id=Column(String(50),#ForeignKey=("s_class.class_id"),
|
||||
comment='学生班级')
|
||||
stu_name=Column(String(30),nullable=False,comment='学生姓名')
|
||||
native_place = Column(String(100), comment="籍贯")
|
||||
graduate_school = Column(String(100), comment="毕业院校")
|
||||
major = Column(String(50), comment="专业")
|
||||
enroll_date = Column(Date, comment="入学时间")
|
||||
graduate_date = Column(Date, comment="毕业时间")
|
||||
education = Column(String(30), comment="学历")
|
||||
advisor_no = Column(String(50), comment="顾问编号")
|
||||
age = Column(Integer, comment="年龄")
|
||||
gender = Column(
|
||||
SQLEnum(Sex, values_callable=lambda x: [e.value for e in x]),
|
||||
comment="性 别")
|
||||
from database import Base
|
||||
from sqlalchemy import Column,Integer,String,Date,Boolean, Enum as SQLEnum
|
||||
from enum import Enum
|
||||
class Sex(Enum):
|
||||
m= "男"
|
||||
w= "女"
|
||||
class Student(Base):
|
||||
__tablename__ = 's_student'
|
||||
id=Column(Integer, primary_key=True,autoincrement=True,comment="数据库主键id")
|
||||
stu_id=Column(String(50),unique=True,nullable=False,comment='学生id')
|
||||
class_id=Column(String(50),#ForeignKey=("s_class.class_id"),
|
||||
comment='学生班级')
|
||||
stu_name=Column(String(30),nullable=False,comment='学生姓名')
|
||||
native_place = Column(String(100), comment="籍贯")
|
||||
graduate_school = Column(String(100), comment="毕业院校")
|
||||
major = Column(String(50), comment="专业")
|
||||
enroll_date = Column(Date, comment="入学时间")
|
||||
graduate_date = Column(Date, comment="毕业时间")
|
||||
education = Column(String(30), comment="学历")
|
||||
advisor_no = Column(String(50), comment="顾问编号")
|
||||
age = Column(Integer, comment="年龄")
|
||||
gender = Column(
|
||||
SQLEnum(Sex, values_callable=lambda x: [e.value for e in x]),
|
||||
comment="性 别")
|
||||
is_deleted = Column(Boolean, default=False, comment="逻辑删除标记:False未删除,True已删除")
|
||||
@@ -1,28 +1,28 @@
|
||||
from sqlalchemy import Integer, String, Column, DateTime, Enum as SQLEnum,Boolean,create_engine
|
||||
from sqlalchemy.orm import declarative_base,sessionmaker
|
||||
|
||||
from enum import Enum
|
||||
from datetime import datetime
|
||||
|
||||
tea_url ='mysql+pymysql://root:123456@127.0.0.1:3306/ai0824_stu?charset=utf8'
|
||||
|
||||
engine = create_engine(tea_url,pool_size=100, echo=False)
|
||||
Base = declarative_base()
|
||||
class Sex(Enum):
|
||||
w = '女'
|
||||
m = '男'
|
||||
|
||||
class Teacher(Base):
|
||||
__tablename__ = 's_teacher'
|
||||
id =Column(Integer, primary_key=True,autoincrement=True)
|
||||
t_name = Column(String(100),comment='教师名称')
|
||||
t_age = Column(Integer,comment='年龄')
|
||||
t_phone = Column(String(20),unique=True,comment='电话')
|
||||
t_sex = Column(SQLEnum(Sex,values_callable=lambda x: [e.value for e in x]),comment='性别')
|
||||
class_id = Column(String(100),comment='带班编号')
|
||||
create_time = Column(DateTime,default=datetime.now,comment='创建时间')
|
||||
update_time = Column(DateTime,default=datetime.now,onupdate=datetime.now,comment='更新时间')
|
||||
is_delete = Column(Boolean,default=False,comment='判断是否删除')
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
from sqlalchemy import Integer, String, Column, DateTime, Enum as SQLEnum,Boolean,create_engine
|
||||
from sqlalchemy.orm import declarative_base,sessionmaker
|
||||
|
||||
from enum import Enum
|
||||
from datetime import datetime
|
||||
|
||||
tea_url ='mysql+pymysql://root:123456@127.0.0.1:3306/ai0824_stu?charset=utf8'
|
||||
|
||||
engine = create_engine(tea_url,pool_size=100, echo=False)
|
||||
Base = declarative_base()
|
||||
class Sex(Enum):
|
||||
w = '女'
|
||||
m = '男'
|
||||
|
||||
class Teacher(Base):
|
||||
__tablename__ = 's_teacher'
|
||||
id =Column(Integer, primary_key=True,autoincrement=True)
|
||||
t_name = Column(String(100),comment='教师名称')
|
||||
t_age = Column(Integer,comment='年龄')
|
||||
t_phone = Column(String(20),unique=True,comment='电话')
|
||||
t_sex = Column(SQLEnum(Sex,values_callable=lambda x: [e.value for e in x]),comment='性别')
|
||||
class_id = Column(String(100),comment='带班编号')
|
||||
create_time = Column(DateTime,default=datetime.now,comment='创建时间')
|
||||
update_time = Column(DateTime,default=datetime.now,onupdate=datetime.now,comment='更新时间')
|
||||
is_delete = Column(Boolean,default=False,comment='判断是否删除')
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
Session = sessionmaker(bind=engine,autoflush=False,autocommit=False)
|
||||
@@ -1,13 +1,13 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
|
||||
class EmploymentRequest(BaseModel):
|
||||
stu_id: str|None = None
|
||||
class_name: str|None = None
|
||||
company: Optional[str] = None
|
||||
salary: Optional[int] = None
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
|
||||
class EmploymentRequest(BaseModel):
|
||||
stu_id: str|None = None
|
||||
class_name: str|None = None
|
||||
company: Optional[str] = None
|
||||
salary: Optional[int] = None
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pydantic import BaseModel
|
||||
class Test(BaseModel):
|
||||
stu_id:int
|
||||
exam_seq:int
|
||||
score:float
|
||||
from pydantic import BaseModel
|
||||
class Test(BaseModel):
|
||||
stu_id:int
|
||||
exam_seq:int
|
||||
score:float
|
||||
@@ -1,58 +1,58 @@
|
||||
from typing import Optional,List
|
||||
from pydantic import BaseModel,Field
|
||||
from datetime import date
|
||||
from model.student_model import Sex
|
||||
##================ =====请求体===============
|
||||
class StudentCreateRequest(BaseModel):
|
||||
stu_id:str=Field(...,description="学生id")
|
||||
class_id:Optional[str]=Field(None,description="学生班级id")
|
||||
stu_name: str = Field(..., description="学生姓名")
|
||||
native_place: Optional[str] = Field(None, description="籍贯")
|
||||
graduate_school: Optional[str] = Field(None, description="毕业院校")
|
||||
major: Optional[str] = Field(None, description="专业")
|
||||
enroll_date: Optional[date] = Field(None, description="入学时间")
|
||||
graduate_date: Optional[date] = Field(None, description="毕业时间")
|
||||
education: Optional[str] = Field(None, description="学历")
|
||||
advisor_no: Optional[str] = Field(None, description="顾问编号")
|
||||
age: Optional[int] = Field(None, ge=0, description="年龄,不能负数")
|
||||
gender: Optional[Sex] = Field(None, description="性别")
|
||||
class StudentUpdateRequest(BaseModel):
|
||||
stu_id:Optional[str]=None#学生id
|
||||
class_id: Optional[str] = None # 学生班级
|
||||
stu_name: Optional[str] = None # 学生姓名
|
||||
native_place: Optional[str] = None # 籍贯
|
||||
graduate_school: Optional[str] = None # 毕业院校
|
||||
major: Optional[str] = None # 专业
|
||||
enroll_date: Optional[date] = None # 入学时间
|
||||
graduate_date: Optional[date] = None # 毕业时间
|
||||
education: Optional[str] = None # 学历
|
||||
advisor_no: Optional[str] = None # 顾问编号
|
||||
age: Optional[int] = Field(None, ge=0) # 年龄,不能负数
|
||||
gender: Optional[Sex] = Field(None, description="性别") # 性别'''
|
||||
class StudentQuery(BaseModel):
|
||||
stu_id: Optional[str] = None # 学生编号筛选
|
||||
stu_name: Optional[str] = None # 学生姓名筛选
|
||||
class_id: Optional[str] = None # 班级筛选
|
||||
page: int = Field(1, ge=1, description="页码,默认第1页")
|
||||
page_size: int = Field(10, ge=1, le=100, description="每页条数,默认10条")
|
||||
##=====================响应体===============
|
||||
class StudentResponse(BaseModel):
|
||||
stu_id: str# 学生编号
|
||||
class_id: Optional[str]# 学生班级
|
||||
stu_name: str# 学生姓名
|
||||
native_place: Optional[str] # 籍贯
|
||||
graduate_school: Optional[str] # 毕业院校
|
||||
major: Optional[str]# 专业
|
||||
enroll_date: Optional[date] # 入学时间
|
||||
graduate_date: Optional[date] # 毕业时间
|
||||
education: Optional[str] # 学历
|
||||
advisor_no: Optional[str]# 顾问编号
|
||||
age: Optional[int]# 年龄
|
||||
gender: Optional[Sex] = Field(None, description="性别")# 性别
|
||||
is_deleted: bool# 逻辑删除标记
|
||||
# 分页列表响应体:查询学生列表时返回
|
||||
class StudentPageResponse(BaseModel):
|
||||
total: int# 符合条件的总记录数
|
||||
page: int# 当前页码
|
||||
page_size: int# 每页数据条数
|
||||
from typing import Optional,List
|
||||
from pydantic import BaseModel,Field
|
||||
from datetime import date
|
||||
from model.student_model import Sex
|
||||
##================ =====请求体===============
|
||||
class StudentCreateRequest(BaseModel):
|
||||
stu_id:str=Field(...,description="学生id")
|
||||
class_id:Optional[str]=Field(None,description="学生班级id")
|
||||
stu_name: str = Field(..., description="学生姓名")
|
||||
native_place: Optional[str] = Field(None, description="籍贯")
|
||||
graduate_school: Optional[str] = Field(None, description="毕业院校")
|
||||
major: Optional[str] = Field(None, description="专业")
|
||||
enroll_date: Optional[date] = Field(None, description="入学时间")
|
||||
graduate_date: Optional[date] = Field(None, description="毕业时间")
|
||||
education: Optional[str] = Field(None, description="学历")
|
||||
advisor_no: Optional[str] = Field(None, description="顾问编号")
|
||||
age: Optional[int] = Field(None, ge=0, description="年龄,不能负数")
|
||||
gender: Optional[Sex] = Field(None, description="性别")
|
||||
class StudentUpdateRequest(BaseModel):
|
||||
stu_id:Optional[str]=None#学生id
|
||||
class_id: Optional[str] = None # 学生班级
|
||||
stu_name: Optional[str] = None # 学生姓名
|
||||
native_place: Optional[str] = None # 籍贯
|
||||
graduate_school: Optional[str] = None # 毕业院校
|
||||
major: Optional[str] = None # 专业
|
||||
enroll_date: Optional[date] = None # 入学时间
|
||||
graduate_date: Optional[date] = None # 毕业时间
|
||||
education: Optional[str] = None # 学历
|
||||
advisor_no: Optional[str] = None # 顾问编号
|
||||
age: Optional[int] = Field(None, ge=0) # 年龄,不能负数
|
||||
gender: Optional[Sex] = Field(None, description="性别") # 性别'''
|
||||
class StudentQuery(BaseModel):
|
||||
stu_id: Optional[str] = None # 学生编号筛选
|
||||
stu_name: Optional[str] = None # 学生姓名筛选
|
||||
class_id: Optional[str] = None # 班级筛选
|
||||
page: int = Field(1, ge=1, description="页码,默认第1页")
|
||||
page_size: int = Field(10, ge=1, le=100, description="每页条数,默认10条")
|
||||
##=====================响应体===============
|
||||
class StudentResponse(BaseModel):
|
||||
stu_id: str# 学生编号
|
||||
class_id: Optional[str]# 学生班级
|
||||
stu_name: str# 学生姓名
|
||||
native_place: Optional[str] # 籍贯
|
||||
graduate_school: Optional[str] # 毕业院校
|
||||
major: Optional[str]# 专业
|
||||
enroll_date: Optional[date] # 入学时间
|
||||
graduate_date: Optional[date] # 毕业时间
|
||||
education: Optional[str] # 学历
|
||||
advisor_no: Optional[str]# 顾问编号
|
||||
age: Optional[int]# 年龄
|
||||
gender: Optional[Sex] = Field(None, description="性别")# 性别
|
||||
is_deleted: bool# 逻辑删除标记
|
||||
# 分页列表响应体:查询学生列表时返回
|
||||
class StudentPageResponse(BaseModel):
|
||||
total: int# 符合条件的总记录数
|
||||
page: int# 当前页码
|
||||
page_size: int# 每页数据条数
|
||||
items: List[StudentResponse] # 当前页学生数据列表
|
||||
@@ -1,16 +1,16 @@
|
||||
from pydantic import BaseModel,Field
|
||||
from model.teaModel import Sex
|
||||
|
||||
|
||||
class RequestModel(BaseModel):
|
||||
t_name: str=Field(min_length=2,max_length=20)
|
||||
t_sex:Sex
|
||||
t_age: int=Field(gt=0)
|
||||
t_phone: str=Field(min_length=11)
|
||||
class_id: str
|
||||
|
||||
class ResponseModel(BaseModel):
|
||||
code: int = 200
|
||||
msg: str = '操作成功'
|
||||
total: int = 0
|
||||
data: list=Field(default=[])
|
||||
from pydantic import BaseModel,Field
|
||||
from model.teaModel import Sex
|
||||
|
||||
|
||||
class RequestModel(BaseModel):
|
||||
t_name: str=Field(min_length=2,max_length=20)
|
||||
t_sex:Sex
|
||||
t_age: int=Field(gt=0)
|
||||
t_phone: str=Field(min_length=11)
|
||||
class_id: str
|
||||
|
||||
class ResponseModel(BaseModel):
|
||||
code: int = 200
|
||||
msg: str = '操作成功'
|
||||
total: int = 0
|
||||
data: list=Field(default=[])
|
||||
Reference in New Issue
Block a user