fix(billing): separate ns for stats query, avoid sqlor ns mutation
This commit is contained in:
parent
1ffdda5ffe
commit
47844253fe
@ -28,18 +28,23 @@ where a.orgid = ${orgid}$
|
|||||||
and d.acc_date <= ${end_date}$"""
|
and d.acc_date <= ${end_date}$"""
|
||||||
rows = await sor.sqlExe(sql, ns)
|
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
|
stats_sql = """select
|
||||||
count(*) as total_count,
|
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 = '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,
|
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
|
|
||||||
from acc_detail d
|
from acc_detail d
|
||||||
join account a on d.accountid = a.id COLLATE utf8mb4_unicode_ci
|
join account a on d.accountid = a.id COLLATE utf8mb4_unicode_ci
|
||||||
where a.orgid = ${orgid}$
|
where a.orgid = ${orgid}$
|
||||||
and d.acc_date >= ${start_date}$
|
and d.acc_date >= ${start_date}$
|
||||||
and d.acc_date <= ${end_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 = {
|
stats = {
|
||||||
'total_count': int(stats_recs[0].total_count) if stats_recs else 0,
|
'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,
|
'debit_sum': float(stats_recs[0].debit_sum) if stats_recs else 0,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user