fix: get_realtime_stats用int(r.xxx or 0)替代hasattr,处理SQL返回NULL

This commit is contained in:
yumoqing 2026-07-23 11:17:55 +08:00
parent 135b394b2a
commit dbcf33ff8c

View File

@ -104,13 +104,13 @@ async def get_realtime_stats(sor, today, scope=None, org_filter=None):
recs = await sor.sqlExe(sql, ns) recs = await sor.sqlExe(sql, ns)
if recs: if recs:
r = recs[0] r = recs[0]
total = int(r.calls) if hasattr(r, 'calls') else r.get('calls', 0) total = int(r.calls or 0)
success = int(r.success) if hasattr(r, 'success') else r.get('success', 0) success = int(r.success or 0)
fail = int(r.fail) if hasattr(r, 'fail') else r.get('fail', 0) fail = int(r.fail or 0)
return { return {
'calls': total, 'calls': total,
'amount': round(float(r.amount) if hasattr(r, 'amount') else r.get('amount', 0), 2), 'amount': round(float(r.amount or 0), 2),
'active_users': int(r.active_users) if hasattr(r, 'active_users') else r.get('active_users', 0), 'active_users': int(r.active_users or 0),
'success_rate': round(success * 100.0 / total, 1) if total else 0, 'success_rate': round(success * 100.0 / total, 1) if total else 0,
'fail_count': fail, 'fail_count': fail,
} }