39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
|
|
"""留存清理审计记录(仅保存脱敏标识)。"""
|
||
|
|
from sqlalchemy import BigInteger, Column, Index, Integer, String, Text, TIMESTAMP, func
|
||
|
|
|
||
|
|
from insurance.db.compat import db
|
||
|
|
|
||
|
|
|
||
|
|
AUDIT_ID_TYPE = BigInteger().with_variant(Integer, "sqlite")
|
||
|
|
|
||
|
|
|
||
|
|
class RetentionCleanupAudit(db.Model):
|
||
|
|
__tablename__ = "insurance_retention_cleanup_audits"
|
||
|
|
__table_args__ = (
|
||
|
|
Index("idx_retention_audits_created", "created_at"),
|
||
|
|
Index("idx_retention_audits_category_action", "category", "action"),
|
||
|
|
)
|
||
|
|
|
||
|
|
id = Column(AUDIT_ID_TYPE, primary_key=True, autoincrement=True)
|
||
|
|
category = Column(String(30), nullable=False)
|
||
|
|
target_type = Column(String(50), nullable=False)
|
||
|
|
target_id_hash = Column(String(64), nullable=False)
|
||
|
|
user_id_hash = Column(String(64), nullable=True)
|
||
|
|
action = Column(String(20), nullable=False)
|
||
|
|
reason = Column(String(200), nullable=False)
|
||
|
|
metadata_json = Column(Text, nullable=True)
|
||
|
|
created_at = Column(TIMESTAMP, server_default=func.now())
|
||
|
|
|
||
|
|
def to_public_dict(self):
|
||
|
|
import json
|
||
|
|
try:
|
||
|
|
metadata = json.loads(self.metadata_json) if self.metadata_json else {}
|
||
|
|
except (TypeError, ValueError):
|
||
|
|
metadata = {}
|
||
|
|
return {
|
||
|
|
"id": self.id, "category": self.category, "targetType": self.target_type,
|
||
|
|
"targetIdHash": self.target_id_hash, "action": self.action,
|
||
|
|
"reason": self.reason, "metadata": metadata,
|
||
|
|
"createdAt": self.created_at.isoformat() if self.created_at else None,
|
||
|
|
}
|