Compare commits

...

No commits in common. 'master2' and 'master' have entirely different histories.

@ -1,4 +1,3 @@
# 默认忽略的文件
/shelf/
/workspace.xml
/.idea

@ -0,0 +1 @@
__init__.cpython-311.pyc

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.11" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/新建文件夹.iml" filepath="$PROJECT_DIR$/.idea/新建文件夹.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -1,36 +1,31 @@
# stumis/bll/auth_bll.py
import json
import bcrypt
from stumis.model.user import User
class AuthBLL:
def __init__(self, users_file: str):
self.users_file = users_file
self.users = self._load_users()
def _load_users(self) -> dict[str, User]:
def _load_users(self) -> Dict[str, User]:
try:
with open(self.users_file, 'r') as f:
data = json.load(f)
return {user['username']: User(user['username'], user['password'].encode(), user['role']) for user in data}
return {user['username']: User(**user) for user in data}
except (FileNotFoundError, json.JSONDecodeError):
return {}
def authenticate(self, username: str, password: str) -> User | None:
def authenticate(self, username: str, password: str) -> Optional[User]:
user = self.users.get(username)
if user and bcrypt.checkpw(password.encode(), user.password):
if user and user.password == password: # 实际应比较哈希值
return user
return None
def add_user(self, user: User) -> bool:
if user.username in self.users:
return False
hashed = bcrypt.hashpw(user.password.encode(), bcrypt.gensalt())
user.password = hashed.decode()
self.users[user.username] = user
self._save_users()
return True
def _save_users(self):
with open(self.users_file, 'w') as f:
json.dump([vars(user) for user in self.users.values()], f)
json.dump([vars(user) for user in self.users.values()], f)

@ -1,23 +1,8 @@
from typing import List
from stumis.model.score import Score
# 简单模拟 JsonScoreDAL 类
class JsonScoreDAL:
def __init__(self, file_path: str):
self.file_path = file_path
self.data = [] # 模拟数据存储
def add(self, score: Score) -> bool:
self.data.append(score)
return True
def get_all(self) -> List[Score]:
return self.data
# stumis/bll/score_bll.py
class ScoreBLL:
def __init__(self, file_path: str):
self.dal = JsonScoreDAL(file_path)
self.dal = JsonScoreDAL(file_path) # 需要实现JsonScoreDAL
def add_score(self, score: Score) -> bool:
return self.dal.add(score)

@ -1 +0,0 @@
print(123)

@ -18,18 +18,6 @@ class Student:
self._birthday = self._extract_birthday(id_card)
self._age = self._calculate_age(self._birthday)
@staticmethod
def _validate_date(date_str: Optional[str]) -> bool:
if not date_str:
return True
try:
date.fromisoformat(date_str)
return True
except ValueError:
return False
@property
def birthday(self) -> date:
return self._birthday

