From 647e63eb04bc5d1f6444517c2e8a2815ffad36ab Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 12 Jun 2026 15:23:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20failed=5Faccounting.ui=20-=20Combobox?= =?UTF-8?q?=E2=86=92UiCode,=20=E7=A7=BB=E9=99=A4formatter,=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Ddspy=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wwwroot/api/failed_accounting_list.dspy | 20 ++++++++------------ wwwroot/api/retry_accounting.dspy | 14 ++++---------- wwwroot/failed_accounting.ui | 15 +++++++-------- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/wwwroot/api/failed_accounting_list.dspy b/wwwroot/api/failed_accounting_list.dspy index ec7af7d..2bc7703 100644 --- a/wwwroot/api/failed_accounting_list.dspy +++ b/wwwroot/api/failed_accounting_list.dspy @@ -1,20 +1,14 @@ -#!/usr/bin/env python3 -import json -import os - result = {'success': False, 'rows': [], 'total': 0, 'page': 1, 'page_size': 50} try: dbname = get_module_dbname('llmage') - user_orgid = await get_userorgid() - # Extract filter parameters from params_kw filters = {} if params_kw.get('userorgid'): filters['userorgid'] = params_kw.get('userorgid') if params_kw.get('llmid'): filters['llmid'] = params_kw.get('llmid') - if params_kw.get('handled') is not None: + if params_kw.get('handled') is not None and params_kw.get('handled') != '': filters['handled'] = params_kw.get('handled') if params_kw.get('start_date'): filters['start_date'] = params_kw.get('start_date') @@ -25,11 +19,9 @@ try: page_size = int(params_kw.get('page_size', 50)) async with DBPools().sqlorContext(dbname) as sor: - # Build dynamic SQL conditions = [] ns = {} - # Default: show unhandled records if 'handled' not in filters: conditions.append("handled='0'") @@ -53,18 +45,22 @@ try: if conditions: where = "where " + " and ".join(conditions) - # Count total count_sql = f"select count(*) as cnt from llmusage_accounting_failed {where}" count_recs = await sor.sqlExe(count_sql, ns) total = count_recs[0].cnt if count_recs else 0 - # Query with pagination offset = (page - 1) * page_size query_sql = f"""select * from llmusage_accounting_failed {where} order by failed_time desc limit {page_size} offset {offset}""" recs = await sor.sqlExe(query_sql, ns) - result['rows'] = [dict(r) for r in (recs or [])] + rows = [] + for r in (recs or []): + d = dict(r) + d['handled'] = '已处理' if d.get('handled') == '1' else '未处理' + rows.append(d) + + result['rows'] = rows result['total'] = total result['page'] = page result['page_size'] = page_size diff --git a/wwwroot/api/retry_accounting.dspy b/wwwroot/api/retry_accounting.dspy index 3ec9eb5..837f9ca 100644 --- a/wwwroot/api/retry_accounting.dspy +++ b/wwwroot/api/retry_accounting.dspy @@ -1,7 +1,3 @@ -#!/usr/bin/env python3 -import json -from datetime import datetime - result = {'success': False, 'message': ''} try: @@ -11,14 +7,12 @@ try: result['message'] = '缺少llmusageid参数' else: async with DBPools().sqlorContext(dbname) as sor: - # 1. 重置 llmusage 记账状态为 created,让后台循环重新处理 await sor.U('llmusage', { 'id': luid, 'accounting_status': 'created' }) - - # 2. 更新失败记录:标记已处理,增加重试次数 - now = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + + now = curDateString() + ' ' + timestampstr().split(' ')[1] if ' ' not in curDateString() else curDateString() await sor.execute(""" UPDATE llmusage_accounting_failed SET handled = '1', @@ -27,10 +21,10 @@ try: handled_note = CONCAT(IFNULL(handled_note, ''), '[', ${now}$, '] 触发重试; ') WHERE llmusageid = ${luid}$ """, {'luid': luid, 'now': now}) - + result['success'] = True result['message'] = '已重置为待记账状态,后台循环将重新处理' except Exception as e: result['message'] = str(e) -return json.dumps(result, ensure_ascii=False, default=str) +return json.dumps(result, ensure_ascii=False) diff --git a/wwwroot/failed_accounting.ui b/wwwroot/failed_accounting.ui index 22874e1..c733dd5 100644 --- a/wwwroot/failed_accounting.ui +++ b/wwwroot/failed_accounting.ui @@ -27,7 +27,7 @@ "options": {"spacing": 4}, "subwidgets": [ {"widgettype": "Text", "options": {"text": "开始日期", "fontSize": "12px"}}, - {"widgettype": "UiDate", "id": "start_date", "options": {"width": "150px"}} + {"widgettype": "UiDate", "id": "start_date", "options": {"cwidth": 10}} ] }, { @@ -35,7 +35,7 @@ "options": {"spacing": 4}, "subwidgets": [ {"widgettype": "Text", "options": {"text": "结束日期", "fontSize": "12px"}}, - {"widgettype": "UiDate", "id": "end_date", "options": {"width": "150px"}} + {"widgettype": "UiDate", "id": "end_date", "options": {"cwidth": 10}} ] }, { @@ -44,10 +44,10 @@ "subwidgets": [ {"widgettype": "Text", "options": {"text": "处理状态", "fontSize": "12px"}}, { - "widgettype": "Combobox", + "widgettype": "UiCode", "id": "handled_filter", "options": { - "width": "120px", + "cwidth": 8, "data": [ {"value": "", "text": "全部"}, {"value": "0", "text": "未处理"}, @@ -69,7 +69,7 @@ "label": "查询", "bgcolor": "#1976d2", "color": "#ffffff", - "width": "80px" + "cwidth": 5 }, "binds": [{ "wid": "self", @@ -93,7 +93,7 @@ "label": "重试", "bgcolor": "#4caf50", "color": "#ffffff", - "width": "80px" + "cwidth": 5 }, "binds": [{ "wid": "self", @@ -127,8 +127,7 @@ {"name": "failed_reason", "title": "失败原因", "width": "30%"}, {"name": "failed_time", "title": "失败时间", "width": "160px"}, {"name": "retry_count", "title": "重试次数", "width": "80px"}, - {"name": "handled", "title": "状态", "width": "80px", - "formatter": "function(v){return v==='1'?'已处理':'未处理';}"} + {"name": "handled", "title": "状态", "width": "80px"} ] } }