From ee570460df3baf8bad827e02c22455f9993d5af0 Mon Sep 17 00:00:00 2001 From: HJW20 <1264519711@qq.com> Date: Tue, 24 Jun 2025 11:14:24 +0800 Subject: [PATCH] 123 --- 面向对象学生系统/bll/__init__.py | 0 面向对象学生系统/bll/import_students.py | 15 +++++++++++++++ 面向对象学生系统/bll/update_student.py | 6 ++++++ 3 files changed, 21 insertions(+) create mode 100644 面向对象学生系统/bll/__init__.py create mode 100644 面向对象学生系统/bll/import_students.py create mode 100644 面向对象学生系统/bll/update_student.py diff --git a/面向对象学生系统/bll/__init__.py b/面向对象学生系统/bll/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/面向对象学生系统/bll/import_students.py b/面向对象学生系统/bll/import_students.py new file mode 100644 index 0000000..02499a7 --- /dev/null +++ b/面向对象学生系统/bll/import_students.py @@ -0,0 +1,15 @@ +def import_students(self,file_path:str)-> bool: + try: + with open(file_path,'r',encoding='utf-8') as f: + student_dicts =json.load(f) + students=[Student.from_dict(student_dict) for student_dict in student_dicts] + for student in students: + if not student.is_valid: + print(f"导入学生数据时校验不通过,学生ID:{student.sid},错误信息:{student.get_errors()}") + continue + if not self.dal.check_student_exists(student.sid): + self.dal.add_student(student) + return True + except Exception as e: + print(f"从JSON导入学生数据时出错:{e}") + return False \ No newline at end of file diff --git a/面向对象学生系统/bll/update_student.py b/面向对象学生系统/bll/update_student.py new file mode 100644 index 0000000..d29e0ff --- /dev/null +++ b/面向对象学生系统/bll/update_student.py @@ -0,0 +1,6 @@ +def update_student(self,sid:str,student:Student)-> bool: + if not self.dal.check_student_exists(sid): + raise ValueError(f"学生ID{sid}不存在") + if not student.is_valid: + raise ValueError(f"学生数据校验不通过,错误信息:{student.get_errors()}") + return self.dal.update_student(sid,student) \ No newline at end of file