fix: collation mismatch in SQL JOINs + billing date fields use uitype:date

This commit is contained in:
yumoqing 2026-05-31 11:44:58 +08:00
parent 997c7a445e
commit 8a3f1955d3
6 changed files with 35 additions and 38 deletions

View File

@ -56,9 +56,9 @@ async def get_my_credit_list(sor, orgid):
ELSE 0
END as usage_pct
FROM credit_limit cl
LEFT JOIN organization org ON cl.orgid = org.id
LEFT JOIN account acc ON cl.accountid = acc.id
LEFT JOIN subject sub ON acc.subjectid = sub.id
LEFT JOIN organization org ON cl.orgid = org.id COLLATE utf8mb4_unicode_ci
LEFT JOIN account acc ON cl.accountid = acc.id COLLATE utf8mb4_unicode_ci
LEFT JOIN subject sub ON acc.subjectid = sub.id COLLATE utf8mb4_unicode_ci
WHERE cl.orgid = ${orgid}$
ORDER BY cl.created_at DESC
"""
@ -88,9 +88,9 @@ async def get_all_customer_credits(sor, orgid, status_filter=None):
ELSE 0
END as usage_pct
FROM credit_limit cl
LEFT JOIN organization org ON cl.orgid = org.id
LEFT JOIN account acc ON cl.accountid = acc.id
LEFT JOIN subject sub ON acc.subjectid = sub.id
LEFT JOIN organization org ON cl.orgid = org.id COLLATE utf8mb4_unicode_ci
LEFT JOIN account acc ON cl.accountid = acc.id COLLATE utf8mb4_unicode_ci
LEFT JOIN subject sub ON acc.subjectid = sub.id COLLATE utf8mb4_unicode_ci
{where_clause}
ORDER BY cl.updated_at DESC
"""

View File

@ -42,7 +42,7 @@ async def get_accounting_stats(request):
sql_today = """
SELECT COALESCE(SUM(amount), 0) as total
FROM acc_detail a
JOIN account b ON a.accountid = b.id
JOIN account b ON a.accountid = b.id COLLATE utf8mb4_unicode_ci
WHERE b.orgid = ${orgid}$
AND a.acc_dir = 1
AND a.acc_date >= ${from_date}$
@ -60,7 +60,7 @@ async def get_accounting_stats(request):
sql_month = """
SELECT COALESCE(SUM(amount), 0) as total
FROM acc_detail a
JOIN account b ON a.accountid = b.id
JOIN account b ON a.accountid = b.id COLLATE utf8mb4_unicode_ci
WHERE b.orgid = ${orgid}$
AND a.acc_dir = 1
AND a.acc_date >= ${from_date}$

View File

@ -21,8 +21,8 @@ async with get_sor_context(request._run_ns, 'accounting') as sor:
sql = """select d.acc_date, d.acc_timestamp, d.acc_dir, d.summary,
d.amount, d.balance, s.name as subject_name
from acc_detail d
join account a on d.accountid = a.id
join subject s on a.subjectid = s.id
join account a on d.accountid = a.id COLLATE utf8mb4_unicode_ci
join subject s on a.subjectid = s.id COLLATE utf8mb4_unicode_ci
where a.orgid = ${orgid}$
and d.acc_date >= ${start_date}$
and d.acc_date <= ${end_date}$"""

View File

@ -22,13 +22,13 @@
{
"name":"start_date",
"label":"开始日期",
"uitype":"str",
"uitype":"date",
"value":"{{start_date}}"
},
{
"name":"end_date",
"label":"结束日期",
"uitype":"str",
"uitype":"date",
"value":"{{end_date}}"
}
],

View File

