From 47844253fe03150901bfce21fbdf3e9a4db59a42 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 16 Jul 2026 17:32:05 +0800 Subject: [PATCH] fix(billing): separate ns for stats query, avoid sqlor ns mutation --- wwwroot/billing.dspy | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/wwwroot/billing.dspy b/wwwroot/billing.dspy index 0d6cfea..89df46c 100644 --- a/wwwroot/billing.dspy +++ b/wwwroot/billing.dspy @@ -28,18 +28,23 @@ where a.orgid = ${orgid}$ and d.acc_date <= ${end_date}$""" rows = await sor.sqlExe(sql, ns) - # 统计数据 + # 统计数据 — 独立 ns 避免被 sqlor 修改 + stats_ns = { + 'orgid': userorgid, + 'start_date': start_date, + 'end_date': end_date, + 'sort': '1' + } stats_sql = """select count(*) as total_count, coalesce(sum(case when d.acc_dir = '1' then d.amount else 0 end), 0) as debit_sum, - coalesce(sum(case when d.acc_dir = '0' then d.amount else 0 end), 0) as credit_sum, - min(d.acc_date) as acc_date + coalesce(sum(case when d.acc_dir = '0' then d.amount else 0 end), 0) as credit_sum from acc_detail d join account a on d.accountid = a.id COLLATE utf8mb4_unicode_ci where a.orgid = ${orgid}$ and d.acc_date >= ${start_date}$ and d.acc_date <= ${end_date}$""" - stats_recs = await sor.sqlExe(stats_sql, ns) + stats_recs = await sor.sqlExe(stats_sql, stats_ns) stats = { 'total_count': int(stats_recs[0].total_count) if stats_recs else 0, 'debit_sum': float(stats_recs[0].debit_sum) if stats_recs else 0,