"""Answer business questions from the active local book, without old regional FAQs.""" from decimal import Decimal, ROUND_HALF_UP import re from .quote_fees import document, amount, material_fee, limit_fees def answer_business(intent,book): from .quote_engine import number text=intent['text'];mode=intent.get('mode') if mode=='currency': return '当前海卡、海派运价中的“元/KG”和“元/CBM”按人民币(RMB/CNY)计;一件代发等资料中标注“$”“USD”“美金”的费用按美元计。不同币种分别列明,未提供结算汇率时不自动换算。' if mode=='insurance': raw=document(book,('保险费','投保金额')) percent=amount(raw,r'百分之\s*(\d+(?:\.\d+)?)') minimum=amount(raw,r'min\s*(\d+(?:\.\d+)?)\s*USD') multiplier=amount(raw,r'货值乘以\s*(\d+(?:\.\d+)?)') if percent is None or minimum is None or multiplier is None: return '当前资料未明确保险的完整计费条件,请提供货值和币种,由人工确认保险费。' lines=[f'当前资料保险费率为保额的{percent:g}%,最低{minimum:g}USD;按货值投保时,投保金额为货值×{multiplier:g}。'] money=re.search(r'(-?\d+(?:\.\d+)?)\s*(万)?\s*(美元|美金|USD|人民币|元)',text,re.I) if money and money.group(3).lower() in ('美元','美金','usd'): value=Decimal(money.group(1))*(10000 if money.group(2) else 1) if not 0