entity/wwwroot/api/entity_import_list.dspy

36 lines
1.6 KiB
Plaintext

# -*- coding: utf-8 -*-
# entity_import_list.dspy —— 导入记录只读分页列表
# entity_import 表为系统生成,禁止手工增删改;此处仅提供只读查询
try:
params_kw = params_kw or {}
page = int(params_kw.get('page', 1) or 1)
rows = int(params_kw.get('rows', params_kw.get('pagerows', 20)) or 20)
if page < 1:
page = 1
if rows < 1 or rows > 200:
rows = 20
status = str(params_kw.get('status') or '').strip()
org_id = (await get_userorgid()) or '0'
where = ['1=1']
ns = {}
if org_id and org_id != '0':
where.append("org_id IN ('0', ${org_id}$)")
ns['org_id'] = org_id
if status:
where.append('status = ${status}$')
ns['status'] = status
cond = ' AND '.join(where)
async with get_sor_context(request._run_ns, 'entity') as sor:
cnt = await sor.sqlExe('SELECT COUNT(*) AS cnt FROM entity_import WHERE ' + cond, ns)
total = int(cnt[0].cnt) if cnt else 0
offset = (page - 1) * rows
ns['limit'] = int(rows)
ns['offset'] = int(offset)
recs = await sor.sqlExe(
'SELECT id, import_no, file_name, total_count, success_count, fail_count, status, error_msg, created_at '
'FROM entity_import WHERE ' + cond + ' ORDER BY created_at DESC LIMIT ${limit}$ OFFSET ${offset}$', ns)
lst = [dict(r) for r in (recs or [])]
return {'list': lst, 'total': total, 'page': page, 'rows': rows}
except Exception as e:
return {'code': 'IMPORT_LIST_ERROR', 'message': '导入记录查询失败', 'field': '', 'detail': str(e)}