v4.5 考勤默认出勤/校历、作业按次登记与权限体系完善
1. 考勤默认出勤:按日期范围给缺失学生批量补"出勤"(跳过周末/法定节假日,调休补班与手动补课日照常,已有记录不覆盖) 2. 节假日/补课校历:法定节假日与调休补班来自在线接口(缓存+失败降级),支持手动添加放假/补课(存 system_settings,优先于接口) 3. 作业按次登记:一次登记覆盖多次作业,配置总提交次数,按每人缺交次数自动扣分(单次缺交扣分x次数),并写入作业提交数据供"数据报表-作业统计"使用 4. 权限体系:新增 homework_register/default_attendance/manage_calendar 权限项;数据报表/操作日志/系统设置拆分为 view_reports/view_logs/manage_settings,共20项功能权限可配置;预置组默认值与 init.sql 同步 5. 权限审计修复:学生端接口管理员越权修复(管理员查看需 view_all_records,学生仅本人);学生列表手机号仅向学生管理/导出名单权限下发;操行分管理页与导航补权限门控 6. v4.5.sql:为预置权限组补充新权限默认值(JSON_SET,幂等可重复执行)
This commit is contained in:
1 parent
4c57ba3a30
commit
4c1ca13a3f
34 files changed
+1438
-48
No files matched your search
@@ -100,4 +100,56 @@ class AttendanceModel:
|
||||
async def mark_deduction_applied(attendance_id: int) -> bool:
|
||||
sql = "UPDATE attendance_records SET deduction_applied = 1 WHERE attendance_id = %s"
|
||||
result = await execute_update(sql, (attendance_id,))
|
||||
return result > 0
|
||||
return result > 0
|
||||
|
||||
@staticmethod
|
||||
async def get_existing_keys(
|
||||
start_date: str,
|
||||
end_date: str,
|
||||
slots: List[str]
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""查询日期范围内已存在的考勤记录(学生+日期+时段)"""
|
||||
placeholders = ", ".join(["%s"] * len(slots))
|
||||
sql = f"""
|
||||
SELECT student_id, date, slot
|
||||
FROM attendance_records
|
||||
WHERE date BETWEEN %s AND %s AND slot IN ({placeholders})
|
||||
"""
|
||||
rows = await execute_query(sql, (start_date, end_date, *slots))
|
||||
|
||||
result = []
|
||||
for row in rows:
|
||||
d = row['date']
|
||||
result.append({
|
||||
'student_id': row['student_id'],
|
||||
'date': d.isoformat() if hasattr(d, 'isoformat') else str(d),
|
||||
'slot': row['slot']
|
||||
})
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
async def bulk_create_present(rows: List[tuple]) -> int:
|
||||
"""批量插入出勤记录
|
||||
|
||||
rows: (student_id, date, slot, recorder_id, semester_id) 列表
|
||||
"""
|
||||
if not rows:
|
||||
return 0
|
||||
|
||||
created = 0
|
||||
chunk_size = 200
|
||||
for i in range(0, len(rows), chunk_size):
|
||||
chunk = rows[i:i + chunk_size]
|
||||
values = ", ".join(["(%s, %s, 'present', NULL, %s, %s, %s, 0)"] * len(chunk))
|
||||
params = []
|
||||
for student_id, day, slot, recorder_id, semester_id in chunk:
|
||||
params.extend([student_id, day, slot, recorder_id, semester_id])
|
||||
|
||||
sql = f"""
|
||||
INSERT INTO attendance_records
|
||||
(student_id, date, status, reason, slot, recorder_id, semester_id, deduction_applied)
|
||||
VALUES {values}
|
||||
"""
|
||||
created += await execute_update(sql, tuple(params))
|
||||
|
||||
return created
|
||||
@@ -0,0 +1,75 @@
|
||||
# ===========================================
|
||||
# 班级操行分管理系统 - 作业数据模型
|
||||
#
|
||||
# 开发者: Canglan
|
||||
# 联系方式: admin@sea-studio.top
|
||||
# 版权归属: Sea Network Technology Studio
|
||||
# 许可证: MIT License
|
||||
#
|
||||
# 版权所有 © Sea Network Technology Studio
|
||||
# ===========================================
|
||||
|
||||
from typing import List
|
||||
from utils.database import execute_insert, execute_update
|
||||
|
||||
|
||||
class HomeworkModel:
|
||||
"""作业数据模型(作业记录与提交数据)"""
|
||||
|
||||
@staticmethod
|
||||
async def create_assignments(
|
||||
subject_id: int,
|
||||
titles: List[str],
|
||||
deadline: str,
|
||||
created_by: int
|
||||
) -> List[int]:
|
||||
"""批量创建作业记录,返回 assignment_id 列表"""
|
||||
ids = []
|
||||
for title in titles:
|
||||
assignment_id = await execute_insert(
|
||||
"INSERT INTO assignments (subject_id, title, deadline, created_by) VALUES (%s, %s, %s, %s)",
|
||||
(subject_id, title, deadline, created_by)
|
||||
)
|
||||
ids.append(assignment_id)
|
||||
return ids
|
||||
|
||||
@staticmethod
|
||||
async def bulk_create_submissions(rows: List[tuple]) -> int:
|
||||
"""批量创建提交记录
|
||||
|
||||
rows: (assignment_id, student_id, status, updated_by) 列表
|
||||
"""
|
||||
if not rows:
|
||||
return 0
|
||||
|
||||
created = 0
|
||||
chunk_size = 200
|
||||
for i in range(0, len(rows), chunk_size):
|
||||
chunk = rows[i:i + chunk_size]
|
||||
values = ", ".join(["(%s, %s, %s, %s)"] * len(chunk))
|
||||
params = []
|
||||
for assignment_id, student_id, status, updated_by in chunk:
|
||||
params.extend([assignment_id, student_id, status, updated_by])
|
||||
|
||||
sql = f"""
|
||||
INSERT INTO homework_submissions
|
||||
(assignment_id, student_id, status, updated_by)
|
||||
VALUES {values}
|
||||
"""
|
||||
created += await execute_update(sql, tuple(params))
|
||||
|
||||
return created
|
||||
|
||||
@staticmethod
|
||||
async def mark_not_submitted_deducted(assignment_ids: List[int], student_id: int) -> int:
|
||||
"""标记某学生在该批次中的缺交记录已扣分"""
|
||||
if not assignment_ids:
|
||||
return 0
|
||||
|
||||
placeholders = ", ".join(["%s"] * len(assignment_ids))
|
||||
sql = f"""
|
||||
UPDATE homework_submissions
|
||||
SET deduction_applied = 1
|
||||
WHERE assignment_id IN ({placeholders}) AND student_id = %s AND status = 'not_submitted'
|
||||
"""
|
||||
return await execute_update(sql, (*assignment_ids, student_id))
|
||||
@@ -26,23 +26,29 @@ PERMISSION_KEYS = [
|
||||
"revoke_own", # 仅撤销自己提交的记录
|
||||
"restore_records", # 反撤销记录
|
||||
"manage_homework", # 作业扣分
|
||||
"homework_register", # 作业按次登记
|
||||
"manage_attendance", # 考勤管理
|
||||
"default_attendance", # 考勤默认出勤(批量补全)
|
||||
"manage_calendar", # 节假日/补课校历设置
|
||||
"manage_subjects", # 科目管理
|
||||
"manage_admins", # 管理员与权限组管理
|
||||
"manage_semesters", # 学期管理
|
||||
"view_all_records", # 查看全班记录/个人查询
|
||||
"view_reports", # 数据报表查看(考勤/作业统计)
|
||||
"export_data", # 导出德育分记录/历史记录
|
||||
"view_logs", # 操作日志查看
|
||||
"manage_settings", # 系统设置(密码策略等)
|
||||
"manage_upgrade", # 系统升级
|
||||
]
|
||||
|
||||
# 预置权限组默认配置(数据库尚未升级时按旧角色降级使用,与 sql/init.sql 种子一致)
|
||||
DEFAULT_GROUP_PERMISSIONS = {
|
||||
"班主任": {key: True for key in PERMISSION_KEYS},
|
||||
"班长": {"manage_conduct": True, "revoke_any": True, "view_all_records": True},
|
||||
"学习委员": {"manage_conduct": True, "manage_homework": True, "manage_subjects": True},
|
||||
"考勤委员": {"manage_conduct": True, "manage_attendance": True, "revoke_own": True},
|
||||
"班长": {"manage_conduct": True, "revoke_any": True, "view_all_records": True, "view_reports": True},
|
||||
"学习委员": {"manage_conduct": True, "manage_homework": True, "homework_register": True, "manage_subjects": True},
|
||||
"考勤委员": {"manage_conduct": True, "manage_attendance": True, "default_attendance": True, "revoke_own": True},
|
||||
"劳动委员": {"manage_conduct": True},
|
||||
"志愿委员": {"manage_conduct": True, "view_all_records": True},
|
||||
"志愿委员": {"manage_conduct": True, "view_all_records": True, "view_reports": True},
|
||||
}
|
||||
|
||||
DEFAULT_GROUP_CAPS = {
|
||||
|
||||
@@ -37,6 +37,23 @@ class SystemSettingModel:
|
||||
)
|
||||
return {row["setting_key"]: row["setting_value"] for row in rows}
|
||||
|
||||
@staticmethod
|
||||
async def get_by_prefix(prefix: str) -> Dict[str, str]:
|
||||
"""按前缀查询设置项"""
|
||||
rows = await execute_query(
|
||||
"SELECT setting_key, setting_value FROM system_settings WHERE setting_key LIKE %s",
|
||||
(prefix + '%',)
|
||||
)
|
||||
return {row["setting_key"]: row["setting_value"] for row in rows}
|
||||
|
||||
@staticmethod
|
||||
async def delete(key: str) -> bool:
|
||||
"""删除设置项"""
|
||||
result = await execute_update(
|
||||
"DELETE FROM system_settings WHERE setting_key = %s", (key,)
|
||||
)
|
||||
return result > 0
|
||||
|
||||
@staticmethod
|
||||
async def upsert(key: str, value: str) -> bool:
|
||||
sql = """
|
||||
|
||||
Reference in new issue
Block a user