nex_docus/backend/app/models/log.py

29 lines
1.2 KiB
Python
Raw Normal View History

2025-12-20 11:18:59 +00:00
"""
操作日志模型
"""
from sqlalchemy import Column, BigInteger, String, Integer, DateTime, SmallInteger, Text
from sqlalchemy.sql import func
from app.core.database import Base
class OperationLog(Base):
"""操作日志表模型"""
__tablename__ = "operation_logs"
id = Column(BigInteger, primary_key=True, autoincrement=True, comment="日志ID")
user_id = Column(BigInteger, index=True, comment="操作用户ID")
username = Column(String(50), comment="用户名")
operation_type = Column(String(50), nullable=False, comment="操作类型")
resource_type = Column(String(50), nullable=False, index=True, comment="资源类型")
resource_id = Column(BigInteger, index=True, comment="资源ID")
detail = Column(Text, comment="操作详情JSON")
ip_address = Column(String(50), comment="IP地址")
user_agent = Column(String(500), comment="用户代理")
status = Column(SmallInteger, default=1, comment="状态0-失败 1-成功")
error_message = Column(Text, comment="错误信息")
created_at = Column(DateTime, server_default=func.now(), index=True, comment="操作时间")
def __repr__(self):
return f"<OperationLog(id={self.id}, operation_type='{self.operation_type}')>"