|
@@ -4,7 +4,7 @@ import re
|
|
|
import urllib.parse
|
|
import urllib.parse
|
|
|
from typing import Any
|
|
from typing import Any
|
|
|
|
|
|
|
|
-from alien_contract.infrastructure.esign.main import SIGN_POSITIONS, apply_platform_seal, fill_in_template, create_by_file
|
|
|
|
|
|
|
+from alien_contract.infrastructure.esign.main import fill_in_template, create_by_file
|
|
|
from alien_contract.infrastructure.esign.esign_config import Config
|
|
from alien_contract.infrastructure.esign.esign_config import Config
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
logger = logging.getLogger(__name__)
|
|
@@ -18,34 +18,6 @@ class ContractBuildError(Exception):
|
|
|
self.raw = raw
|
|
self.raw = raw
|
|
|
|
|
|
|
|
|
|
|
|
|
-def _is_esign_success(resp: dict[str, Any]) -> bool:
|
|
|
|
|
- code = resp.get("code")
|
|
|
|
|
- return code in (0, "0") or resp.get("success") is True
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-def _apply_platform_seal_if_required(contract_type: str, contract_name: str, sign_flow_id: str) -> None:
|
|
|
|
|
- positions = SIGN_POSITIONS.get(contract_type, {})
|
|
|
|
|
- if not positions.get("alien"):
|
|
|
|
|
- return
|
|
|
|
|
-
|
|
|
|
|
- seal_resp = apply_platform_seal(sign_flow_id)
|
|
|
|
|
- try:
|
|
|
|
|
- seal_json = json.loads(seal_resp)
|
|
|
|
|
- except json.JSONDecodeError:
|
|
|
|
|
- logger.error("apply_platform_seal non-json resp contract_type=%s: %s", contract_type, seal_resp)
|
|
|
|
|
- raise ContractBuildError(
|
|
|
|
|
- message=f"{contract_name}平台自动盖章失败:e签宝返回非 JSON",
|
|
|
|
|
- raw={"contract_type": contract_type, "sign_flow_id": sign_flow_id, "resp": seal_resp},
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- if not isinstance(seal_json, dict) or not _is_esign_success(seal_json):
|
|
|
|
|
- logger.error("apply_platform_seal failed contract_type=%s: %s", contract_type, seal_json)
|
|
|
|
|
- raise ContractBuildError(
|
|
|
|
|
- message=f"{contract_name}平台自动盖章失败",
|
|
|
|
|
- raw={"contract_type": contract_type, "sign_flow_id": sign_flow_id, "resp": seal_json},
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
def build_contract_items(
|
|
def build_contract_items(
|
|
|
configs: list[tuple[str, str, int]],
|
|
configs: list[tuple[str, str, int]],
|
|
|
template_name: str,
|
|
template_name: str,
|
|
@@ -137,8 +109,6 @@ def build_contract_items(
|
|
|
raw={"contract_type": contract_type, "resp": sign_json},
|
|
raw={"contract_type": contract_type, "resp": sign_json},
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- _apply_platform_seal_if_required(contract_type, contract_name, sign_id)
|
|
|
|
|
-
|
|
|
|
|
items.append(
|
|
items.append(
|
|
|
{
|
|
{
|
|
|
"contract_type": contract_type,
|
|
"contract_type": contract_type,
|