unified_dashboard/wwwroot/api/report_list.dspy
yumoqing aec650dcef sync: local modifications to unified_dashboard
- Updated core.py, init.py, mysql.ddl.sql
- Added __init__.py
- Added API files: dashboard_kpi, report_list
- Added UI files: base.ui, dashboard.ui, reports.ui
2026-04-28 18:55:07 +08:00

36 lines
1.1 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Report list API"""
import json
result = {'success': False, 'rows': [], 'total': 0}
try:
dbname = get_module_dbname('unified_dashboard')
ns = {
'page': int(params_kw.get('page', 1)),
'rows': int(params_kw.get('rows', 20)),
'sort': 'created_at desc'
}
sql = "SELECT id, template_name, category, description, is_active, created_at FROM report_template WHERE 1=1"
keyword = params_kw.get('keyword', '').strip()
if keyword:
sql += " AND template_name LIKE ${keyword}$"
ns['keyword'] = f'%{keyword}%'
async with DBPools().sqlorContext(dbname) as sor:
data = await sor.sqlExe(sql, ns)
if isinstance(data, dict):
result['total'] = data.get('total', 0)
result['rows'] = [dict(r) for r in data.get('rows', [])]
else:
result['rows'] = [dict(r) for r in (data or [])]
result['total'] = len(result['rows'])
result['success'] = True
except Exception as e:
result['error'] = str(e)
return json.dumps(result, ensure_ascii=False, default=str)