feat: 日志自动清理 — 系统设置+定时任务+手动操作

1. 系统设置新增 cleanup 分组(6项配置):
   - 启用自动清理(开关)
   - 清理执行时间(默认凌晨3点)
   - 工单保留天数(默认90天)
   - 审计日志保留天数(默认180天)
   - 查询历史保留天数(默认30天)
   - 定时任务日志保留天数(默认30天)

2. log_cleanup.py: 自动清理服务
   - 只清理已完成/已拒绝的工单
   - 按保留天数过滤
   - 0天=不清理

3. APScheduler cron job: 每天03:00自动清理

4. API endpoints:
   - POST /settings/cleanup/run — 手动触发清理
   - GET /settings/cleanup/preview — 预览待清理数量

5. 前端 PlatformConfigPage:
   - GROUP_META 新增 cleanup 分组
   - CleanupActions 子组件: 预览+手动清理按钮

6. 清空所有历史工单数据(tickets/ticket_approvals/audit_logs/query_histories)
This commit is contained in:
logan committed 2026-05-25 00:19:38 +08:00
1 parent a8c92fe7ae
commit 00db0e5bca
5 files changed
+352

No files matched your search

+63
View File
@@ -126,6 +126,68 @@ SEED_SETTINGS = [
"default_value": "true",
"sort_order": 21,
},
# ── 日志清理 ──
{
"key": "cleanup_enabled",
"value": "true",
"value_type": "boolean",
"group": "cleanup",
"label": "启用自动清理",
"description": "开启后每天凌晨自动清理过期记录",
"default_value": "true",
"sort_order": 30,
},
{
"key": "cleanup_run_hour",
"value": "3",
"value_type": "integer",
"group": "cleanup",
"label": "清理执行时间(时)",
"description": "每天几点执行自动清理(0-23),默认凌晨 3 点",
"default_value": "3",
"sort_order": 31,
},
{
"key": "cleanup_ticket_days",
"value": "90",
"value_type": "integer",
"group": "cleanup",
"label": "数据变更工单保留天数",
"description": "已完成/已拒绝的工单超过保留天数将被自动清理(0 表示不清理)",
"default_value": "90",
"sort_order": 32,
},
{
"key": "cleanup_audit_log_days",
"value": "180",
"value_type": "integer",
"group": "cleanup",
"label": "审计日志保留天数",
"description": "审计日志超过保留天数将被自动清理(0 表示不清理)",
"default_value": "180",
"sort_order": 33,
},
{
"key": "cleanup_query_history_days",
"value": "30",
"value_type": "integer",
"group": "cleanup",
"label": "查询历史保留天数",
"description": "查询历史超过保留天数将被自动清理(0 表示不清理)",
"default_value": "30",
"sort_order": 34,
},
{
"key": "cleanup_scheduled_task_log_days",
"value": "30",
"value_type": "integer",
"group": "cleanup",
"label": "定时任务日志保留天数",
"description": "定时任务执行日志超过保留天数将被自动清理(0 表示不清理)",
"default_value": "30",
"sort_order": 35,
},
]
# 分组元信息
@@ -133,4 +195,5 @@ SETTING_GROUPS = {
"query": {"label": "查询控制", "icon": "🔍", "description": "控制查询行为、LIMIT、超时和脱敏策略"},
"security": {"label": "安全设置", "icon": "🔒", "description": "登录安全、密码策略、审计日志"},
"ticket": {"label": "工单设置", "icon": "📋", "description": "审批流程、回滚策略"},
"cleanup": {"label": "日志清理", "icon": "🧹", "description": "数据变更工单、审计日志、查询历史的自动清理策略"},
}