contract_management/wwwroot/api/contracts_delete.dspy
yumoqing a72637b2a3 sync: local modifications to contract_management
- Updated core modules: __init__, ai_config, ai_core, attachment, contract, enhanced_contract
- Updated mysql.ddl.sql
- Updated UI files: contract_detail, contract_edit, contract_list
- Added new files: api/*.dspy, contract_list.dspy
2026-04-28 18:49:46 +08:00

26 lines
1.1 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Contract delete API"""
import json
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid request', 'type': 'error'}}
try:
record_id = params_kw.get('id', '').strip()
if not record_id:
result['options'] = {'title': 'Error', 'message': '记录ID不能为空', 'type': 'error'}
else:
dbname = get_module_dbname('contract_management')
async with DBPools().sqlorContext(dbname) as sor:
existing = await sor.sqlExe("SELECT id FROM contract WHERE id = ${id}$", {'id': record_id})
if not existing:
result['options'] = {'title': 'Error', 'message': '合同不存在', 'type': 'error'}
else:
await sor.sqlExe("DELETE FROM contract 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 json.dumps(result, ensure_ascii=False)