From 1e335d35cb6644e0082b66dc3b158563f6c3d6f0 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 24 May 2026 14:11:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(llmage):=20=E8=A7=84=E8=8C=83=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - accounting.py: 删除重复datetime导入, 清理未使用env变量 - failed_accounting.ui: Button text→label(规范), DatePicker→TextInput(不确定的widget) - index.ui: backgroundColor→bgcolor(规范), 3处修复 - llmusage_accounting_failed_update.dspy: 删除ServerEnv()违规(.dspy禁用), 用datetime替代 - 新增llmusage_history只读DSPY(create/update/delete返回只读提示) --- llmage/accounting.py | 4 +--- wwwroot/api/llmusage_accounting_failed_update.dspy | 5 ++--- wwwroot/api/llmusage_history_create.dspy | 4 ++++ wwwroot/api/llmusage_history_delete.dspy | 4 ++++ wwwroot/api/llmusage_history_update.dspy | 4 ++++ wwwroot/failed_accounting.ui | 6 +++--- wwwroot/index.ui | 6 +++--- 7 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 wwwroot/api/llmusage_history_create.dspy create mode 100644 wwwroot/api/llmusage_history_delete.dspy create mode 100644 wwwroot/api/llmusage_history_update.dspy diff --git a/llmage/accounting.py b/llmage/accounting.py index e985e23..c3a0fd6 100644 --- a/llmage/accounting.py +++ b/llmage/accounting.py @@ -242,7 +242,6 @@ async def llm_accoung_failed(luid, reason=None): async def backup_accounted_llmusage(): """Backup yesterday's accounted records to history table and remove from llmusage.""" env = ServerEnv() - from datetime import datetime, timedelta yesterday = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d') ts = env.timestampstr() batched = 0 @@ -295,8 +294,7 @@ async def get_failed_accounting_records(filters=None, page=1, page_size=50): - start_date: filter use_date >= start_date - end_date: filter use_date <= end_date """ - env = ServerEnv() - async with get_sor_context(env, 'llmage') as sor: + async with get_sor_context(ServerEnv(), 'llmage') as sor: conditions = [] ns = {} if filters: diff --git a/wwwroot/api/llmusage_accounting_failed_update.dspy b/wwwroot/api/llmusage_accounting_failed_update.dspy index 3ce34a1..40b9ba5 100644 --- a/wwwroot/api/llmusage_accounting_failed_update.dspy +++ b/wwwroot/api/llmusage_accounting_failed_update.dspy @@ -1,6 +1,6 @@ #!/usr/bin/env python3 import json -from ahserver.serverenv import ServerEnv +from datetime import datetime result = {'success': False, 'message': ''} @@ -15,8 +15,7 @@ try: data['id'] = rid # Mark as handled - set handled_time if data.get('handled') == '1' and not data.get('handled_time'): - env = ServerEnv() - data['handled_time'] = env.timestampstr() + data['handled_time'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S') await sor.U('llmusage_accounting_failed', data) result['success'] = True result['message'] = '更新成功' diff --git a/wwwroot/api/llmusage_history_create.dspy b/wwwroot/api/llmusage_history_create.dspy new file mode 100644 index 0000000..3f307aa --- /dev/null +++ b/wwwroot/api/llmusage_history_create.dspy @@ -0,0 +1,4 @@ +#!/usr/bin/env python3 +import json +result = {'success': False, 'message': '历史数据为只读,不可新增'} +return json.dumps(result, ensure_ascii=False, default=str) diff --git a/wwwroot/api/llmusage_history_delete.dspy b/wwwroot/api/llmusage_history_delete.dspy new file mode 100644 index 0000000..c2b4fc5 --- /dev/null +++ b/wwwroot/api/llmusage_history_delete.dspy @@ -0,0 +1,4 @@ +#!/usr/bin/env python3 +import json +result = {'success': False, 'message': '历史数据为只读,不可删除'} +return json.dumps(result, ensure_ascii=False, default=str) diff --git a/wwwroot/api/llmusage_history_update.dspy b/wwwroot/api/llmusage_history_update.dspy new file mode 100644 index 0000000..e4578b0 --- /dev/null +++ b/wwwroot/api/llmusage_history_update.dspy @@ -0,0 +1,4 @@ +#!/usr/bin/env python3 +import json +result = {'success': False, 'message': '历史数据为只读,不可修改'} +return json.dumps(result, ensure_ascii=False, default=str) diff --git a/wwwroot/failed_accounting.ui b/wwwroot/failed_accounting.ui index b4016a8..dabe5d0 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": "DatePicker", "id": "start_date", "options": {"width": "150px"}} + {"widgettype": "TextInput", "id": "start_date", "options": {"width": "150px", "placeholder": "YYYY-MM-DD"}} ] }, { @@ -35,7 +35,7 @@ "options": {"spacing": 4}, "subwidgets": [ {"widgettype": "Text", "options": {"text": "结束日期", "fontSize": "12px"}}, - {"widgettype": "DatePicker", "id": "end_date", "options": {"width": "150px"}} + {"widgettype": "TextInput", "id": "end_date", "options": {"width": "150px", "placeholder": "YYYY-MM-DD"}} ] }, { @@ -66,7 +66,7 @@ "widgettype": "Button", "id": "search_btn", "options": { - "text": "查询", + "label": "查询", "bgcolor": "#1976d2", "color": "#ffffff", "width": "80px" diff --git a/wwwroot/index.ui b/wwwroot/index.ui index 4123f00..a2d8b90 100644 --- a/wwwroot/index.ui +++ b/wwwroot/index.ui @@ -24,7 +24,7 @@ { "widgettype": "VBox", "options": { - "backgroundColor": "#1e3a5f", + "bgcolor": "#1e3a5f", "padding": "24px", "cursor": "pointer", "borderRadius": "8px" @@ -71,7 +71,7 @@ { "widgettype": "VBox", "options": { - "backgroundColor": "#1e3a5f", + "bgcolor": "#1e3a5f", "padding": "24px", "cursor": "pointer", "borderRadius": "8px" @@ -118,7 +118,7 @@ { "widgettype": "VBox", "options": { - "backgroundColor": "#1e3a5f", + "bgcolor": "#1e3a5f", "padding": "24px", "cursor": "pointer", "borderRadius": "8px"