bug修改
This commit is contained in:
+2
-2
@@ -11,7 +11,7 @@ from sqlalchemy.orm import Session
|
||||
statistics_router=APIRouter()
|
||||
|
||||
|
||||
@statistics_router.get("/scores/age-over-30",response_model=SuccessResponse)
|
||||
@statistics_router.get("/students/age-over-30",response_model=SuccessResponse)
|
||||
def api_age_over_thirty(db:Session=Depends(get_db)):
|
||||
try:
|
||||
age_over_thirty_list=age_over_thirty(Student,db)
|
||||
@@ -71,7 +71,7 @@ def employ_time(db:Session=Depends(get_db)):
|
||||
@statistics_router.get("/employments/class-average-duration",response_model=SuccessResponse)
|
||||
def avg_employ_time(db:Session=Depends(get_db)):
|
||||
try:
|
||||
result = avg_class(Employment,Student,db)
|
||||
result = avg_emptime(Employment,Student,db)
|
||||
return SuccessResponse(status_code=200,msg=result)
|
||||
except NoExist as e:
|
||||
raise HTTPException(status_code=404,detail=str(e))
|
||||
|
||||
+13
-10
@@ -5,25 +5,28 @@ from time import time
|
||||
#查询所有超过 30 岁的学员信息
|
||||
|
||||
def age_over_thirty(Student,db):
|
||||
student_list=db.query(Student).filter(Student.age>=30).all()
|
||||
student_list=db.query(Student).filter(Student.age>30,Student.is_delted==0).all()
|
||||
if not student_list :
|
||||
raise NoExist('无目标年龄大于30岁')
|
||||
return student_list
|
||||
|
||||
def gender_count(Student,db):
|
||||
result=db.query(Student.class_id,Student.gender,func.count(Student.id)).group_by(Student.class_id,Student.gender).all()
|
||||
result=db.query(Student.class_id,Student.gender,func.count(Student.id)).filter(Student.is_deleted==0).group_by(Student.class_id,Student.gender).all()
|
||||
if not result :
|
||||
raise NoExist('班里招点人吧,要倒闭了')
|
||||
dict1 = {}
|
||||
sum_stu = 0
|
||||
for i,j,k in result:
|
||||
if i not in dict1 :
|
||||
dict1[i]={'男':0,'女':0}
|
||||
dict[i][j]+=k
|
||||
dict1[i][j]+=k
|
||||
sum_stu+=k
|
||||
dict1['总人数'] = sum_stu
|
||||
return dict1
|
||||
#查询每次考试成绩都在 80 分以上的学生编号、姓名和成绩
|
||||
def score_over_eighty(Score,Student,db):
|
||||
student_list=db.query(Student.id, Student.student_name)\
|
||||
.join(Score,Score.student_id==Student.id).group_by(Student.student_no,Student.student_name)\
|
||||
.join(Score,Score.student_id==Student.id).filter(Student.is_deleted==0,Score.is_deleted==0).group_by(Student.student_id,Student.student_name)\
|
||||
.having(func.min(Score.score)>80).all()
|
||||
if not student_list :
|
||||
raise NoExist('全是学渣')
|
||||
@@ -35,26 +38,26 @@ def score_over_eighty(Score,Student,db):
|
||||
return list1
|
||||
#查询有两次以上不及格的学生姓名、班级和不及格成绩
|
||||
def twice_error(Score,Student,db):
|
||||
student_list=db.query(Score.student_id).filter(Score.score<60).group_by(Score.student_id).having(func.count(Score.id)>1).all()
|
||||
student_list=db.query(Score.student_id).filter(Score.score<60,Score.is_deleted==0).group_by(Score.student_id).having(func.count(Score.id)>2).all()
|
||||
if not student_list :
|
||||
raise NoExist('全是学霸')
|
||||
list1=[]
|
||||
for i in student_list:
|
||||
result=db.query(Student.student_name,Student.class_id,Score.score).join(Score, Student.id==Score.student_id)\
|
||||
.filter(i.student_id==Score.student_id,Score.score<60).all()
|
||||
.filter(i.student_id==Score.student_id,Score.score<60,Student.is_deleted==0,Score.is_deleted==0).all()
|
||||
list1.extend(result)
|
||||
return list1
|
||||
|
||||
#统计每次考试每个班级的平均分,并按照平均分从高到低排序
|
||||
def avg_class(Score,Student,db):
|
||||
student_list = db.query(Student.class_id,Score.exam_seq,func.avg(Score.score)).join(Score, Student.id == Score.student_id).group_by(Student.class_id,Score.exam_seq).order_by(func.avg(Score.score).desc()).all()
|
||||
student_list = db.query(Student.class_id,Score.exam_seq,func.avg(Score.score)).join(Score, Student.id == Score.student_id).filter(Score.is_deleted==0,Student.is_deleted==0).group_by(Student.class_id,Score.exam_seq).order_by(func.avg(Score.score).desc()).all()
|
||||
if not student_list :
|
||||
raise NoExist('招个人吧')
|
||||
return student_list
|
||||
|
||||
#统计就业薪资最高的前五名学生姓名、班级、就业时间、就业公司
|
||||
def max_salary(Student,Employment,db):
|
||||
student_list = db.query(Student.student_name,Student.class_id,Employment.offer_date,Employment.company_name).join(Employment, Student.id == Employment.student_id).order_by(Employment.salary_max.desc()).limit(5).all()
|
||||
student_list = db.query(Student.student_name,Student.class_id,Employment.offer_date,Employment.company_name).join(Employment, Student.id == Employment.student_id).filter(Student.is_deleted==0,Employment.is_deleted==0).order_by(Employment.salary.desc()).limit(5).all()
|
||||
if not student_list :
|
||||
raise NoExist('没就业的啊兄弟?')
|
||||
return student_list
|
||||
@@ -62,7 +65,7 @@ def max_salary(Student,Employment,db):
|
||||
# - 统计每个学生的就业时长
|
||||
# - 就业时长 = `offer_date - employment_open_date`
|
||||
def student_market(Employment,db):
|
||||
student_list = db.query(Employment.student_id,func.datediff(Employment.offer_date,Employment.employment_open_date)).all()
|
||||
student_list = db.query(Employment.student_id,func.datediff(Employment.offer_date,Employment.employment_open_date)).filter(Employment.is_deleted==0).all()
|
||||
return student_list
|
||||
|
||||
# - 统计每个班级的平均就业时长
|
||||
@@ -70,7 +73,7 @@ def student_market(Employment,db):
|
||||
def avg_emptime(Employment,Student,db):
|
||||
student_list = (db.query(Student.class_id,\
|
||||
func.avg(func.datediff(Employment.offer_date,Employment.employment_open_date)))\
|
||||
.join(Employment, Student.id==Employment.student_id).filter(Employment.employment_open_date.is_not(None)))\
|
||||
.join(Employment, Student.id==Employment.student_id).filter(Student.is_deleted==0,Employment.is_deleted==0,Employment.employment_open_date.is_not(None)))\
|
||||
.group_by(Student.class_id).all()
|
||||
if not student_list :
|
||||
raise NoExist('一个就业都没有吗')
|
||||
|
||||
@@ -34,7 +34,7 @@ def add_student(
|
||||
|
||||
|
||||
|
||||
def generate_no(field_name: str, prefix: str, db_object, db: Session):
|
||||
def generate_no(field_name: str, prefix: str, db_object, db):
|
||||
if getattr(db_object, field_name):
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user