From 38b95eadf8a1eb5475ec629efc069506435969ee Mon Sep 17 00:00:00 2001 From: Orangeeee Date: Wed, 23 Sep 2026 02:19:58 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D=EF=BC=8C=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E6=B5=8B=E8=AF=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StatCalc/dao/statcalc_dao.py | 21 ++++++++++----------- seed_data.py | 14 +++++++------- stu_jiuye/dao.py | 2 +- students/StudentsQuery.sql | 4 +++- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/StatCalc/dao/statcalc_dao.py b/StatCalc/dao/statcalc_dao.py index 6d23b76..36943c4 100644 --- a/StatCalc/dao/statcalc_dao.py +++ b/StatCalc/dao/statcalc_dao.py @@ -17,23 +17,22 @@ from class_management.model.class_management_model import ClassInfo def get_class_count(g , db): if g == "班级人数": - q = (db.query(ClassInfo.id,ClassInfo.name,func.count(ClassInfo.id) ) + q = (db.query(ClassInfo.id,ClassInfo.name,func.count(ClassInfo.id).label('count') ) .join(Students,Students.class_id==ClassInfo.id) .group_by(ClassInfo.id,ClassInfo.name,Students.sex) .all()) elif g == "男女人数": - q = (db.query(Students.sex,func.count(ClassInfo.id) ) - .join(Students,Students.class_id==ClassInfo.id) - .group_by(Students.sex) - .all()) + q = (db.query(Students.sex, func.count(Students.id).label('count')) + .group_by(Students.sex) + .all()) elif g == "班级中男女人数": - q = (db.query(ClassInfo.id,ClassInfo.name,Students.sex,func.count(ClassInfo.id) ) + q = (db.query(ClassInfo.id,ClassInfo.name,Students.sex,func.count(ClassInfo.id).label('count') ) .join(Students,Students.class_id==ClassInfo.id) .group_by(ClassInfo.id,ClassInfo.name,Students.sex) .all()) else: return False - return q + return [row._asdict() for row in q] from scores.model.score_model import Score @@ -41,19 +40,19 @@ from scores.model.score_model import Score def get_score_80(db): sq = ( db.query(Students.id) .join(Score, Score.sid == Students.id) - .filer(Score.score < 80 ) + .filter(Score.score < 80 ) .group_by(Students.id) .having(func.count(Score.id) > 2 ) - .sq() + .all() ) q = ( db.query(Students.name,ClassInfo.name,Score.score ) .join(ClassInfo, ClassInfo.id == Students.class_id) .join(Score, Score.sid == Students.id) - .filer(Students.id.in_(sq),Score.score < 80) + .filter(Students.id.in_(sq),Score.score < 80) .all() ) - return q + return [row._asdict() for row in q] def get_class_avg_dao(db): results = (db.query(Score.num, diff --git a/seed_data.py b/seed_data.py index a8e3044..688955a 100644 --- a/seed_data.py +++ b/seed_data.py @@ -204,8 +204,8 @@ def seed_test_data(): company_ids = [] for idx, comp_name in enumerate(companies): result = db.execute( - text("INSERT INTO Company (employment_company, address_id) VALUES (:name, :addr_id)"), - {"name": comp_name, "addr_id": address_ids[idx % len(address_ids)]} + text("INSERT INTO Company (employment_company) VALUES (:name)"), + {"name": comp_name} ) company_ids.append(result.lastrowid) @@ -228,17 +228,17 @@ def seed_test_data(): (all_students[7][0], all_students[7][1], company_ids[2], 31000, date(2028, 3, 1), date(2028, 5, 5)), ] - for emp in employment_data: + for idx, emp in enumerate(employment_data): db.execute(text(""" - INSERT INTO Employments (stuid, class_id, company_id, + INSERT INTO Employments (stuid, class_id, company_id, address_id, employment_salary, employment_open_time, offer_recived_time, is_deleted) - VALUES (:stuid, :class_id, :company_id, :salary, + VALUES (:stuid, :class_id, :company_id, :addr_id, :salary, :open_time, :offer_time, 0) """), { "stuid": emp[0], "class_id": emp[1], - "company_id": emp[2], "salary": emp[3], - "open_time": emp[4], "offer_time": emp[5], + "company_id": emp[2], "addr_id": address_ids[idx % len(address_ids)], + "salary": emp[3], "open_time": emp[4], "offer_time": emp[5], }) db.commit() diff --git a/stu_jiuye/dao.py b/stu_jiuye/dao.py index fa60fa6..d050af3 100644 --- a/stu_jiuye/dao.py +++ b/stu_jiuye/dao.py @@ -128,7 +128,7 @@ def get_emp_dao( #获取学生 # , "创建时间": i.create_time, # "更新时间": i.update_time, # "是否删除":i.is_deleted - } for i,sname,employment_company,somewhere in r ] #返回信息列表 + } for i,sname,employment_company in r ] #返回信息列表 return {"code": 200, "totals": len(r), "data": r} def delete_emp_dao(id,db): #删除函数 diff --git a/students/StudentsQuery.sql b/students/StudentsQuery.sql index 377ff29..b8baef8 100644 --- a/students/StudentsQuery.sql +++ b/students/StudentsQuery.sql @@ -10,7 +10,9 @@ drop database student_manage_system; drop table students; -select * from students limit 50; +select * from students limit 200; + +select * from scores limit 200; desc students;