@ -28,18 +28,17 @@
"widgettype": "VBox",
"options": {
"bgcolor": "#1E293B",
"padding": "16px",
"padding": "12px",
"borderRadius": "10px",
"border": "1px solid #334155",
"flex": "1",
"minHeight": "100px"
"flex": "none"
},
"subwidgets": [
{
"widgettype": "HBox",
"options": {
"alignItems": "center",
"marginBottom": "8px"
"marginBottom": "6px"
},
"subwidgets": [
{
@ -57,7 +56,7 @@
"widgettype": "Text",
"options": {
"text": "¥{{'%.2f' % cstats.total_credit}}",
"fontSize": "26px",
"fontSize": "22px",
"fontWeight": "700",
"color": "#3B82F6",
"lineHeight": "1.2"
@ -69,7 +68,7 @@
"text": "授信总额度",
"fontSize": "13px",
"color": "#94A3B8",
"marginTop": "4px"
"marginTop": "2px"
}
}
]
@ -78,18 +77,17 @@
"widgettype": "VBox",
"options": {
"bgcolor": "#1E293B",
"padding": "16px",
"padding": "12px",
"borderRadius": "10px",
"border": "1px solid #334155",
"flex": "1",
"minHeight": "100px"
"flex": "none"
},
"subwidgets": [
{
"widgettype": "HBox",
"options": {
"alignItems": "center",
"marginBottom": "8px"
"marginBottom": "6px"
},
"subwidgets": [
{
@ -107,7 +105,7 @@
"widgettype": "Text",
"options": {
"text": "¥{{'%.2f' % cstats.total_used}}",
"fontSize": "26px",
"fontSize": "22px",
"fontWeight": "700",
"color": "#F59E0B",
"lineHeight": "1.2"
@ -119,7 +117,7 @@
"text": "已用额度",
"fontSize": "13px",
"color": "#94A3B8",
"marginTop": "4px"
"marginTop": "2px"
}
}
]
@ -128,18 +126,17 @@
"widgettype": "VBox",
"options": {
"bgcolor": "#1E293B",
"padding": "16px",
"padding": "12px",
"borderRadius": "10px",
"border": "1px solid #334155",
"flex": "1",
"minHeight": "100px"
"flex": "none"
},
"subwidgets": [
{
"widgettype": "HBox",
"options": {
"alignItems": "center",
"marginBottom": "8px"
"marginBottom": "6px"
},
"subwidgets": [
{
@ -157,7 +154,7 @@
"widgettype": "Text",
"options": {
"text": "¥{{'%.2f' % cstats.total_available}}",
"fontSize": "26px",
"fontSize": "22px",
"fontWeight": "700",
"color": "#22C55E",
"lineHeight": "1.2"
@ -169,7 +166,7 @@
"text": "剩余额度",
"fontSize": "13px",
"color": "#94A3B8",
"marginTop": "4px"
"marginTop": "2px"
}
}
]
@ -178,18 +175,17 @@
"widgettype": "VBox",
"options": {
"bgcolor": "#1E293B",
"padding": "16px",
"padding": "12px",
"borderRadius": "10px",
"border": "1px solid #334155",
"flex": "1",
"minHeight": "100px"
"flex": "none"
},
"subwidgets": [
{
"widgettype": "HBox",
"options": {
"alignItems": "center",
"marginBottom": "8px"
"marginBottom": "6px"
},
"subwidgets": [
{
@ -207,7 +203,7 @@
"widgettype": "Text",
"options": {
"text": "{{cstats.usage_pct}}%",
"fontSize": "26px",
"fontSize": "22px",
"fontWeight": "700",
"color": "#A78BFA",
"lineHeight": "1.2"
@ -219,7 +215,7 @@
"text": "额度使用率 ({{cstats.active_count}}/{{cstats.customer_count}}户)",
"fontSize": "13px",
"color": "#94A3B8",
"marginTop": "4px"
"marginTop": "2px"
}
}
]
@ -294,7 +290,8 @@
"id": "credit_content",
"options": {
"width": "100%",
"flex": "1"
"css": "filler",
"marginTop": "8px"
}
}
]

View File

@ -1,7 +1,7 @@
{
"widgettype": "VBox",
"options": {
"cheight": 40,
"height": "100%",
"width": "100%"
},
"subwidgets": [