feat:添加前端页面

This commit is contained in:
pzc
2026-09-14 10:23:36 +08:00
parent c392cd90e6
commit 28c13f4f69
27 changed files with 2873 additions and 62 deletions
+35 -40
View File
@@ -1,16 +1,15 @@
from sqlalchemy.orm import Session
from sqlalchemy import select, update, delete
from sqlalchemy import select, delete
from model.wl_score_model import Score
from model.wl_student_model import Student
def get_score(db: Session, stu_id: int, exam_order: int):
"""根据学生id+考试批次查询单条成绩"""
stmt = select(Score).where(
Score.stu_id == stu_id,
Score.exam_order == exam_order
)
return db.scalar(stmt)
def get_student_by_no(db: Session, stu_no: str):
"""按学号查学生。
新增成绩前先确认学生真实存在:wl_score.stu_no 是指向学生表的外键,
给一个不存在的学号会在 commit 时抛外键异常,那样报出来就是 500 了。
"""
return db.scalar(select(Student).where(Student.stu_no == stu_no))
def get_student_by_id(db: Session, stu_id: int):
@@ -23,33 +22,41 @@ def get_student_by_name(db: Session, stu_name: str):
return db.scalar(select(Student).where(Student.stu_name == stu_name))
def list_score_by_stu_id(db: Session, stu_id: int):
"""查询一个学生全部成绩,返回列表"""
stmt = select(Score).where(Score.stu_id == stu_id)
def get_score(db: Session, stu_no: str, exam_order: int):
"""根据学号+考试批次查询单条成绩"""
stmt = select(Score).where(
Score.stu_no == stu_no,
Score.exam_order == exam_order
)
return db.scalar(stmt)
def list_score_by_stu_no(db: Session, stu_no: str):
"""查询一个学生全部成绩。
学号不存在时自然就是空列表,不用单独去查一次学生。
"""
stmt = select(Score).where(Score.stu_no == stu_no)
return db.scalars(stmt).all()
def create_score(db: Session, stu_id: int, exam_order: int, score: float):
def create_score(db: Session, stu_no: str, exam_order: int, score: float):
"""
新增成绩
返回:成功返回StudentScore对象;检测不通过返回None
返回:成功返回Score对象;检测不通过返回None
"""
# 1.检测:学生是否真实存在学生表
stu = get_student_by_id(db, stu_id)
if not stu:
print("[检测] 学生表无此学生,stu_id=", stu_id)
if not get_student_by_no(db, stu_no):
print("[检测] 学生表无此学生,stu_no=", stu_no)
return None
# 2.检测:该学生该批次成绩是否已经存在(重复新增)
exist_score = get_score(db, stu_id, exam_order)
if exist_score:
print("[检测] 成绩已存在 stu_id=", stu_id, "exam_order=", exam_order)
if get_score(db, stu_no, exam_order):
print("[检测] 成绩已存在 stu_no=", stu_no, "exam_order=", exam_order)
return None
# 3.构建ORM对象插入数据库
new_score = Score(
stu_id=stu_id,
stu_no=stu_no,
exam_order=exam_order,
score=score
)
@@ -59,47 +66,35 @@ def create_score(db: Session, stu_id: int, exam_order: int, score: float):
return new_score
def update_score(db: Session, stu_id: int, exam_order: int, new_score: float):
def update_score(db: Session, stu_no: str, exam_order: int, new_score: float):
"""
更新指定学生指定考试批次的分数
"""
# 1.检测学生是否存在
stu = get_student_by_id(db, stu_id)
if not stu:
print("[检测] 更新失败:学生不存在")
return None
# 2.检测这条成绩记录本身是否存在
score_obj = get_score(db, stu_id, exam_order)
# 检测这条成绩记录是否存在(记录在,学生就一定在,外键保证的)
score_obj = get_score(db, stu_no, exam_order)
if not score_obj:
print("[检测] 更新失败:该学生该批次成绩记录不存在")
return None
# 方案A:直接修改对象属性(推荐)
# 直接修改对象属性
score_obj.score = new_score
db.commit()
db.refresh(score_obj)
return score_obj
def delete_score(db: Session, stu_id: int, exam_order: int):
def delete_score(db: Session, stu_no: str, exam_order: int):
"""删除某个学生某一次考核成绩"""
# 检测记录是否存在
score_obj = get_score(db, stu_id, exam_order)
score_obj = get_score(db, stu_no, exam_order)
if not score_obj:
print("[检测] 删除失败,记录不存在")
return False
stmt = delete(Score).where(
Score.stu_id == stu_id,
Score.stu_no == stu_no,
Score.exam_order == exam_order
)
db.execute(stmt)
db.commit()
return True
+2 -1
View File
@@ -133,7 +133,8 @@ class StatisticDao:
Student.stu_name,
Student.class_id,
Emp.offer_time,
Emp.company_name
Emp.company_name,
Emp.salary
).select_from(Student) \
.join(Student.emp)) \
.filter(Student.is_deleted==0, Emp.is_deleted==0) \
+3
View File
@@ -7,6 +7,9 @@ from scheme.wl_student_scheme import StudentCreate, StudentUpdate
# ---- 学号生成 ----
def generate_stu_no(db: Session, class_id: int, seq: int = None) -> str:
#没选班级和班级不存在给不同的提示,前端能直接展示给用户看
if class_id is None:
raise ValueError("请先选择班级")
#非测试就解除下面5行测试,注释date_str = "20260912"
cls = db.query(Class_).filter_by(class_id=class_id).first()
if not cls or not cls.start_time: