workflow_approval/wwwroot/api/workflow_delete.dspy

25 lines
1.2 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Delete approval workflow"""
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid request', 'type': 'error'}}
try:
record_id = params_kw.get('id', '')
if not record_id:
result['options'] = {'title': 'Error', 'message': '记录ID不能为空', 'type': 'error'}
else:
dbname = get_module_dbname('workflow_approval')
async with DBPools().sqlorContext(dbname) as sor:
existing = await sor.sqlExe("SELECT id FROM approval_workflow WHERE id=${id}$", {'id': record_id})
if not existing:
result['options'] = {'title': 'Error', 'message': '工作流不存在', 'type': 'error'}
else:
await sor.sqlExe("DELETE FROM approval_step WHERE workflow_id=${id}$", {'id': record_id})
await sor.sqlExe("DELETE FROM approval_workflow WHERE id=${id}$", {'id': record_id})
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '工作流删除成功', 'type': 'success'}}
except Exception as e:
result['options'] = {'title': 'Error', 'message': f'删除失败: {str(e)}', 'type': 'error'}
return result