- cms/: Python包(合并原entcms+dingdingflow) - init.py: 791行,load_cms()注册所有CRUD+审批函数 - dingtalk_client.py: 钉钉API客户端 - models/: 7个表定义JSON(5个CMS+2个DD) - json/: 7个CRUD定义JSON - wwwroot/: 管理后台CRUD页面和API(37个dspy) - init/data.yaml: 模块初始数据(appcodes/appcodes_kv/分类/栏目/配置) - scripts/load_path.py: RBAC权限配置 - pyproject.toml: pip-installable包定义 - 删除: app/, conf/, build.sh, entcms/, dingdingflow/等webapp文件 - 数据库访问统一为DBPools()+_get_dbname()动态模式
73 lines
2.9 KiB
Plaintext
73 lines
2.9 KiB
Plaintext
result = {'success': False, 'rows': [], 'total': 0}
|
|
|
|
try:
|
|
dbname = get_module_dbname('dingdingflow')
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
# Build WHERE clause from data_filter or direct params
|
|
where_clauses = []
|
|
where_ns = {}
|
|
|
|
# Support data_filter from CRUD search popup
|
|
data_filter_str = params_kw.get('data_filter', '')
|
|
if data_filter_str:
|
|
# Individual filter values passed alongside data_filter
|
|
status_filter = params_kw.get('status_filter', '')
|
|
biz_type_filter = params_kw.get('biz_type_filter', '')
|
|
title_filter = params_kw.get('title_filter', '')
|
|
|
|
if status_filter:
|
|
where_clauses.append("status=${status_filter}$")
|
|
where_ns['status_filter'] = status_filter
|
|
if biz_type_filter:
|
|
where_clauses.append("biz_type=${biz_type_filter}$")
|
|
where_ns['biz_type_filter'] = biz_type_filter
|
|
if title_filter:
|
|
where_clauses.append("title LIKE ${title_filter}$")
|
|
where_ns['title_filter'] = f'%{title_filter}%'
|
|
else:
|
|
# Direct param filtering
|
|
status = params_kw.get('status', '')
|
|
if status:
|
|
where_clauses.append("status=${status}$")
|
|
where_ns['status'] = status
|
|
biz_type = params_kw.get('biz_type', '')
|
|
if biz_type:
|
|
where_clauses.append("biz_type=${biz_type}$")
|
|
where_ns['biz_type'] = biz_type
|
|
|
|
where_sql = " AND ".join(where_clauses)
|
|
where_prefix = " WHERE " if where_clauses else ""
|
|
|
|
# Count query
|
|
count_sql = "SELECT count(*) rcnt FROM dd_approvals" + where_prefix + where_sql
|
|
count_rows = await sor.sqlExe(count_sql, where_ns)
|
|
total = 0
|
|
if count_rows and len(count_rows) > 0:
|
|
r = count_rows[0]
|
|
total = getattr(r, 'rcnt', 0)
|
|
|
|
if total > 0:
|
|
ns = {
|
|
'page': int(params_kw.get('page', 1)),
|
|
'rows': int(params_kw.get('rows', 20)),
|
|
'sort': params_kw.get('sort', 'created_at desc')
|
|
}
|
|
sql = "SELECT id, org_id, biz_type, biz_id, title, applicant_id, approver_id, dingtalk_instance_id, status, comment, created_at, completed_at FROM dd_approvals" + where_prefix + where_sql
|
|
query_ns = dict(list(ns.items()) + list(where_ns.items()))
|
|
rows = await sor.sqlExe(sql, query_ns)
|
|
|
|
if isinstance(rows, dict):
|
|
result['rows'] = rows.get('rows', [])
|
|
result['total'] = rows.get('total', total)
|
|
elif rows:
|
|
result['rows'] = [dict(r) if hasattr(r, 'keys') else r for r in rows]
|
|
result['total'] = total
|
|
else:
|
|
result['total'] = 0
|
|
|
|
result['success'] = True
|
|
except Exception as e:
|
|
result['error'] = str(e)
|
|
|
|
return result
|