fix: failed_accounting.ui - Combobox→UiCode, 移除formatter, 修复dspy import
This commit is contained in:
parent
39af416625
commit
647e63eb04
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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"}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user