Merge remote-tracking branch 'origin/conding' into conding
This commit is contained in:
@@ -1,40 +1,46 @@
|
||||
|
||||
from fastapi import HTTPException,Depends
|
||||
from model.all_model import Employment_info, ClassManagement, Student_Model
|
||||
from util.database import get_db
|
||||
from schema.employment_schema import EmlpoymentRequest
|
||||
from schema.employment_schema import EmploymentRequest
|
||||
|
||||
def get_employment_dao(stu_id,class_id,db):
|
||||
q = db.query(Employment_info).\
|
||||
join(ClassManagement,ClassManagement.stu_id == Employment_info.stu_id).\
|
||||
filter(Employment_info.delete_status == 0).\
|
||||
filter(Student_Model.delete_status == 0).\
|
||||
filter(ClassManagement.delete_status == 0)
|
||||
if stu_id is not None:
|
||||
q = q.filter(Employment_info.stu_id == stu_id)
|
||||
if class_id is not None:
|
||||
q = q.filter(ClassManagement.class_id == class_id)
|
||||
r = q.all()
|
||||
if r:
|
||||
return [{'emp_id':i.emp_id
|
||||
,'stu_id': i.stu_id
|
||||
,'stu_name':i.stu_name
|
||||
,'class_id':i.class_id
|
||||
,'email':i.email
|
||||
,'employment_opening_date':i.employment_opening_date
|
||||
,'offer_issuance_date':i.offer_issuance_date
|
||||
,'company_name':i.company_name
|
||||
,'company_address':i.company_address
|
||||
,'salary':i.salary
|
||||
}for i in r
|
||||
]
|
||||
|
||||
def add_employment_dao(e:EmlpoymentRequest,db,stu_id):
|
||||
def get_employment_dao(stu_id,class_id,db=Depends(get_db())):
|
||||
try:
|
||||
e1 = Employment_info(**e)
|
||||
db.add(e1)
|
||||
q = db.query(Employment_info).\
|
||||
join(Student_Model,Employment_info.stu_id == Student_Model.stu_id).\
|
||||
join(ClassManagement,Student_Model.class_id == ClassManagement.class_id).\
|
||||
filter(Employment_info.delete_status == 0).\
|
||||
filter(Student_Model.delete_status == 0).\
|
||||
filter(ClassManagement.delete_status == 0)
|
||||
if stu_id is not None:
|
||||
q = q.filter(Employment_info.stu_id == stu_id)
|
||||
if class_id is not None:
|
||||
q = q.filter(ClassManagement.class_id == class_id)
|
||||
r = q.all()
|
||||
if r:
|
||||
return [{'emp_id':i.emp_id
|
||||
,'stu_id': i.stu_id
|
||||
,'stu_name':i.stu_name
|
||||
,'class_id':i.class_id
|
||||
,'email':i.email
|
||||
,'employment_opening_date':i.employment_opening_date
|
||||
,'offer_issuance_date':i.offer_issuance_date
|
||||
,'company_name':i.company_name
|
||||
,'company_address':i.company_address
|
||||
,'salary':i.salary
|
||||
}for i in r
|
||||
]
|
||||
except:
|
||||
db.rollback()
|
||||
return False
|
||||
else:
|
||||
db.commit()
|
||||
return True
|
||||
raise HTTPException(status_code=404,detail='信息不存在!')
|
||||
|
||||
# def add_employment_dao(e:EmlpoymentRequest,db=Depends(get_db()),stu_id):
|
||||
# try:
|
||||
# r = db.query(Employment_info).filter(Employment_info.stu_id == stu_id).all()
|
||||
# if r:
|
||||
# e1 = Employment_info(**e)
|
||||
# db.add(e1)
|
||||
# except:
|
||||
# db.rollback()
|
||||
# return False
|
||||
# else:
|
||||
# db.commit()
|
||||
# return True
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from fastapi import HTTPException,Depends
|
||||
from fastapi import HTTPException
|
||||
from sqlalchemy import func
|
||||
from model.all_model import Student_Model,WlScore
|
||||
from util.database import get_db
|
||||
from model.all_model import Student_Model,WlScore,Employment_info
|
||||
|
||||
# 实现根据年龄查询学生信息的功能
|
||||
def select_age(min_age,max_age,db):
|
||||
@@ -23,7 +22,8 @@ def select_age(min_age,max_age,db):
|
||||
# 实现统计每个班级的学员总数以及男女生的总数的功能
|
||||
def select_all(db):
|
||||
try:
|
||||
l1 = db.query(Student_Model.class_id,Student_Model.gender,func.count(1)).group_by(Student_Model.class_id,Student_Model.gender).all()
|
||||
l1 = db.query(Student_Model.class_id,Student_Model.gender,func.count(1).label('cnt'))\
|
||||
.group_by(Student_Model.class_id,Student_Model.gender).all()
|
||||
return l1
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
@@ -34,7 +34,8 @@ def select_score(min_score,max_score,db):
|
||||
if min_score is None and max_score is None:
|
||||
raise HTTPException(status_code=400, detail="请至少传入一个参数")
|
||||
db = db.query(Student_Model,WlScore.score,WlScore.score)\
|
||||
.join(WlScore,WlScore.stu_id == Student_Model.stu_id,WlScore.delete_status==0,WlScore.delete_status == 0)
|
||||
.join(WlScore,WlScore.stu_id == Student_Model.stu_id)\
|
||||
.filter(WlScore.delete_status==0,Student_Model.delete_status == 0)
|
||||
if min_score is not None:
|
||||
db = db.filter(WlScore.score >= min_score)
|
||||
if min_score is not None:
|
||||
@@ -45,3 +46,48 @@ def select_score(min_score,max_score,db):
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
|
||||
# 实现统计每次考试每个班级的平均分并排序的功能
|
||||
def select_avg_score(db):
|
||||
try:
|
||||
l1 = db.query(Student_Model.class_id,func.avg(WlScore.score).label('avg_score'))\
|
||||
.join(Student_Model,WlScore.stu_id == Student_Model.stu_id)\
|
||||
.filter(WlScore.delete_status==0,Student_Model.delete_status == 0)\
|
||||
.group_by(Student_Model.class_id)\
|
||||
.order_by(func.avg(WlScore.score)).all()
|
||||
return l1
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
|
||||
# 实现统计薪资最高的前五名的学员信息
|
||||
def select_salary(db):
|
||||
try:
|
||||
l1 = db.query(Student_Model,Employment_info.salary)\
|
||||
.join(Employment_info,Employment_info.stu_id==Student_Model.stu_id)\
|
||||
.filter(Employment_info.delete_status==0,Student_Model.delete_status == 0)\
|
||||
.order_by(Employment_info.salary.desc())\
|
||||
.limit(5).all()
|
||||
return l1
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500,detail="查询异常")
|
||||
|
||||
# 实现统计每个班级的平均就业时长
|
||||
def select_days(db):
|
||||
try:
|
||||
l1 = db.query(Student_Model.class_id,
|
||||
func.coalesce(
|
||||
func.avg(
|
||||
func.datediff(
|
||||
Employment_info.offer_issuance_date, Employment_info.employment_opening_date
|
||||
)
|
||||
),0).label("avg_days")
|
||||
).join(Employment_info,Employment_info.stu_id == Student_Model.stu_id)\
|
||||
.filter(Student_Model.delete_status == 0,
|
||||
Employment_info.delete_status == 0,
|
||||
Employment_info.employment_opening_date.isnot(None),
|
||||
Employment_info.offer_issuance_date.isnot(None),)\
|
||||
.group_by( Student_Model.class_id)\
|
||||
.order_by(func.avg(func.datediff(Employment_info.offer_issuance_date,Student_Model.admission_date)).desc()).all()
|
||||
return l1
|
||||
except Exception:
|
||||
raise HTTPException(status_code=500, detail="查询异常")
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from util.database import get_db
|
||||
from model.all_model import Student_Model
|
||||
from typing import List, Optional, Dict, Any
|
||||
|
||||
def add_student_dao(o,db=Depends(get_db)):
|
||||
def add_student_dao(o,db):
|
||||
try:
|
||||
o1 = Student_Model( **o)
|
||||
db.add(o1)
|
||||
@@ -14,7 +14,7 @@ def add_student_dao(o,db=Depends(get_db)):
|
||||
db.commit()
|
||||
return True
|
||||
|
||||
def delete_student_dao(stu_id,db=Depends(get_db)):
|
||||
def delete_student_dao(stu_id,db):
|
||||
try:
|
||||
rows = db.query(Student_Model).filter(Student_Model.stu_id == stu_id,Student_Model.delete_status == 0)\
|
||||
.update({'delete_status':1})
|
||||
@@ -25,7 +25,7 @@ def delete_student_dao(stu_id,db=Depends(get_db)):
|
||||
finally:
|
||||
return rows
|
||||
|
||||
def update_student_dao(stu_id,update_data,db=Depends(get_db)):
|
||||
def update_student_dao(stu_id,update_data,db):
|
||||
try:
|
||||
rows = db.query( Student_Model ).filter( Student_Model.stu_id == stu_id,Student_Model.delete_status == 0).update( update_data )
|
||||
except:
|
||||
@@ -40,16 +40,19 @@ def get_student_dao(stu_id:Optional[int]
|
||||
,class_id:Optional[int]
|
||||
,page: int
|
||||
,page_size: int
|
||||
,db=Depends(get_db)
|
||||
,db
|
||||
) -> tuple[List[Dict[str, Any]], int]:
|
||||
q = db.query(Student_Model)
|
||||
if 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}%"),Student_Model.delete_status == 0)
|
||||
if 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()
|
||||
|
||||
return r
|
||||
try:
|
||||
q = db.query(Student_Model)
|
||||
if stu_id:
|
||||
q = q.filter(Student_Model.stu_id == stu_id,Student_Model.delete_status == 0)
|
||||
if stu_name and stu_name.strip() != "":
|
||||
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,Student_Model.delete_status == 0)
|
||||
total = q.count()
|
||||
r = q.offset((page - 1) * page_size).limit(page_size).all()
|
||||
return total,r
|
||||
except:
|
||||
db.rollback()
|
||||
return [],0
|
||||
|
||||
@@ -1,25 +1,31 @@
|
||||
from fastapi import HTTPException,Depends
|
||||
from model.all_model import Teacher_Model
|
||||
from util.database import *
|
||||
from schema.teacher_schema import Teacher_RequestModel
|
||||
from model.all_model import *
|
||||
|
||||
def add_teacher(req:Teacher_RequestModel,session):
|
||||
def add_teacher(teacher,session):
|
||||
try:
|
||||
data=req.model_dump()
|
||||
session.add(Teacher_Model(**data))
|
||||
print(teacher)
|
||||
x=Teacher_Model(**teacher)
|
||||
print(1)
|
||||
session.add(x)
|
||||
print(2)
|
||||
session.commit()
|
||||
print(3)
|
||||
return teacher
|
||||
except:
|
||||
raise HTTPException(status_code=500,detail="添加异常!")
|
||||
return req.model_dump()
|
||||
session.rollback()
|
||||
# raise HTTPException(status_code=500,detail='添加异常!')
|
||||
return None
|
||||
|
||||
def get_teacher(session):
|
||||
try:
|
||||
teacher_list=session.query(Teacher_Model).filter(Teacher_Model.delete_status==0).all()
|
||||
return teacher_list
|
||||
except:
|
||||
raise HTTPException(status_code=500,detail="查询异常!")
|
||||
def get_teacher(id,session):
|
||||
l=session.query(Teacher_Model).filter(Teacher_Model.teac_id==id)\
|
||||
.filter(Teacher_Model.delete_status==0).all()
|
||||
if l:
|
||||
return l
|
||||
else:
|
||||
raise HTTPException(status_code=404,detail='该老师不存在!')
|
||||
|
||||
def update_teacher(id:int,req:Teacher_RequestModel,session):
|
||||
def update_teacher(teac_id:int,req:Teacher_RequestModel,session):
|
||||
try:
|
||||
session.query(Teacher_Model).filter(Teacher_Model.teac_id==id)\
|
||||
.filter(Teacher_Model.delete_status==0).update(req.model_dump(exclude_unset=True))
|
||||
|
||||
Reference in New Issue
Block a user