|
|
@@ -451,39 +451,51 @@ class InstitutionService:
|
|
|
@classmethod
|
|
|
async def delete_institution_service(
|
|
|
cls, auth: AuthSchema, data: AlipayEbppInvoiceInstitutionDeleteModel
|
|
|
- ) -> AlipayEbppInvoiceInstitutionDeleteResponse:
|
|
|
+ ) -> dict:
|
|
|
"""
|
|
|
删除费控制度
|
|
|
调用: alipay.ebpp.invoice.institution.delete
|
|
|
+ 支付宝侧已删时忽略错误,始终清理本地关联表
|
|
|
"""
|
|
|
- request = AlipayEbppInvoiceInstitutionDeleteRequest()
|
|
|
- request.biz_model = data
|
|
|
-
|
|
|
- response = await asyncio.to_thread(cls._execute_alipay, request)
|
|
|
-
|
|
|
- if not response:
|
|
|
- raise CustomException(msg="删除费控制度失败: 无响应")
|
|
|
-
|
|
|
- result = AlipayEbppInvoiceInstitutionDeleteResponse()
|
|
|
- result.parse_response_content(response)
|
|
|
-
|
|
|
- if not result.is_success():
|
|
|
- log.error(f"支付宝接口调用失败: {result.code} - {result.msg}")
|
|
|
- raise CustomException(msg=f"删除费控制度失败: {result.msg}")
|
|
|
+ institution_id = getattr(data, 'institution_id', None)
|
|
|
|
|
|
- # 同步删除本地记录
|
|
|
+ # 调用支付宝删除(失败时仅告警,不影响本地清理)
|
|
|
try:
|
|
|
- crud = InstitutionCRUD(auth)
|
|
|
- institution_id = getattr(data, 'institution_id', None)
|
|
|
- if institution_id:
|
|
|
- obj = await crud.get(institution_id=institution_id)
|
|
|
- if obj:
|
|
|
- await crud.delete(ids=[obj.id])
|
|
|
- log.info(f"已删除本地记录: institution_id={institution_id}")
|
|
|
+ request = AlipayEbppInvoiceInstitutionDeleteRequest()
|
|
|
+ request.biz_model = data
|
|
|
+ response = await asyncio.to_thread(cls._execute_alipay, request)
|
|
|
+ if response:
|
|
|
+ result = AlipayEbppInvoiceInstitutionDeleteResponse()
|
|
|
+ result.parse_response_content(response)
|
|
|
+ if result.is_success():
|
|
|
+ log.info(f"支付宝删除成功: institution_id={institution_id}")
|
|
|
+ else:
|
|
|
+ log.warning(f"支付宝删除失败(可能已删): {result.code} - {result.msg}")
|
|
|
+ else:
|
|
|
+ log.warning("支付宝删除无响应,继续清理本地")
|
|
|
except Exception as e:
|
|
|
- log.warning(f"删除本地记录失败(不影响支付宝侧): {e}")
|
|
|
+ log.warning(f"支付宝删除异常(忽略): {e}")
|
|
|
|
|
|
- return result
|
|
|
+ # 清理本地关联表
|
|
|
+ if institution_id:
|
|
|
+ try:
|
|
|
+ from app.plugin.module_payment.expense.rule.model import ExpenseRuleModel
|
|
|
+ from app.plugin.module_payment.expense.quota.model import QuotaModel
|
|
|
+ from app.plugin.module_payment.expense.institution.model import ExpenseInstitutionModel
|
|
|
+ from sqlalchemy import delete as sa_delete
|
|
|
+
|
|
|
+ # 删规则
|
|
|
+ await auth.db.execute(sa_delete(ExpenseRuleModel).where(ExpenseRuleModel.institution_id == institution_id))
|
|
|
+ # 删额度
|
|
|
+ await auth.db.execute(sa_delete(QuotaModel).where(QuotaModel.institution_id == institution_id))
|
|
|
+ # 删制度
|
|
|
+ await auth.db.execute(sa_delete(ExpenseInstitutionModel).where(ExpenseInstitutionModel.institution_id == institution_id))
|
|
|
+ await auth.db.flush()
|
|
|
+ log.info(f"本地关联数据已清理: institution_id={institution_id}")
|
|
|
+ except Exception as e:
|
|
|
+ log.warning(f"本地清理失败: {e}")
|
|
|
+
|
|
|
+ return {"institution_id": institution_id, "deleted": True}
|
|
|
|
|
|
@classmethod
|
|
|
async def modify_institution_service(
|