HJW20 2 months ago
commit ee570460df

@ -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

@ -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)
Loading…
Cancel
Save