历史记录/操作日志与作业按次登记改进
1. 历史记录:批次合并视图新增"批量反撤销"(需反撤销权限);单条/批量撤销与反撤销提示更明确(说明记录去向,不会删除);操作列权限门控补充 restore_records 2. 操作日志:批量撤销/反撤销写入日志;单条撤销/反撤销/加减分日志详情补充学生姓名(学号)、分值变动、原因;新增"详情关键词"筛选(学生姓名/原因等) 3. 节假日接口:证书校验失败自动回退重试,提高服务器兼容性 4. 作业按次登记:默认列出全部学生、缺交次数默认0(0=已交),支持全员已交登记;后端允许空缺交名单
This commit is contained in:
1 parent
dbf70f602e
commit
d0cdb5b928
13 files changed
+188
-48
No files matched your search
+10
-4
@@ -69,7 +69,8 @@ class OperationLogModel:
|
|||||||
operation_type: str = None,
|
operation_type: str = None,
|
||||||
operator: str = None,
|
operator: str = None,
|
||||||
start_date: str = None,
|
start_date: str = None,
|
||||||
end_date: str = None
|
end_date: str = None,
|
||||||
|
keyword: str = None
|
||||||
):
|
):
|
||||||
conditions = ["1=1"]
|
conditions = ["1=1"]
|
||||||
params = []
|
params = []
|
||||||
@@ -79,6 +80,9 @@ class OperationLogModel:
|
|||||||
if operator:
|
if operator:
|
||||||
conditions.append("(operator_name LIKE %s OR operator_role LIKE %s)")
|
conditions.append("(operator_name LIKE %s OR operator_role LIKE %s)")
|
||||||
params.extend([f"%{operator}%", f"%{operator}%"])
|
params.extend([f"%{operator}%", f"%{operator}%"])
|
||||||
|
if keyword:
|
||||||
|
conditions.append("details LIKE %s")
|
||||||
|
params.append(f"%{keyword}%")
|
||||||
if start_date:
|
if start_date:
|
||||||
conditions.append("DATE(created_at) >= %s")
|
conditions.append("DATE(created_at) >= %s")
|
||||||
params.append(start_date)
|
params.append(start_date)
|
||||||
@@ -93,12 +97,13 @@ class OperationLogModel:
|
|||||||
operator: str = None,
|
operator: str = None,
|
||||||
start_date: str = None,
|
start_date: str = None,
|
||||||
end_date: str = None,
|
end_date: str = None,
|
||||||
|
keyword: str = None,
|
||||||
limit: int = 20,
|
limit: int = 20,
|
||||||
offset: int = 0
|
offset: int = 0
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
"""查询操作日志(分页)"""
|
"""查询操作日志(分页)"""
|
||||||
where, params = OperationLogModel._build_filters(
|
where, params = OperationLogModel._build_filters(
|
||||||
operation_type, operator, start_date, end_date
|
operation_type, operator, start_date, end_date, keyword
|
||||||
)
|
)
|
||||||
sql = f"""
|
sql = f"""
|
||||||
SELECT log_id, operator_id, operator_name, operator_role,
|
SELECT log_id, operator_id, operator_name, operator_role,
|
||||||
@@ -116,11 +121,12 @@ class OperationLogModel:
|
|||||||
operation_type: str = None,
|
operation_type: str = None,
|
||||||
operator: str = None,
|
operator: str = None,
|
||||||
start_date: str = None,
|
start_date: str = None,
|
||||||
end_date: str = None
|
end_date: str = None,
|
||||||
|
keyword: str = None
|
||||||
) -> int:
|
) -> int:
|
||||||
"""统计操作日志数量"""
|
"""统计操作日志数量"""
|
||||||
where, params = OperationLogModel._build_filters(
|
where, params = OperationLogModel._build_filters(
|
||||||
operation_type, operator, start_date, end_date
|
operation_type, operator, start_date, end_date, keyword
|
||||||
)
|
)
|
||||||
result = await execute_one(
|
result = await execute_one(
|
||||||
f"SELECT COUNT(*) AS total FROM operation_logs WHERE {where}",
|
f"SELECT COUNT(*) AS total FROM operation_logs WHERE {where}",
|
||||||
|
|||||||
+60
-9
@@ -23,6 +23,7 @@ from services.attendance_service import AttendanceService
|
|||||||
from services.homework_service import HomeworkService
|
from services.homework_service import HomeworkService
|
||||||
from services.log_service import LogService
|
from services.log_service import LogService
|
||||||
from services.setting_service import SettingService
|
from services.setting_service import SettingService
|
||||||
|
from models.student import StudentModel
|
||||||
from utils.redis_client import RedisClient
|
from utils.redis_client import RedisClient
|
||||||
from schemas.admin import (
|
from schemas.admin import (
|
||||||
AddPointsRequest, RevokeRequest, AddAdminRequest,
|
AddPointsRequest, RevokeRequest, AddAdminRequest,
|
||||||
@@ -42,6 +43,19 @@ router = APIRouter()
|
|||||||
logger = get_logger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
async def _students_brief(student_ids: list, limit: int = 10) -> str:
|
||||||
|
"""操作日志用:学生姓名(学号)摘要"""
|
||||||
|
names = []
|
||||||
|
for sid in student_ids[:limit]:
|
||||||
|
student = await StudentModel.get_by_id(sid)
|
||||||
|
if student:
|
||||||
|
names.append(f"{student['name']}({student['student_no']})")
|
||||||
|
if not names:
|
||||||
|
return "-"
|
||||||
|
suffix = f" 等{len(student_ids)}人" if len(student_ids) > limit else ""
|
||||||
|
return "、".join(names) + suffix
|
||||||
|
|
||||||
|
|
||||||
# ========== 学生管理 ==========
|
# ========== 学生管理 ==========
|
||||||
|
|
||||||
@router.get("/students/dormitories")
|
@router.get("/students/dormitories")
|
||||||
@@ -246,7 +260,10 @@ async def add_conduct_points(request: Request, req: AddPointsRequest):
|
|||||||
operator_id=user["user_id"], operator_name=user["real_name"],
|
operator_id=user["user_id"], operator_name=user["real_name"],
|
||||||
operator_role=role, operation_type="add_points",
|
operator_role=role, operation_type="add_points",
|
||||||
target_type="conduct",
|
target_type="conduct",
|
||||||
details=f"批量加减分: {req.points_change}分, 原因: {req.reason}, 对象: {req.student_ids}",
|
details=(
|
||||||
|
f"批量加减分: {req.points_change}分, 原因: {req.reason}, "
|
||||||
|
f"学生({len(req.student_ids)}人): {await _students_brief(req.student_ids)}"
|
||||||
|
),
|
||||||
ip=request.client.host
|
ip=request.client.host
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -270,15 +287,18 @@ async def revoke_conduct_record(request: Request, req: RevokeRequest):
|
|||||||
if result["success"]:
|
if result["success"]:
|
||||||
role = await PermissionChecker.get_user_role(user["user_id"])
|
role = await PermissionChecker.get_user_role(user["user_id"])
|
||||||
record = result.get("record", {})
|
record = result.get("record", {})
|
||||||
|
student = await StudentModel.get_by_id(record.get("student_id")) if record.get("student_id") else None
|
||||||
|
student_text = f"{student['name']}({student['student_no']})" if student else f"ID:{record.get('student_id')}"
|
||||||
await LogService.write_operation_log(
|
await LogService.write_operation_log(
|
||||||
operator_id=user["user_id"], operator_name=user["real_name"],
|
operator_id=user["user_id"], operator_name=user["real_name"],
|
||||||
operator_role=role, operation_type="revoke_record",
|
operator_role=role, operation_type="revoke_record",
|
||||||
target_type="conduct", target_id=req.record_id,
|
target_type="conduct", target_id=req.record_id,
|
||||||
details=(
|
details=(
|
||||||
f"撤销记录ID: {req.record_id}, "
|
f"撤销记录: {student_text}, "
|
||||||
|
f"分值变动: {'+' if record.get('points_change', 0) > 0 else ''}{record.get('points_change', 0)}分, "
|
||||||
|
f"原因: {record.get('reason', '-')}, "
|
||||||
f"原操作人: {record.get('recorder_name', '未知')}, "
|
f"原操作人: {record.get('recorder_name', '未知')}, "
|
||||||
f"原分值变动: {'+' if record.get('points_change', 0) > 0 else ''}{record.get('points_change', 0)}分, "
|
f"操作人: {user['username']}"
|
||||||
f"撤销操作人: {user['username']}"
|
|
||||||
),
|
),
|
||||||
ip=request.client.host
|
ip=request.client.host
|
||||||
)
|
)
|
||||||
@@ -300,15 +320,18 @@ async def restore_conduct_record(request: Request, req: RevokeRequest):
|
|||||||
)
|
)
|
||||||
if result["success"]:
|
if result["success"]:
|
||||||
record = result.get("record", {})
|
record = result.get("record", {})
|
||||||
|
student = await StudentModel.get_by_id(record.get("student_id")) if record.get("student_id") else None
|
||||||
|
student_text = f"{student['name']}({student['student_no']})" if student else f"ID:{record.get('student_id')}"
|
||||||
await LogService.write_operation_log(
|
await LogService.write_operation_log(
|
||||||
operator_id=user["user_id"], operator_name=user["real_name"],
|
operator_id=user["user_id"], operator_name=user["real_name"],
|
||||||
operator_role=(await PermissionChecker.get_user_role(user["user_id"]) or "管理员"), operation_type="restore_record",
|
operator_role=(await PermissionChecker.get_user_role(user["user_id"]) or "管理员"), operation_type="restore_record",
|
||||||
target_type="conduct", target_id=req.record_id,
|
target_type="conduct", target_id=req.record_id,
|
||||||
details=(
|
details=(
|
||||||
f"反撤销记录ID: {req.record_id}, "
|
f"反撤销记录: {student_text}, "
|
||||||
|
f"分值变动: {'+' if record.get('points_change', 0) > 0 else ''}{record.get('points_change', 0)}分, "
|
||||||
|
f"原因: {record.get('reason', '-')}, "
|
||||||
f"原操作人: {record.get('recorder_name', '未知')}, "
|
f"原操作人: {record.get('recorder_name', '未知')}, "
|
||||||
f"原分值变动: {'+' if record.get('points_change', 0) > 0 else ''}{record.get('points_change', 0)}分, "
|
f"操作人: {user['username']}"
|
||||||
f"反撤销操作人: {user['username']}"
|
|
||||||
),
|
),
|
||||||
ip=request.client.host
|
ip=request.client.host
|
||||||
)
|
)
|
||||||
@@ -411,6 +434,19 @@ async def batch_revoke_conduct_records(request: Request):
|
|||||||
fail_count += 1
|
fail_count += 1
|
||||||
errors.append({"record_id": record_id, "error": result["message"]})
|
errors.append({"record_id": record_id, "error": result["message"]})
|
||||||
|
|
||||||
|
if success_count > 0:
|
||||||
|
ids_preview = ", ".join(str(i) for i in record_ids[:10]) + ("..." if len(record_ids) > 10 else "")
|
||||||
|
try:
|
||||||
|
await LogService.write_operation_log(
|
||||||
|
operator_id=user["user_id"], operator_name=user["real_name"],
|
||||||
|
operator_role=await PermissionChecker.get_user_role(user["user_id"]) or "管理员",
|
||||||
|
operation_type="batch_revoke", target_type="conduct",
|
||||||
|
details=f"批量撤销 {success_count} 条记录(记录ID: {ids_preview})",
|
||||||
|
ip=request.client.host
|
||||||
|
)
|
||||||
|
except Exception as log_error:
|
||||||
|
logger.error(f"写入批量撤销日志失败: {log_error}")
|
||||||
|
|
||||||
return success_response(data={
|
return success_response(data={
|
||||||
"success_count": success_count,
|
"success_count": success_count,
|
||||||
"fail_count": fail_count,
|
"fail_count": fail_count,
|
||||||
@@ -451,6 +487,19 @@ async def batch_restore_conduct_records(request: Request):
|
|||||||
fail_count += 1
|
fail_count += 1
|
||||||
errors.append({"record_id": record_id, "error": result["message"]})
|
errors.append({"record_id": record_id, "error": result["message"]})
|
||||||
|
|
||||||
|
if success_count > 0:
|
||||||
|
ids_preview = ", ".join(str(i) for i in record_ids[:10]) + ("..." if len(record_ids) > 10 else "")
|
||||||
|
try:
|
||||||
|
await LogService.write_operation_log(
|
||||||
|
operator_id=user["user_id"], operator_name=user["real_name"],
|
||||||
|
operator_role=await PermissionChecker.get_user_role(user["user_id"]) or "管理员",
|
||||||
|
operation_type="batch_restore", target_type="conduct",
|
||||||
|
details=f"批量反撤销 {success_count} 条记录(记录ID: {ids_preview})",
|
||||||
|
ip=request.client.host
|
||||||
|
)
|
||||||
|
except Exception as log_error:
|
||||||
|
logger.error(f"写入批量反撤销日志失败: {log_error}")
|
||||||
|
|
||||||
return success_response(data={
|
return success_response(data={
|
||||||
"success_count": success_count,
|
"success_count": success_count,
|
||||||
"fail_count": fail_count,
|
"fail_count": fail_count,
|
||||||
@@ -993,7 +1042,8 @@ async def get_operation_logs(
|
|||||||
operation_type: Optional[str] = None,
|
operation_type: Optional[str] = None,
|
||||||
operator: Optional[str] = None,
|
operator: Optional[str] = None,
|
||||||
start_date: Optional[str] = None,
|
start_date: Optional[str] = None,
|
||||||
end_date: Optional[str] = None
|
end_date: Optional[str] = None,
|
||||||
|
keyword: Optional[str] = None
|
||||||
):
|
):
|
||||||
"""查询操作日志(需操作日志查看权限)"""
|
"""查询操作日志(需操作日志查看权限)"""
|
||||||
try:
|
try:
|
||||||
@@ -1006,7 +1056,8 @@ async def get_operation_logs(
|
|||||||
operation_type=operation_type,
|
operation_type=operation_type,
|
||||||
operator=operator,
|
operator=operator,
|
||||||
start_date=start_date,
|
start_date=start_date,
|
||||||
end_date=end_date
|
end_date=end_date,
|
||||||
|
keyword=keyword
|
||||||
)
|
)
|
||||||
return success_response(data=result)
|
return success_response(data=result)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ class HomeworkRegisterRequest(BaseModel):
|
|||||||
total_times: int = Field(..., ge=1, le=99, description="总提交次数")
|
total_times: int = Field(..., ge=1, le=99, description="总提交次数")
|
||||||
per_deduction: Optional[int] = Field(None, ge=1, le=20, description="单次缺交扣分(默认取系统配置)")
|
per_deduction: Optional[int] = Field(None, ge=1, le=20, description="单次缺交扣分(默认取系统配置)")
|
||||||
note: Optional[str] = Field(None, max_length=100, description="备注")
|
note: Optional[str] = Field(None, max_length=100, description="备注")
|
||||||
records: List[HomeworkRegisterItem] = Field(..., min_length=1, max_length=200, description="缺交学生与缺交次数")
|
records: List[HomeworkRegisterItem] = Field(default_factory=list, max_length=200, description="缺交学生与缺交次数(可为空,空=全班已交)")
|
||||||
|
|
||||||
|
|
||||||
class ResetPasswordRequest(BaseModel):
|
class ResetPasswordRequest(BaseModel):
|
||||||
|
|||||||
@@ -12,8 +12,10 @@
|
|||||||
"""节假日服务:在线获取法定节假日与调休补班数据(带缓存与失败降级)"""
|
"""节假日服务:在线获取法定节假日与调休补班数据(带缓存与失败降级)"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import ssl
|
||||||
import time
|
import time
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import urllib.error
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
@@ -36,8 +38,15 @@ def _fetch_year_sync(year: int) -> Dict[str, Any]:
|
|||||||
HOLIDAY_API.format(year=year),
|
HOLIDAY_API.format(year=year),
|
||||||
headers={'User-Agent': 'ClassManager/4.5 (HolidayFetcher)'}
|
headers={'User-Agent': 'ClassManager/4.5 (HolidayFetcher)'}
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT) as response:
|
with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT) as response:
|
||||||
payload = json.loads(response.read().decode('utf-8'))
|
payload = json.loads(response.read().decode('utf-8'))
|
||||||
|
except (ssl.SSLError, urllib.error.URLError) as e:
|
||||||
|
# 部分服务器根证书较旧,回退为不校验证书重试一次(节假日数据非敏感)
|
||||||
|
logger.warning(f"节假日接口证书校验失败,回退重试: {e}")
|
||||||
|
context = ssl._create_unverified_context()
|
||||||
|
with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT, context=context) as response:
|
||||||
|
payload = json.loads(response.read().decode('utf-8'))
|
||||||
|
|
||||||
if payload.get('code') != 0:
|
if payload.get('code') != 0:
|
||||||
raise ValueError(f"接口返回错误码: {payload.get('code')}")
|
raise ValueError(f"接口返回错误码: {payload.get('code')}")
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ class LogService:
|
|||||||
operation_type: str = None,
|
operation_type: str = None,
|
||||||
operator: str = None,
|
operator: str = None,
|
||||||
start_date: str = None,
|
start_date: str = None,
|
||||||
end_date: str = None
|
end_date: str = None,
|
||||||
|
keyword: str = None
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""查询操作日志(分页 + 筛选)"""
|
"""查询操作日志(分页 + 筛选)"""
|
||||||
if operation_type == "":
|
if operation_type == "":
|
||||||
@@ -73,12 +74,14 @@ class LogService:
|
|||||||
start_date = None
|
start_date = None
|
||||||
if end_date == "":
|
if end_date == "":
|
||||||
end_date = None
|
end_date = None
|
||||||
|
if keyword == "":
|
||||||
|
keyword = None
|
||||||
offset = (page - 1) * page_size
|
offset = (page - 1) * page_size
|
||||||
total = await OperationLogModel.count_logs(
|
total = await OperationLogModel.count_logs(
|
||||||
operation_type, operator, start_date, end_date
|
operation_type, operator, start_date, end_date, keyword
|
||||||
)
|
)
|
||||||
logs = await OperationLogModel.get_logs(
|
logs = await OperationLogModel.get_logs(
|
||||||
operation_type, operator, start_date, end_date, page_size, offset
|
operation_type, operator, start_date, end_date, keyword, page_size, offset
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
"logs": logs,
|
"logs": logs,
|
||||||
|
|||||||
+13
-1
@@ -84,6 +84,17 @@
|
|||||||
1. 在历史记录列表中找到目标记录
|
1. 在历史记录列表中找到目标记录
|
||||||
2. 点击右侧"撤销"按钮
|
2. 点击右侧"撤销"按钮
|
||||||
3. 确认撤销操作
|
3. 确认撤销操作
|
||||||
|
4. 撤销后记录会移入"已撤销"(状态筛选选"已撤销"可查看并反撤销),学生分数自动恢复
|
||||||
|
|
||||||
|
#### 批量撤销 / 批量反撤销(批次合并视图)
|
||||||
|
1. 勾选"批次合并"后,同一批次的记录会合并为一行
|
||||||
|
2. 点击该行的"批量撤销"可一次撤销整批记录
|
||||||
|
3. 查看"已撤销"状态的批次时,点击"批量反撤销"可一次恢复整批记录
|
||||||
|
4. 撤销/反撤销操作均会写入操作日志(批量操作记录条数与记录ID)
|
||||||
|
|
||||||
|
#### 反撤销(恢复记录)
|
||||||
|
1. 状态筛选选择"已撤销",找到被撤销的记录
|
||||||
|
2. 点击"反撤销"按钮,确认后分数变动重新生效
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -399,8 +410,9 @@
|
|||||||
|
|
||||||
用于审计管理端所有关键操作。
|
用于审计管理端所有关键操作。
|
||||||
|
|
||||||
- 支持按**操作类型**、**操作人/角色关键词**、**日期范围**筛选
|
- 支持按**操作类型**、**操作人/角色关键词**、**详情关键词**(学生姓名/记录原因等)、**日期范围**筛选
|
||||||
- 分页展示:时间、操作人、角色、操作类型、对象、详情、IP
|
- 分页展示:时间、操作人、角色、操作类型、对象、详情、IP
|
||||||
|
- 操行分相关日志详情包含:学生姓名(学号)、分值变动、原因、原操作人;批量撤销/反撤销会记录条数与记录ID
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ include __DIR__ . '/../includes/header.php';
|
|||||||
<th>学生</th>
|
<th>学生</th>
|
||||||
<th style="white-space: nowrap; min-width: 80px;">操作人</th>
|
<th style="white-space: nowrap; min-width: 80px;">操作人</th>
|
||||||
<th>时间</th>
|
<th>时间</th>
|
||||||
<?php if (has_perm('revoke_any') || has_perm('revoke_own')): ?>
|
<?php if (has_perm('revoke_any') || has_perm('revoke_own') || has_perm('restore_records')): ?>
|
||||||
<th>操作</th>
|
<th>操作</th>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ include __DIR__ . '/../includes/header.php';
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>缺交学生与次数</label>
|
<label>缺交学生与次数</label>
|
||||||
<div id="hwRegStudentList" class="hw-reg-list"></div>
|
<div id="hwRegStudentList" class="hw-reg-list"></div>
|
||||||
<small>缺交次数不超过总提交次数,其他学生自动记为已交</small>
|
<small>默认全部学生按已交处理;在列表中为缺交学生填写缺交次数(0 或留空 = 已交),缺交次数不超过总提交次数</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>备注</label>
|
<label>备注</label>
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ include __DIR__ . '/../includes/header.php';
|
|||||||
<label>操作人 / 角色</label>
|
<label>操作人 / 角色</label>
|
||||||
<input type="text" id="logOperatorFilter" placeholder="关键词">
|
<input type="text" id="logOperatorFilter" placeholder="关键词">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="filter-group">
|
||||||
|
<label>详情关键词</label>
|
||||||
|
<input type="text" id="logKeywordFilter" placeholder="学生 / 原因等">
|
||||||
|
</div>
|
||||||
<div class="filter-group">
|
<div class="filter-group">
|
||||||
<label>开始日期</label>
|
<label>开始日期</label>
|
||||||
<input type="date" id="logStartDate">
|
<input type="date" id="logStartDate">
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ const canRevokeAny = hasPermission('revoke_any');
|
|||||||
const canRevokeOwn = hasPermission('revoke_own');
|
const canRevokeOwn = hasPermission('revoke_own');
|
||||||
const canRestore = hasPermission('restore_records');
|
const canRestore = hasPermission('restore_records');
|
||||||
const canRevoke = canRevokeAny || canRevokeOwn;
|
const canRevoke = canRevokeAny || canRevokeOwn;
|
||||||
|
const canAct = canRevoke || canRestore;
|
||||||
let currentHistoryPage = 1;
|
let currentHistoryPage = 1;
|
||||||
let totalHistoryPages = 1;
|
let totalHistoryPages = 1;
|
||||||
|
|
||||||
@@ -126,12 +127,12 @@ async function loadHistory(page) {
|
|||||||
var headHtml = '';
|
var headHtml = '';
|
||||||
if (isGrouped) {
|
if (isGrouped) {
|
||||||
headHtml = '<th>类型</th><th>分值</th><th>原因</th><th>学生名单</th><th' + nowrapStyle + '>操作人</th><th>时间</th>';
|
headHtml = '<th>类型</th><th>分值</th><th>原因</th><th>学生名单</th><th' + nowrapStyle + '>操作人</th><th>时间</th>';
|
||||||
if (canRevoke) {
|
if (canAct) {
|
||||||
headHtml += '<th>操作</th>';
|
headHtml += '<th>操作</th>';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
headHtml = '<th>类型</th><th>分值</th><th>原因</th><th>学生</th><th' + nowrapStyle + '>操作人</th><th>时间</th>';
|
headHtml = '<th>类型</th><th>分值</th><th>原因</th><th>学生</th><th' + nowrapStyle + '>操作人</th><th>时间</th>';
|
||||||
if (canRevoke) {
|
if (canAct) {
|
||||||
headHtml += '<th>操作</th>';
|
headHtml += '<th>操作</th>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,9 +153,13 @@ async function loadHistory(page) {
|
|||||||
'<td class="history-students">' + escapeHtml(names) + '</td>' +
|
'<td class="history-students">' + escapeHtml(names) + '</td>' +
|
||||||
'<td>' + escapeHtml(record.recorder_name || '') + '</td>' +
|
'<td>' + escapeHtml(record.recorder_name || '') + '</td>' +
|
||||||
'<td class="history-time">' + formatDateTime(record.created_at) + '</td>';
|
'<td class="history-time">' + formatDateTime(record.created_at) + '</td>';
|
||||||
if (canRevoke) {
|
if (canAct) {
|
||||||
if (allRevoked) {
|
if (allRevoked) {
|
||||||
|
if (canRestore) {
|
||||||
|
html += '<td><button class="btn btn-sm btn-outline" onclick="batchRestoreGrouped(\'' + escapeHtml(record.reason).replace(/'/g, "\\'") + '\',' + record.points_change + ',\'' + escapeHtml(record.recorder_name || '').replace(/'/g, "\\'") + '\')">批量反撤销</button></td>';
|
||||||
|
} else {
|
||||||
html += '<td><span class="text-muted">已撤销</span></td>';
|
html += '<td><span class="text-muted">已撤销</span></td>';
|
||||||
|
}
|
||||||
} else if (canRevokeAny) {
|
} else if (canRevokeAny) {
|
||||||
html += '<td><button class="btn btn-sm btn-outline" onclick="batchRevokeGrouped(\'' + escapeHtml(record.reason).replace(/'/g, "\\'") + '\',' + record.points_change + ',\'' + escapeHtml(record.recorder_name || '').replace(/'/g, "\\'") + '\',\'' + formatDateTime(record.created_at) + '\')">批量撤销</button></td>';
|
html += '<td><button class="btn btn-sm btn-outline" onclick="batchRevokeGrouped(\'' + escapeHtml(record.reason).replace(/'/g, "\\'") + '\',' + record.points_change + ',\'' + escapeHtml(record.recorder_name || '').replace(/'/g, "\\'") + '\',\'' + formatDateTime(record.created_at) + '\')">批量撤销</button></td>';
|
||||||
} else {
|
} else {
|
||||||
@@ -164,7 +169,7 @@ async function loadHistory(page) {
|
|||||||
html += '</tr>';
|
html += '</tr>';
|
||||||
});
|
});
|
||||||
if (res.data.records.length === 0) {
|
if (res.data.records.length === 0) {
|
||||||
var colSpan = canRevoke ? 7 : 6;
|
var colSpan = canAct ? 7 : 6;
|
||||||
html = '<tr><td colspan="' + colSpan + '" style="text-align:center;">暂无记录</td></tr>';
|
html = '<tr><td colspan="' + colSpan + '" style="text-align:center;">暂无记录</td></tr>';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -179,7 +184,7 @@ async function loadHistory(page) {
|
|||||||
'<td>' + escapeHtml(record.student_name) + '</td>' +
|
'<td>' + escapeHtml(record.student_name) + '</td>' +
|
||||||
'<td>' + escapeHtml(record.recorder_name) + '</td>' +
|
'<td>' + escapeHtml(record.recorder_name) + '</td>' +
|
||||||
'<td class="history-time">' + formatDateTime(record.created_at) + '</td>';
|
'<td class="history-time">' + formatDateTime(record.created_at) + '</td>';
|
||||||
if (canRevoke) {
|
if (canAct) {
|
||||||
if (record.is_revoked == 1) {
|
if (record.is_revoked == 1) {
|
||||||
var revokerInfo = record.revoker_name ? '由 ' + escapeHtml(record.revoker_name) + ' 撤销' : '已撤销';
|
var revokerInfo = record.revoker_name ? '由 ' + escapeHtml(record.revoker_name) + ' 撤销' : '已撤销';
|
||||||
if (canRestore) {
|
if (canRestore) {
|
||||||
@@ -197,7 +202,7 @@ async function loadHistory(page) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (res.data.records.length === 0) {
|
if (res.data.records.length === 0) {
|
||||||
var colSpan = canRevoke ? 7 : 6;
|
var colSpan = canAct ? 7 : 6;
|
||||||
html = '<tr><td colspan="' + colSpan + '" style="text-align:center;">暂无记录</td></tr>';
|
html = '<tr><td colspan="' + colSpan + '" style="text-align:center;">暂无记录</td></tr>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -358,7 +363,8 @@ async function batchRevokeGrouped(reason, pointsChange, recorderName, createdAt)
|
|||||||
|
|
||||||
var matchedIds = [];
|
var matchedIds = [];
|
||||||
res.data.records.forEach(function(r) {
|
res.data.records.forEach(function(r) {
|
||||||
if (r.reason === reason && r.points_change === pointsChange && r.is_revoked == 0) {
|
if (r.reason === reason && r.points_change === pointsChange && r.is_revoked == 0
|
||||||
|
&& (!recorderName || r.recorder_name === recorderName)) {
|
||||||
matchedIds.push(r.record_id);
|
matchedIds.push(r.record_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -370,7 +376,7 @@ async function batchRevokeGrouped(reason, pointsChange, recorderName, createdAt)
|
|||||||
|
|
||||||
var revokeRes = await apiPost('/api/admin/conduct/batch-revoke', { record_ids: matchedIds });
|
var revokeRes = await apiPost('/api/admin/conduct/batch-revoke', { record_ids: matchedIds });
|
||||||
if (revokeRes && revokeRes.success) {
|
if (revokeRes && revokeRes.success) {
|
||||||
showToast('批量撤销完成: ' + (revokeRes.data ? revokeRes.data.success_count : 0) + '条成功');
|
showToast('批量撤销完成: ' + (revokeRes.data ? revokeRes.data.success_count : 0) + '条(已移入“已撤销”,可筛选查看/批量反撤销)');
|
||||||
loadHistory(currentHistoryPage);
|
loadHistory(currentHistoryPage);
|
||||||
} else {
|
} else {
|
||||||
showToast(revokeRes && revokeRes.message || '批量撤销失败', 'error');
|
showToast(revokeRes && revokeRes.message || '批量撤销失败', 'error');
|
||||||
@@ -380,6 +386,55 @@ async function batchRevokeGrouped(reason, pointsChange, recorderName, createdAt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 批量反撤销合并记录(按条件查找并恢复)
|
||||||
|
async function batchRestoreGrouped(reason, pointsChange, recorderName) {
|
||||||
|
if (!confirm('确定要反撤销所有"' + reason + '"(' + (pointsChange > 0 ? '+' : '') + pointsChange + '分)的记录吗?')) return;
|
||||||
|
|
||||||
|
showToast('正在批量反撤销...', 'info');
|
||||||
|
|
||||||
|
try {
|
||||||
|
var params = {
|
||||||
|
page: 1, page_size: 1000,
|
||||||
|
start_date: document.getElementById('historyStartDate').value,
|
||||||
|
end_date: document.getElementById('historyEndDate').value,
|
||||||
|
reason_prefix: reason.substring(0, 4),
|
||||||
|
grouped: false,
|
||||||
|
is_revoked: 1
|
||||||
|
};
|
||||||
|
var semesterSelect = document.getElementById('historySemesterFilter');
|
||||||
|
if (semesterSelect && semesterSelect.value) params.semester_id = semesterSelect.value;
|
||||||
|
|
||||||
|
var res = await apiGet('/api/admin/conduct/history', params);
|
||||||
|
if (!res || !res.success || !res.data.records) {
|
||||||
|
showToast('查询记录失败', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var matchedIds = [];
|
||||||
|
res.data.records.forEach(function(r) {
|
||||||
|
if (r.reason === reason && r.points_change === pointsChange && r.is_revoked == 1
|
||||||
|
&& (!recorderName || r.recorder_name === recorderName)) {
|
||||||
|
matchedIds.push(r.record_id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (matchedIds.length === 0) {
|
||||||
|
showToast('没有找到可反撤销的记录', 'warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var restoreRes = await apiPost('/api/admin/conduct/batch-restore', { record_ids: matchedIds });
|
||||||
|
if (restoreRes && restoreRes.success) {
|
||||||
|
showToast('批量反撤销完成: ' + (restoreRes.data ? restoreRes.data.success_count : 0) + '条成功(记录已恢复正常)');
|
||||||
|
loadHistory(currentHistoryPage);
|
||||||
|
} else {
|
||||||
|
showToast((restoreRes && restoreRes.message) || '批量反撤销失败', 'error');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
showToast('批量反撤销失败: ' + err.message, 'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化:并行加载学生、科目、学期列表,然后加载历史记录
|
// 初始化:并行加载学生、科目、学期列表,然后加载历史记录
|
||||||
Promise.all([loadStudentsForSelect(), loadSubjectsForFilter(), loadSemestersForFilter()]).then(function() {
|
Promise.all([loadStudentsForSelect(), loadSubjectsForFilter(), loadSemestersForFilter()]).then(function() {
|
||||||
var urlParams = new URLSearchParams(window.location.search);
|
var urlParams = new URLSearchParams(window.location.search);
|
||||||
@@ -396,6 +451,7 @@ window.loadStudentsForSelect = loadStudentsForSelect;
|
|||||||
window.showExportHistoryModal = showExportHistoryModal;
|
window.showExportHistoryModal = showExportHistoryModal;
|
||||||
window.exportHistoryRecords = exportHistoryRecords;
|
window.exportHistoryRecords = exportHistoryRecords;
|
||||||
window.batchRevokeGrouped = batchRevokeGrouped;
|
window.batchRevokeGrouped = batchRevokeGrouped;
|
||||||
|
window.batchRestoreGrouped = batchRestoreGrouped;
|
||||||
window.onStudentFilterChange = onStudentFilterChange;
|
window.onStudentFilterChange = onStudentFilterChange;
|
||||||
window.onSubjectFilterChange = onSubjectFilterChange;
|
window.onSubjectFilterChange = onSubjectFilterChange;
|
||||||
window.toggleFilterPanel = toggleFilterPanel;
|
window.toggleFilterPanel = toggleFilterPanel;
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
const hwNotSubmit = window.DEDUCTION_HOMEWORK_NOT_SUBMIT || 2;
|
const hwNotSubmit = window.DEDUCTION_HOMEWORK_NOT_SUBMIT || 2;
|
||||||
const hwLate = window.DEDUCTION_HOMEWORK_LATE || 1;
|
const hwLate = window.DEDUCTION_HOMEWORK_LATE || 1;
|
||||||
|
|
||||||
|
let studentsData = [];
|
||||||
|
|
||||||
// 更新页面中的配置值显示(加减分上限来自权限组动态配置)
|
// 更新页面中的配置值显示(加减分上限来自权限组动态配置)
|
||||||
document.querySelectorAll('.hw-not-submit').forEach(el => el.textContent = hwNotSubmit);
|
document.querySelectorAll('.hw-not-submit').forEach(el => el.textContent = hwNotSubmit);
|
||||||
document.querySelectorAll('.hw-late').forEach(el => el.textContent = hwLate);
|
document.querySelectorAll('.hw-late').forEach(el => el.textContent = hwLate);
|
||||||
@@ -43,6 +45,7 @@ async function loadSubjectsForHomework() {
|
|||||||
async function loadStudents() {
|
async function loadStudents() {
|
||||||
const res = await apiGet('/api/admin/students', {page_size: 1000});
|
const res = await apiGet('/api/admin/students', {page_size: 1000});
|
||||||
if (res && res.success) {
|
if (res && res.success) {
|
||||||
|
studentsData = res.data.students || [];
|
||||||
let html = '';
|
let html = '';
|
||||||
res.data.students.forEach(student => {
|
res.data.students.forEach(student => {
|
||||||
html += `<tr>
|
html += `<tr>
|
||||||
@@ -266,9 +269,8 @@ async function submitEditSubject() {
|
|||||||
// ========== 作业按次登记 ==========
|
// ========== 作业按次登记 ==========
|
||||||
|
|
||||||
async function showHomeworkRegisterModal() {
|
async function showHomeworkRegisterModal() {
|
||||||
const checked = Array.from(document.querySelectorAll('.student-checkbox:checked'));
|
if (!studentsData || studentsData.length === 0) {
|
||||||
if (checked.length === 0) {
|
showToast('学生列表尚未加载,请稍后重试', 'warning');
|
||||||
showToast('请先在学生列表中勾选缺交学生', 'warning');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,16 +285,13 @@ async function showHomeworkRegisterModal() {
|
|||||||
}
|
}
|
||||||
subjectSelect.innerHTML = options;
|
subjectSelect.innerHTML = options;
|
||||||
|
|
||||||
// 缺交学生列表(每人可填缺交次数)
|
// 默认列出全部学生,缺交次数默认 0(0 = 已交)
|
||||||
let html = '';
|
let html = '';
|
||||||
checked.forEach(cb => {
|
studentsData.forEach(student => {
|
||||||
const row = cb.closest('tr');
|
|
||||||
const no = row ? row.children[1].textContent.trim() : '';
|
|
||||||
const name = row ? row.children[2].textContent.trim() : '';
|
|
||||||
html += `<div class="hw-reg-item">
|
html += `<div class="hw-reg-item">
|
||||||
<span class="hw-reg-name">${escapeHtml(name)} <small>${escapeHtml(no)}</small></span>
|
<span class="hw-reg-name">${escapeHtml(student.name)} <small>${escapeHtml(student.student_no)}</small></span>
|
||||||
<span class="hw-reg-miss-label" style="margin-left:auto;">缺交</span>
|
<span class="hw-reg-miss-label" style="margin-left:auto;">缺交</span>
|
||||||
<input type="number" class="hw-reg-miss" data-id="${cb.dataset.id}" min="1" value="1" style="width:64px;">
|
<input type="number" class="hw-reg-miss" data-id="${student.student_id}" min="0" value="0" style="width:64px;">
|
||||||
<span class="hw-reg-miss-label">次</span>
|
<span class="hw-reg-miss-label">次</span>
|
||||||
</div>`;
|
</div>`;
|
||||||
});
|
});
|
||||||
@@ -325,20 +324,17 @@ async function submitHomeworkRegister() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const inputs = Array.from(document.querySelectorAll('.hw-reg-miss'));
|
const inputs = Array.from(document.querySelectorAll('.hw-reg-miss'));
|
||||||
if (inputs.length === 0) {
|
|
||||||
showToast('请先在学生列表中勾选缺交学生', 'warning');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const records = [];
|
const records = [];
|
||||||
for (const input of inputs) {
|
for (const input of inputs) {
|
||||||
const miss = parseInt(input.value);
|
const miss = parseInt(input.value) || 0;
|
||||||
if (!miss || miss < 1 || miss > totalTimes) {
|
if (miss < 0 || miss > totalTimes) {
|
||||||
showToast('缺交次数需在1~总提交次数之间', 'warning');
|
showToast('缺交次数需在0~总提交次数之间', 'warning');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (miss > 0) {
|
||||||
records.push({ student_id: parseInt(input.dataset.id), miss_count: miss });
|
records.push({ student_id: parseInt(input.dataset.id), miss_count: miss });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
subject_id: subjectId,
|
subject_id: subjectId,
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ const OPERATION_TYPES = {
|
|||||||
add_calendar_day: '添加校历设置',
|
add_calendar_day: '添加校历设置',
|
||||||
remove_calendar_day: '删除校历设置',
|
remove_calendar_day: '删除校历设置',
|
||||||
homework_register: '作业按次登记',
|
homework_register: '作业按次登记',
|
||||||
|
batch_revoke: '批量撤销记录',
|
||||||
|
batch_restore: '批量反撤销记录',
|
||||||
add_admin: '添加管理员',
|
add_admin: '添加管理员',
|
||||||
reactivate_admin: '重新激活管理员',
|
reactivate_admin: '重新激活管理员',
|
||||||
update_admin: '编辑管理员',
|
update_admin: '编辑管理员',
|
||||||
@@ -84,6 +86,7 @@ async function loadLogs(page) {
|
|||||||
page_size: 20,
|
page_size: 20,
|
||||||
operation_type: document.getElementById('logTypeFilter').value,
|
operation_type: document.getElementById('logTypeFilter').value,
|
||||||
operator: document.getElementById('logOperatorFilter').value.trim(),
|
operator: document.getElementById('logOperatorFilter').value.trim(),
|
||||||
|
keyword: document.getElementById('logKeywordFilter') ? document.getElementById('logKeywordFilter').value.trim() : '',
|
||||||
start_date: document.getElementById('logStartDate').value,
|
start_date: document.getElementById('logStartDate').value,
|
||||||
end_date: document.getElementById('logEndDate').value
|
end_date: document.getElementById('logEndDate').value
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -95,7 +95,7 @@
|
|||||||
|
|
||||||
const res = await apiPost('/api/admin/conduct/revoke', { record_id: recordId });
|
const res = await apiPost('/api/admin/conduct/revoke', { record_id: recordId });
|
||||||
if (res && res.success) {
|
if (res && res.success) {
|
||||||
showToast('撤销成功');
|
showToast('撤销成功,该记录已移入“已撤销”(可筛选查看/反撤销)');
|
||||||
loadHistory(currentHistoryPage);
|
loadHistory(currentHistoryPage);
|
||||||
} else {
|
} else {
|
||||||
showToast(res?.message || '撤销失败', 'error');
|
showToast(res?.message || '撤销失败', 'error');
|
||||||
@@ -108,7 +108,7 @@
|
|||||||
|
|
||||||
const res = await apiPost('/api/admin/conduct/restore', { record_id: recordId });
|
const res = await apiPost('/api/admin/conduct/restore', { record_id: recordId });
|
||||||
if (res && res.success) {
|
if (res && res.success) {
|
||||||
showToast('反撤销成功');
|
showToast('反撤销成功,该记录已恢复正常');
|
||||||
loadHistory(currentHistoryPage);
|
loadHistory(currentHistoryPage);
|
||||||
} else {
|
} else {
|
||||||
showToast(res?.message || '反撤销失败', 'error');
|
showToast(res?.message || '反撤销失败', 'error');
|
||||||
|
|||||||
Reference in new issue
Block a user