File size: 1,961 Bytes
b4f2238 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | """Business logic services."""
from __future__ import annotations
from typing import Any
from apps.core.exceptions import NotFoundError, ValidationException
from ..wiring import (
get_contract_folder_binding_service,
get_contract_generation_service,
get_supplementary_agreement_generation_service,
)
class ContractAdminDocumentService:
def generate_contract_document(self, contract_id: int) -> dict[str, Any]:
service = get_contract_generation_service()
content, filename, error = service.generate_contract_document(contract_id)
if error:
if "不存在" in error:
raise NotFoundError(message=error, code="CONTRACT_NOT_FOUND", errors={})
raise ValidationException(message=error, code="CONTRACT_GENERATION_FAILED", errors={})
folder_binding_service = get_contract_folder_binding_service()
binding = folder_binding_service.get_binding(contract_id)
return {
"content": content,
"filename": filename,
"folder_path": binding.folder_path if binding else None,
}
def generate_supplementary_agreement(self, contract_id: int, agreement_id: int) -> dict[str, Any]:
service = get_supplementary_agreement_generation_service()
content, filename, error = service.generate_supplementary_agreement(contract_id, agreement_id)
if error:
if "不存在" in error:
raise NotFoundError(message=error, code="SUPPLEMENTARY_AGREEMENT_NOT_FOUND", errors={})
raise ValidationException(message=error, code="SUPPLEMENTARY_AGREEMENT_GENERATION_FAILED", errors={})
folder_binding_service = get_contract_folder_binding_service()
binding = folder_binding_service.get_binding(contract_id)
return {
"content": content,
"filename": filename,
"folder_path": binding.folder_path if binding else None,
}
|