#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Update approval step""" import json result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid request', 'type': 'error'}} try: record_id = params_kw.get('id', '') workflow_id = params_kw.get('workflow_id', '') step_name = params_kw.get('step_name', '') step_order = params_kw.get('step_order', '1') approver_type = params_kw.get('approver_type', '') approver_value = params_kw.get('approver_value', '') description = params_kw.get('description', '') timeout_hours = params_kw.get('timeout_hours', '') 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_step WHERE id=${id}$", {'id': record_id}) if not existing: result['options'] = {'title': 'Error', 'message': '步骤不存在', 'type': 'error'} else: await sor.sqlExe(""" UPDATE approval_step SET workflow_id=${workflow_id}$, step_name=${step_name}$, step_number=${step_number}$, approver_role=${approver_role}$, approver_id=${approver_id}$, description=${description}$, timeout_hours=${timeout_hours}$ WHERE id=${id}$ """, { 'id': record_id, 'workflow_id': workflow_id, 'step_name': step_name, 'step_number': int(step_order), 'approver_role': approver_type, 'approver_id': approver_value, 'description': description, 'timeout_hours': int(timeout_hours) if timeout_hours else None }) result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '步骤更新成功', 'type': 'success'}} except Exception as e: result['options'] = {'title': 'Error', 'message': f'更新失败: {str(e)}', 'type': 'error'} return json.dumps(result, ensure_ascii=False)