v0.6测试
This commit is contained in:
64
backend/models/log.py
Normal file
64
backend/models/log.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# ===========================================
|
||||
# 班级操行分管理系统 - 后端服务
|
||||
#
|
||||
# 开发者: Canglan
|
||||
# 联系方式: admin@sea-studio.top
|
||||
# 版权归属: Sea Network Technology Studio
|
||||
# 许可证: MIT License
|
||||
#
|
||||
# 版权所有 © Sea Network Technology Studio
|
||||
# ===========================================
|
||||
|
||||
from utils.database import execute_insert
|
||||
from utils.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
class LoginLogModel:
|
||||
"""登录日志数据模型"""
|
||||
|
||||
@staticmethod
|
||||
async def create(username: str, login_result: int, ip_address: str, user_agent: str = None, fail_reason: str = None) -> int:
|
||||
"""
|
||||
写入登录日志
|
||||
:param username: 用户名
|
||||
:param login_result: 登录结果 (1=成功, 0=失败)
|
||||
:param ip_address: IP地址
|
||||
:param user_agent: 浏览器UA
|
||||
:param fail_reason: 失败原因
|
||||
:return: log_id
|
||||
"""
|
||||
sql = """
|
||||
INSERT INTO login_logs (username, login_result, fail_reason, ip_address, user_agent)
|
||||
VALUES (%s, %s, %s, %s, %s)
|
||||
"""
|
||||
return await execute_insert(sql, (username, login_result, fail_reason, ip_address, user_agent))
|
||||
|
||||
|
||||
class OperationLogModel:
|
||||
"""操作日志数据模型"""
|
||||
|
||||
@staticmethod
|
||||
async def create(operator_id: int, operator_name: str, operator_role: str,
|
||||
operation_type: str, target_type: str = None, target_id: int = None,
|
||||
details: str = None, ip_address: str = None) -> int:
|
||||
"""
|
||||
写入操作日志
|
||||
:param operator_id: 操作者用户ID
|
||||
:param operator_name: 操作者用户名
|
||||
:param operator_role: 操作者角色
|
||||
:param operation_type: 操作类型
|
||||
:param target_type: 目标类型
|
||||
:param target_id: 目标ID
|
||||
:param details: 详细信息
|
||||
:param ip_address: IP地址
|
||||
:return: log_id
|
||||
"""
|
||||
sql = """
|
||||
INSERT INTO operation_logs (operator_id, operator_name, operator_role,
|
||||
operation_type, target_type, target_id, details, ip_address)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
|
||||
"""
|
||||
return await execute_insert(sql, (operator_id, operator_name, operator_role,
|
||||
operation_type, target_type, target_id, details, ip_address))
|
||||
Reference in New Issue
Block a user