v4.4 数据报表/操作日志/系统设置与月度分排行
1. 月度分排行:管理端首页支持总分/月度分切换与月份选择,新增排行榜导出CSV 2. 数据报表:新增考勤/作业统计页(日期范围、汇总与每人明细、CSV导出) 3. 操作日志:新增查看页(操作类型/操作人/日期筛选,分页) 4. 系统设置:密码策略可配置(长度/字符种类),全站改密与重置统一校验、前端提示同步;策略通过公开配置下发 5. 学期归档对比:查看归档时展示与上一学期的分数变化与名次升降 6. 历史记录导出支持按学生分表(每人一段,便于发家长) 7. 移动端适配:导航横向滚动、表格触控滚动、字号与弹窗优化 8. 版本升级至4.4(无数据库结构变更)
This commit is contained in:
1 parent
9a19add6c1
commit
768ea281e0
54 files changed
+1782
-90
No files matched your search
@@ -15,6 +15,7 @@ from models.user import UserModel
|
||||
from models.student import StudentModel
|
||||
from models.admin_role import AdminRoleModel
|
||||
from models.permission_group import PermissionGroupModel, PERMISSION_KEYS
|
||||
from services.setting_service import SettingService
|
||||
from utils.security import security
|
||||
from utils.validators import is_valid_email
|
||||
from utils.logger import get_logger
|
||||
@@ -616,9 +617,23 @@ class AdminService:
|
||||
logger.error(f"删除学生失败: {e}")
|
||||
return {"success": False, "message": f"删除失败: {str(e)}"}
|
||||
|
||||
@staticmethod
|
||||
async def validate_new_password(new_password: str) -> Dict[str, Any]:
|
||||
"""按系统密码策略校验新密码"""
|
||||
policy = await SettingService.get_password_policy()
|
||||
is_valid, msg = security.validate_password_strength(
|
||||
new_password, policy["min_length"], policy["max_length"], policy["min_types"]
|
||||
)
|
||||
if not is_valid:
|
||||
return {"success": False, "message": msg}
|
||||
return {"success": True}
|
||||
|
||||
@staticmethod
|
||||
async def reset_student_password(student_id: int, new_password: str) -> Dict[str, Any]:
|
||||
"""重置学生密码"""
|
||||
policy_check = await AdminService.validate_new_password(new_password)
|
||||
if not policy_check["success"]:
|
||||
return policy_check
|
||||
try:
|
||||
user = await execute_one(
|
||||
"SELECT user_id FROM users WHERE student_id = %s AND user_type = 'student'",
|
||||
|
||||
@@ -18,6 +18,7 @@ from models.user import UserModel
|
||||
from models.student import StudentModel
|
||||
from middleware.permission import PermissionChecker
|
||||
from services.log_service import LogService
|
||||
from services.setting_service import SettingService
|
||||
from utils.security import security
|
||||
from utils.validators import is_valid_email
|
||||
from utils.email_sender import EmailSender
|
||||
@@ -160,8 +161,11 @@ class AuthService:
|
||||
if not is_valid:
|
||||
return {"success": False, "message": "原密码错误"}
|
||||
|
||||
# 验证新密码强度
|
||||
is_valid, msg = security.validate_password_strength(new_password)
|
||||
# 验证新密码强度(策略可配置)
|
||||
policy = await SettingService.get_password_policy()
|
||||
is_valid, msg = security.validate_password_strength(
|
||||
new_password, policy["min_length"], policy["max_length"], policy["min_types"]
|
||||
)
|
||||
if not is_valid:
|
||||
return {"success": False, "message": msg}
|
||||
|
||||
@@ -315,7 +319,10 @@ class AuthService:
|
||||
if not user or user.get("user_type") != "admin" or user.get("status") != 1:
|
||||
return {"success": False, "message": "账号不存在或不可重置密码"}
|
||||
|
||||
is_valid, message = security.validate_password_strength(new_password)
|
||||
policy = await SettingService.get_password_policy()
|
||||
is_valid, message = security.validate_password_strength(
|
||||
new_password, policy["min_length"], policy["max_length"], policy["min_types"]
|
||||
)
|
||||
if not is_valid:
|
||||
return {"success": False, "message": message}
|
||||
|
||||
|
||||
@@ -54,3 +54,41 @@ class LogService:
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"写入操作日志失败: {e}")
|
||||
|
||||
@staticmethod
|
||||
async def get_operation_logs(
|
||||
page: int = 1,
|
||||
page_size: int = 20,
|
||||
operation_type: str = None,
|
||||
operator: str = None,
|
||||
start_date: str = None,
|
||||
end_date: str = None
|
||||
) -> dict:
|
||||
"""查询操作日志(分页 + 筛选)"""
|
||||
if operation_type == "":
|
||||
operation_type = None
|
||||
if operator == "":
|
||||
operator = None
|
||||
if start_date == "":
|
||||
start_date = None
|
||||
if end_date == "":
|
||||
end_date = None
|
||||
offset = (page - 1) * page_size
|
||||
total = await OperationLogModel.count_logs(
|
||||
operation_type, operator, start_date, end_date
|
||||
)
|
||||
logs = await OperationLogModel.get_logs(
|
||||
operation_type, operator, start_date, end_date, page_size, offset
|
||||
)
|
||||
return {
|
||||
"logs": logs,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"page_size": page_size,
|
||||
"total_pages": (total + page_size - 1) // page_size
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
async def get_operation_log_types() -> dict:
|
||||
"""获取操作日志类型列表(用于筛选下拉)"""
|
||||
return {"types": await OperationLogModel.get_types()}
|
||||
@@ -0,0 +1,115 @@
|
||||
# ===========================================
|
||||
# 班级操行分管理系统 - 统计报表服务
|
||||
#
|
||||
# 开发者: Canglan
|
||||
# 联系方式: admin@sea-studio.top
|
||||
# 版权归属: Sea Network Technology Studio
|
||||
# 许可证: MIT License
|
||||
#
|
||||
# 版权所有 © Sea Network Technology Studio
|
||||
# ===========================================
|
||||
|
||||
from typing import Dict, Any
|
||||
from models.report import ReportModel
|
||||
from utils.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
ATTENDANCE_STATUSES = ["present", "absent", "late", "leave"]
|
||||
HOMEWORK_STATUSES = ["submitted", "not_submitted", "late"]
|
||||
|
||||
|
||||
class ReportService:
|
||||
"""统计报表服务"""
|
||||
|
||||
@staticmethod
|
||||
async def attendance_report(start_date: str, end_date: str) -> Dict[str, Any]:
|
||||
"""考勤统计报表:出勤/缺勤/迟到/请假与出勤率"""
|
||||
students = await ReportModel.get_active_students()
|
||||
stats = await ReportModel.get_attendance_stats(start_date, end_date)
|
||||
|
||||
counts_map: Dict[int, Dict[str, int]] = {}
|
||||
for stat in stats:
|
||||
sid = stat["student_id"]
|
||||
entry = counts_map.setdefault(sid, {key: 0 for key in ATTENDANCE_STATUSES})
|
||||
if stat["status"] in entry:
|
||||
entry[stat["status"]] = int(stat["cnt"] or 0)
|
||||
|
||||
rows = []
|
||||
summary = {key: 0 for key in ATTENDANCE_STATUSES}
|
||||
for student in students:
|
||||
counts = counts_map.get(student["student_id"], {key: 0 for key in ATTENDANCE_STATUSES})
|
||||
total = sum(counts.values())
|
||||
present = counts["present"]
|
||||
rate = round(present / total * 100, 1) if total else None
|
||||
rows.append({
|
||||
"student_id": student["student_id"],
|
||||
"student_no": student["student_no"],
|
||||
"name": student["name"],
|
||||
"present": present,
|
||||
"absent": counts["absent"],
|
||||
"late": counts["late"],
|
||||
"leave": counts["leave"],
|
||||
"total": total,
|
||||
"rate": rate
|
||||
})
|
||||
for key in ATTENDANCE_STATUSES:
|
||||
summary[key] += counts[key]
|
||||
|
||||
rows.sort(key=lambda r: (-r["absent"], -r["late"], r["student_no"]))
|
||||
summary["total"] = sum(summary.values())
|
||||
summary["rate"] = (
|
||||
round(summary["present"] / summary["total"] * 100, 1)
|
||||
if summary["total"] else None
|
||||
)
|
||||
return {
|
||||
"start_date": start_date,
|
||||
"end_date": end_date,
|
||||
"rows": rows,
|
||||
"summary": summary
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
async def homework_report(start_date: str, end_date: str) -> Dict[str, Any]:
|
||||
"""作业统计报表:已交/未交/迟交与未交率"""
|
||||
students = await ReportModel.get_active_students()
|
||||
stats = await ReportModel.get_homework_stats(start_date, end_date)
|
||||
|
||||
counts_map: Dict[int, Dict[str, int]] = {}
|
||||
for stat in stats:
|
||||
sid = stat["student_id"]
|
||||
entry = counts_map.setdefault(sid, {key: 0 for key in HOMEWORK_STATUSES})
|
||||
if stat["status"] in entry:
|
||||
entry[stat["status"]] = int(stat["cnt"] or 0)
|
||||
|
||||
rows = []
|
||||
summary = {key: 0 for key in HOMEWORK_STATUSES}
|
||||
for student in students:
|
||||
counts = counts_map.get(student["student_id"], {key: 0 for key in HOMEWORK_STATUSES})
|
||||
total = sum(counts.values())
|
||||
miss_rate = round(counts["not_submitted"] / total * 100, 1) if total else None
|
||||
rows.append({
|
||||
"student_id": student["student_id"],
|
||||
"student_no": student["student_no"],
|
||||
"name": student["name"],
|
||||
"submitted": counts["submitted"],
|
||||
"not_submitted": counts["not_submitted"],
|
||||
"late": counts["late"],
|
||||
"total": total,
|
||||
"miss_rate": miss_rate
|
||||
})
|
||||
for key in HOMEWORK_STATUSES:
|
||||
summary[key] += counts[key]
|
||||
|
||||
rows.sort(key=lambda r: (-r["not_submitted"], -r["late"], r["student_no"]))
|
||||
summary["total"] = sum(summary.values())
|
||||
summary["miss_rate"] = (
|
||||
round(summary["not_submitted"] / summary["total"] * 100, 1)
|
||||
if summary["total"] else None
|
||||
)
|
||||
return {
|
||||
"start_date": start_date,
|
||||
"end_date": end_date,
|
||||
"rows": rows,
|
||||
"summary": summary
|
||||
}
|
||||
@@ -387,6 +387,25 @@ class SemesterService:
|
||||
|
||||
archives = await SemesterArchiveModel.get_by_semester(semester_id)
|
||||
|
||||
# 归档对比:与上一个已归档学期比较分数与名次
|
||||
previous_semester = await SemesterModel.get_previous_archived_semester(semester_id)
|
||||
if previous_semester:
|
||||
prev_archives = await SemesterArchiveModel.get_by_semester(previous_semester["semester_id"])
|
||||
prev_map = {a["student_id"]: a for a in prev_archives}
|
||||
for archive in archives:
|
||||
prev = prev_map.get(archive["student_id"])
|
||||
if prev:
|
||||
archive["prev_final_points"] = prev["final_points"]
|
||||
archive["points_change"] = (archive["final_points"] or 0) - (prev["final_points"] or 0)
|
||||
archive["prev_rank_position"] = prev["rank_position"]
|
||||
# 正数表示名次进步
|
||||
archive["rank_change"] = (prev["rank_position"] or 0) - (archive["rank_position"] or 0)
|
||||
else:
|
||||
archive["prev_final_points"] = None
|
||||
archive["points_change"] = None
|
||||
archive["prev_rank_position"] = None
|
||||
archive["rank_change"] = None
|
||||
|
||||
total = len(archives)
|
||||
offset = (page - 1) * page_size
|
||||
paged_archives = archives[offset:offset + page_size]
|
||||
@@ -401,6 +420,10 @@ class SemesterService:
|
||||
"end_date": semester.get('end_date'),
|
||||
"is_archived": bool(semester['is_archived'])
|
||||
},
|
||||
"previous_semester": {
|
||||
"semester_id": previous_semester["semester_id"],
|
||||
"semester_name": previous_semester["semester_name"]
|
||||
} if previous_semester else None,
|
||||
"archives": paged_archives,
|
||||
"total": total,
|
||||
"page": page,
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
# ===========================================
|
||||
# 班级操行分管理系统 - 系统设置服务
|
||||
#
|
||||
# 开发者: Canglan
|
||||
# 联系方式: admin@sea-studio.top
|
||||
# 版权归属: Sea Network Technology Studio
|
||||
# 许可证: MIT License
|
||||
#
|
||||
# 版权所有 © Sea Network Technology Studio
|
||||
# ===========================================
|
||||
|
||||
from typing import Dict, Any
|
||||
from models.system_setting import SystemSettingModel
|
||||
from utils.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
# 密码策略默认值(未配置时使用)
|
||||
DEFAULT_PASSWORD_POLICY = {
|
||||
"min_length": 6,
|
||||
"max_length": 20,
|
||||
"min_types": 3
|
||||
}
|
||||
|
||||
|
||||
class SettingService:
|
||||
"""系统设置服务"""
|
||||
|
||||
@staticmethod
|
||||
async def get_password_policy() -> Dict[str, int]:
|
||||
"""获取密码策略(长度范围与最少字符种类数)"""
|
||||
values = await SystemSettingModel.get_many([
|
||||
"password_min_length", "password_max_length", "password_min_types"
|
||||
])
|
||||
policy = dict(DEFAULT_PASSWORD_POLICY)
|
||||
|
||||
def parse_int(key: str, default: int, low: int, high: int) -> int:
|
||||
try:
|
||||
value = int(values.get(key, ""))
|
||||
except (TypeError, ValueError):
|
||||
return default
|
||||
return max(low, min(high, value))
|
||||
|
||||
policy["min_length"] = parse_int("password_min_length", policy["min_length"], 4, 64)
|
||||
policy["max_length"] = parse_int("password_max_length", policy["max_length"], 8, 100)
|
||||
policy["min_types"] = parse_int("password_min_types", policy["min_types"], 1, 4)
|
||||
if policy["min_length"] > policy["max_length"]:
|
||||
policy["min_length"] = policy["max_length"]
|
||||
return policy
|
||||
|
||||
@staticmethod
|
||||
async def update_password_policy(
|
||||
min_length: int,
|
||||
max_length: int,
|
||||
min_types: int,
|
||||
operator_id: int = None
|
||||
) -> Dict[str, Any]:
|
||||
"""更新密码策略"""
|
||||
if not (4 <= min_length <= 64):
|
||||
return {"success": False, "message": "最小长度需在4-64之间"}
|
||||
if not (8 <= max_length <= 100):
|
||||
return {"success": False, "message": "最大长度需在8-100之间"}
|
||||
if min_length > max_length:
|
||||
return {"success": False, "message": "最小长度不能大于最大长度"}
|
||||
if not (1 <= min_types <= 4):
|
||||
return {"success": False, "message": "字符种类数需在1-4之间"}
|
||||
|
||||
await SystemSettingModel.upsert("password_min_length", str(min_length))
|
||||
await SystemSettingModel.upsert("password_max_length", str(max_length))
|
||||
await SystemSettingModel.upsert("password_min_types", str(min_types))
|
||||
logger.info(
|
||||
f"用户[{operator_id}] 更新密码策略: {min_length}-{max_length}位, 至少{min_types}种字符"
|
||||
)
|
||||
return {"success": True, "message": "密码策略已保存"}
|
||||
@@ -121,15 +121,20 @@ class StudentService:
|
||||
@staticmethod
|
||||
async def get_ranking(
|
||||
user_id: int,
|
||||
limit: int = 50
|
||||
limit: int = 50,
|
||||
month: str = None
|
||||
) -> Dict[str, Any]:
|
||||
"""获取排行榜(单班级系统)"""
|
||||
ranking = await StudentModel.get_ranking(limit=limit)
|
||||
"""获取排行榜(单班级系统);传 month 时返回月度分排行"""
|
||||
if month:
|
||||
ranking = await StudentModel.get_monthly_ranking(month=month, limit=limit)
|
||||
else:
|
||||
ranking = await StudentModel.get_ranking(limit=limit)
|
||||
total_students = await StudentModel.get_total_count()
|
||||
|
||||
return {
|
||||
"ranking": ranking,
|
||||
"total_students": total_students
|
||||
"total_students": total_students,
|
||||
"month": month
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in new issue
Block a user