fix(admin): 优化管理控制台报表显示

This commit is contained in:
sophie committed 2026-07-13 16:20:29 +08:00
1 parent 1ee4c69dee
commit b2fa2688a3
16 files changed
+1326 -157

No files matched your search

@@ -3,7 +3,7 @@ backend/app/services/admin/database_admin_service.py
用途:管理后台通用数据表浏览与 chat_logs 批量删除。
依赖:models、report_service(chat_logs 报表复用)。
逻辑:由 api/admin/database.py 调用。
逻辑:由 api/admin/database.py 调用;整型筛选字段对纯数字条件使用等值匹配。
"""
from __future__ import annotations
@@ -66,7 +66,12 @@ def get_table_data(table: str, query_params: dict[str, str]) -> list[dict]:
for key, value in query_params.items():
if hasattr(model, key) and value:
col = getattr(model, key)
query = query.filter(col.cast(db.String).ilike(f'%{value}%'))
col_type = getattr(col, 'type', None)
# 整型外键(如 agent_id)用等值过滤,避免 ILIKE '%16%' 误匹配 160
if value.isdigit() and col_type is not None and getattr(col_type, 'python_type', None) is int:
query = query.filter(col == int(value))
else:
query = query.filter(col.cast(db.String).ilike(f'%{value}%'))
items = query.limit(100).all()
return [_serialize_model_row(item) for item in items]