feat(conduct): add restore revoked record functionality and update history view
This commit is contained in:
@@ -152,6 +152,42 @@ class ConductService:
|
||||
else:
|
||||
return {"success": False, "message": "撤销失败"}
|
||||
|
||||
@staticmethod
|
||||
async def restore_record(record_id: int, restorer_id: int) -> Dict[str, Any]:
|
||||
"""反撤销(恢复)已撤销的记录"""
|
||||
# 检查权限:只有班主任可以反撤销
|
||||
role = await PermissionChecker.get_user_role(restorer_id)
|
||||
if role != "班主任":
|
||||
return {"success": False, "message": "仅班主任可反撤销记录"}
|
||||
|
||||
# 获取原记录信息
|
||||
record = await ConductModel.get_record_by_id(record_id)
|
||||
if not record:
|
||||
return {"success": False, "message": "记录不存在"}
|
||||
|
||||
if not record.get("is_revoked"):
|
||||
return {"success": False, "message": "该记录未被撤销,无需恢复"}
|
||||
|
||||
# 恢复记录
|
||||
result = await ConductModel.restore_record(record_id, restorer_id)
|
||||
|
||||
if result:
|
||||
# 恢复学生总分(重新加上原来的分数变动)
|
||||
await StudentModel.update_total_points(record["student_id"], record["points_change"])
|
||||
logger.info(f"用户[{restorer_id}] 反撤销了记录[{record_id}]")
|
||||
return {
|
||||
"success": True,
|
||||
"message": "反撤销成功",
|
||||
"record": {
|
||||
"student_id": record["student_id"],
|
||||
"recorder_name": record.get("recorder_name", "未知"),
|
||||
"points_change": record["points_change"],
|
||||
"reason": record.get("reason", "")
|
||||
}
|
||||
}
|
||||
else:
|
||||
return {"success": False, "message": "反撤销失败"}
|
||||
|
||||
@staticmethod
|
||||
async def get_history(
|
||||
user_id: int,
|
||||
@@ -193,7 +229,7 @@ class ConductService:
|
||||
|
||||
# 获取总数
|
||||
from utils.database import execute_one
|
||||
count_conditions = ["cr.is_revoked = 0"]
|
||||
count_conditions = ["1=1"]
|
||||
count_params = []
|
||||
if student_id:
|
||||
count_conditions.append("cr.student_id = %s")
|
||||
|
||||
Reference in New Issue
Block a user