32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
"""系统操作日志模型。"""
|
|
from sqlalchemy import Column, Integer, String, TIMESTAMP, func, JSON
|
|
from insurance.db.compat import db
|
|
|
|
|
|
class SystemOperationLog(db.Model):
|
|
"""系统操作审计日志。"""
|
|
__tablename__ = "system_operation_logs"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
user_id = Column(String(64), nullable=False, index=True)
|
|
action = Column(String(32), nullable=False, index=True)
|
|
target_type = Column(String(32))
|
|
target_id = Column(String(64))
|
|
detail = Column(JSON)
|
|
ip = Column(String(45))
|
|
user_agent = Column(String(256))
|
|
created_at = Column(TIMESTAMP, server_default=func.now(), index=True)
|
|
|
|
def to_dict(self):
|
|
return {
|
|
"id": self.id,
|
|
"user_id": self.user_id,
|
|
"action": self.action,
|
|
"target_type": self.target_type,
|
|
"target_id": self.target_id,
|
|
"detail": self.detail,
|
|
"ip": self.ip,
|
|
"user_agent": self.user_agent,
|
|
"created_at": str(self.created_at) if self.created_at else None,
|
|
}
|