Compare commits

...
6 Commits
Author SHA1 Message Date
msj 1b5f985b7f Merge remote-tracking branch 'origin/conding' into conding 2026-09-21 11:44:19 +08:00
msj 1837764dd2 text 2026-09-21 11:43:34 +08:00
msj a775a1a334 Merge remote-tracking branch 'origin/conding' into conding 2026-09-21 11:27:24 +08:00
msj 6cc776899f Merge remote-tracking branch 'origin/conding' into conding 2026-09-21 11:21:33 +08:00
msj 29fe223a74 Merge remote-tracking branch 'origin/conding' into conding
# Conflicts:
#	PythonProject/dao/student_dao.py
2026-09-21 09:56:46 +08:00
msj 8626f57db5 text 2026-09-21 09:39:28 +08:00
3 changed files with 71 additions and 20 deletions
+37 -4
View File
@@ -1,11 +1,44 @@
from fastapi import APIRouter
from dao.student_dao import select_age
from fastapi import APIRouter,Depends,HTTPException
from schema.student_schema import StudentResponse
from dao.student_dao import delete_student_dao,add_student_dao,update_student_dao,get_student_dao,select_age
from schema.student_schema import StudentRequest,StudentResponse
from model.student_model import Student_Model
from util.database import get_db
studentapi = APIRouter()
@studentapi.get("/age",response_model=StudentResponse,tags=['统计分析模块'],description='根据年龄查询学生信息')
StudentAPI = APIRouter()
@StudentAPI.get("/age",response_model=StudentResponse,tags=['统计分析模块'],description='根据年龄查询学生信息')
def get_students(min_age:int|None=None,max_age:int|None=None):
l = select_age(min_age,max_age)
return [i for i in l]
@StudentAPI.get('',description='查询学生信息')
def get_students(stu_id:int|None=None
,stu_name:str|None=None
,class_id:int|None=None
,db=Depends(get_db)
,page:int=1
,page_size:int=10):
r=get_student_dao(stu_id,stu_name,class_id,db,page,page_size)
if r:
return r
raise HTTPException(status_code=404,detail='学生不存在')
@StudentAPI.put('/{stu_id}')
def update_orders(s:StudentRequest,stu_id:int,db=Depends(get_db)):
d = s.model_dump(exclude_unset=True)
r = update_student_dao( stu_id=stu_id,update_data=d,db=db )
if not r:
raise HTTPException(status_code=500, detail='没有更新!')
return {'code':200,'totals':r,'detail':'更新成功'}
@StudentAPI.delete('/{stu_id}')
def del_student(stu_id:int,db=Depends(get_db)):
rows=delete_student_dao( stu_id=stu_id,db=db )
if not rows:
raise HTTPException(status_code=500,detail='没有删除')
return {'code':200,'totals':rows,'detail':'删除成功'}
+30 -12
View File
@@ -9,49 +9,65 @@ def select_age(min_age,max_age,session=Depends(get_db)):
raise HTTPException(status_code=400, detail="请至少传入一个参数")
session = session.query(Student_Model)
if min_age is not None:
session = session.filter(Student_Model.age >= min_age)
session = session.filter(Student_Model.age >= min_age,Student_Model.delete_status == 0)
if max_age is not None:
session = session.filter(Student_Model.age <= max_age)
session = session.filter(Student_Model.age <= max_age,Student_Model.delete_status == 0)
return session.all()
except HTTPException:
raise
except Exception:
raise HTTPException(status_code=500,detail="查询异常")
def delete_student_dao(stu_id,db):
def add_student_dao(o,db=Depends(get_db)):
try:
rows = db.query(Student_Model).filter(Student_Model.stu_id == stu_id).delete()
r = db.query(Student_Model).filter(Student_Model.stu_id == o['stu_id'],Student_Model.delete_status == 0).all()
if not r:
o1 = Student_Model( **o)
db.add(o1)
else:
raise ValueError
except:
db.rollback()
return False
else:
db.commit()
return True
def delete_student_dao(stu_id,db=Depends(get_db)):
try:
rows = db.query(Student_Model).filter(Student_Model.stu_id == stu_id,Student_Model.delete_status == 0).delete()
Student_Model.delete_status = 1
db.commit()
except:
db.rollback()
rows = 0
else:
db.commit()
finally:
return rows
def update_student_dao(stu_id,update_data,db):
def update_student_dao(stu_id,update_data,db=Depends(get_db)):
try:
rows = db.query( Student_Model ).filter( Student_Model.stu_id == stu_id ).update( update_data )
rows = db.query( Student_Model ).filter( Student_Model.stu_id == stu_id,Student_Model.delete_status == 0).update( update_data )
except:
db.rollback()
return False
else:
db.commit()
return rows
def get_student_dao(stu_id:Optional[int]
,stu_name:Optional[str]
,class_id:Optional[int]
,db: Session
,page: int
,page_size: int
,db=Depends(get_db)
) -> tuple[List[Dict[str, Any]], int]:
q = db.query(Student_Model)
if stu_id:
q = q.filter(Student_Model.stu_id == stu_id)
q = q.filter(Student_Model.stu_id == stu_id,Student_Model.delete_status == 0)
if stu_name:
q = q.filter(Student_Model.stu_name.like(f"%{stu_name}%"))
q = q.filter(Student_Model.stu_name.like(f"%{stu_name}%"),Student_Model.delete_status == 0)
if class_id:
q= q.filter(Student_Model.class_id == class_id)
q= q.filter(Student_Model.class_id == class_id,Student_Model.delete_status == 0)
total = q.count()
r = q.offset((page - 1) * page_size).limit(page_size).all()
data = []
@@ -63,3 +79,5 @@ def get_student_dao(stu_id:Optional[int]
,'update_date': i.update_date
})
return data, total
+4 -4
View File
@@ -23,10 +23,10 @@ dao层(每一个功能就是一个函数,判断能否功能复用)
通用模块
学生模块
实现增加学生的功能 **xxx 做成中**
实现查询学生的功能:需要能进行多条件查询 **xxx 做成中**
实现更新学生信息的功能 **xxx 做成中**
实现删除学生信息的功能 (更新删除状态这个列,即软删除)**xxx 做成中**
实现增加学生的功能 **msj 做成中**
实现查询学生的功能:需要能进行多条件查询 **msj 做成中**
实现更新学生信息的功能 **msj 做成中**
实现删除学生信息的功能 (更新删除状态这个列,即软删除)**msj 做成中**
成绩模块
实现增加学生成绩的功能 **hzl 做成中**