30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
"""客户 C 级与产品 R 级的公共适当性校验。"""
|
|||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from dataclasses import dataclass
|
||
|
|
import re
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass(frozen=True)
|
||
|
|
class SuitabilityResult:
|
||
|
|
ok: bool
|
||
|
|
reason: str
|
||
|
|
|
||
|
|
|
||
|
|
_RISK_PATTERN = re.compile(r"^[CR]([1-5])$")
|
||
|
|
|
||
|
|
|
||
|
|
def check_suitability(customer_risk: str, product_risk: str) -> SuitabilityResult:
|
||
|
|
customer_match = _RISK_PATTERN.fullmatch(customer_risk or "")
|
||
|
|
product_match = _RISK_PATTERN.fullmatch(product_risk or "")
|
||
|
|
if not customer_match or not product_match:
|
||
|
|
return SuitabilityResult(False, "客户或产品风险等级无效")
|
||
|
|
if customer_risk[0] != "C" or product_risk[0] != "R":
|
||
|
|
return SuitabilityResult(False, "客户或产品风险等级类型无效")
|
||
|
|
|
||
|
|
customer_level = int(customer_match.group(1))
|
||
|
|
product_level = int(product_match.group(1))
|
||
|
|
if product_level > customer_level:
|
||
|
|
return SuitabilityResult(False, "产品风险等级高于客户风险等级")
|
||
|
|
return SuitabilityResult(True, "适当性校验通过")
|