@ -1,48 +1,39 @@
# test_student_bll.py
# test_bll.py
from stumis.bll.studentBLL import StudentBLL
from stumis.model.student import Student
import os
import pytest
from datetime import date
import uuid
@pytest.fixture
def student_bll(tmp_path):
file_path = tmp_path / "test_students.json"
bll = StudentBLL(str(file_path))
yield bll
# 清理资源(如果需要)
@pytest.fixture
def test_student():
unique_suffix = uuid.uuid4().hex[:6]
return Student(
name=f"测试学生_{unique_suffix}",
id_card=f"110101{date.today().year}{date.today().month:02d}{date.today().day:02d}{unique_suffix}",
stu_id=f"{date.today().year}{int(date.today().strftime('%m%d'))}{unique_suffix}",
def test_student_bll():
file_path = "test_students.json"
bll = StudentBLL(file_path)
# 使用合法的身份证号码
test_student = Student(
name="测试学生",
id_card="110101200001011234", # 2000年1月1日出生
stu_id="2025001",
gender=True,
height=175,
weight=70.5,
enrollment_date=f"{date.today().year}-09-01",
class_name=f"软件工程1班_{unique_suffix}",
enrollment_date="2025-09-01",
class_name="软件工程1班",
major="计算机科学与技术"
)
def test_add_student(student_bll, test_student):
# 测试添加学生
print("测试添加学生...")
result = student_bll.add(test_student)
assert result is True
result = bll.add(test_student)
print("添加结果:", result)
# 测试查询学生
print("测试查询学生...")
retrieved_student = student_bll.get_by_id(test_student.id_card)
assert retrieved_student is not None
assert retrieved_student.name == test_student.name
print("查询成功:", retrieved_student.name)
retrieved_student = bll.get_by_id("110101200001011234")
if retrieved_student:
print("查询成功:", retrieved_student.name)
else:
print("查询失败")
print("所有测试完成!")
if __name__ == "__main__":
pytest.main([__file__])
test_student_bll()

@ -4,12 +4,13 @@ from stumis.bll.studentBLL import StudentBLL
from stumis.dal import JsonStudentDAL
class StudentUI:
def __init__(self, file_path):
self.bll = StudentBLL(file_path)
print("UI层中StudentBLL的方法列表:", dir(self.bll))
assert hasattr(self.bll, 'add'), "add方法缺失"
def run(self):
while True:
self.display_menu()
@ -56,15 +57,10 @@ class StudentUI:
enrollment_date = input("入学日期 (YYYY-MM-DD): ")
class_name = input("班级: ")
major = input("专业: ")
if not Student._validate_id_card(id_card):
print("无效的身份证号,请重新输入。")
return
if not Student._validate_date(enrollment_date):
print("无效的入学日期格式请使用YYYY-MM-DD格式。")
return
try:
height = int(height) if height else None
weight = float(weight) if weight else None
@ -103,10 +99,6 @@ class StudentUI:
class_name = input(f"班级 ({student.class_name}): ") or student.class_name
major = input(f"专业 ({student.major}): ") or student.major
if not Student._validate_date(enrollment_date):
print("无效的入学日期格式请使用YYYY-MM-DD格式。")
return
try:
height = int(height) if height else None
weight = float(weight) if weight else None

@ -1 +1,13 @@
[]
[
{
"name": "陈浩",
"id_card": "522132200412245917",
"stu_id": "110309230907019",
"gender": true,
"height": 169,
"weight": 55.0,
"enrollment_date": "2023-09-01",
"class_name": "4",
"major": "语文"
}
]

@ -1,8 +1,10 @@
# stumis/utils/backup_manager.py
import os
import shutil
from datetime import datetime
class BackupManager:
def __init__(self, source_dir: str, backup_dir: str):
self.source_dir = source_dir
@ -11,32 +13,23 @@ class BackupManager:
def create_backup(self) -> str:
"""创建数据备份"""
try:
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
backup_path = os.path.join(self.backup_dir, f"backup_{timestamp}")
shutil.copytree(self.source_dir, backup_path)
return backup_path
except Exception as e:
print(f"创建备份失败: {e}")
return None
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
backup_path = os.path.join(self.backup_dir, f"backup_{timestamp}")
shutil.copytree(self.source_dir, backup_path)
return backup_path
def restore_backup(self, backup_path: str) -> bool:
"""恢复数据备份"""
if not os.path.exists(backup_path):
print("备份路径不存在。")
return False
try:
# 先删除当前数据
for root, dirs, files in os.walk(self.source_dir):
for file in files:
os.remove(os.path.join(root, file))
for dir in dirs:
os.rmdir(os.path.join(root, dir))
# 先删除当前数据
for root, dirs, files in os.walk(self.source_dir):
for file in files:
os.remove(os.path.join(root, file))
for dir in dirs:
os.rmdir(os.path.join(root, dir))
# 复制备份数据
shutil.copytree(backup_path, self.source_dir)
return True
except Exception as e:
print(f"恢复备份失败: {e}")
return False
# 复制备份数据
shutil.copytree(backup_path, self.source_dir)
return True
Loading…
Cancel
Save