41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
"""企查查 VO 组装器。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC
|
|
from typing import Any
|
|
|
|
from fastapi_modules.fastapi_leaudit.domian.vo.qichachaVo import QichachaCompanyInfoVO
|
|
from fastapi_modules.fastapi_leaudit.models.qichachaCompanyInfo import QichachaCompanyInfo
|
|
|
|
|
|
class QichachaVoAssembler:
|
|
"""企查查 VO 组装器。"""
|
|
|
|
@classmethod
|
|
def BuildCompanyInfo(cls, record: QichachaCompanyInfo) -> QichachaCompanyInfoVO:
|
|
"""组装企业信息 VO。"""
|
|
dishonesty = record.dishonesty if isinstance(record.dishonesty, dict) else None
|
|
data_list = dishonesty.get("Data") if dishonesty else []
|
|
has_dishonesty = bool(dishonesty and int(dishonesty.get("VerifyResult") or 0) == 1)
|
|
dishonesty_count = len(data_list) if isinstance(data_list, list) else 0
|
|
return QichachaCompanyInfoVO(
|
|
searchKey=record.searchKey,
|
|
creditCode=record.creditCode,
|
|
companyName=record.companyName,
|
|
enterprise=record.enterprise if isinstance(record.enterprise, dict) else None,
|
|
dishonesty=dishonesty,
|
|
hasDishonesty=has_dishonesty,
|
|
dishonestyCount=dishonesty_count,
|
|
updatedAt=cls.FormatDatetime(record.updated_at),
|
|
)
|
|
|
|
@classmethod
|
|
def FormatDatetime(cls, value: Any) -> str | None:
|
|
"""格式化时间。"""
|
|
if value is None:
|
|
return None
|
|
if getattr(value, "tzinfo", None) is None:
|
|
value = value.replace(tzinfo=UTC)
|
|
return value.isoformat()
|