49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
|
|
"""PPT 生成场景解析与模板兼容性判断。"""
|
||
|
|
from insurance.ppt.comparison import generation_mode_for_scenario
|
||
|
|
|
||
|
|
|
||
|
|
def get_scenario_config(code: str) -> dict | None:
|
||
|
|
if not code:
|
||
|
|
return None
|
||
|
|
try:
|
||
|
|
from insurance.models.ppt_config import PptScenario
|
||
|
|
|
||
|
|
scenario = PptScenario.query.filter_by(
|
||
|
|
code=code, status=1, deleted_at=None
|
||
|
|
).first()
|
||
|
|
return scenario.to_dict() if scenario else None
|
||
|
|
except Exception:
|
||
|
|
return None
|
||
|
|
|
||
|
|
|
||
|
|
def template_scenario_compatible(template_scenario: str, detected_scenario: str) -> bool:
|
||
|
|
"""模板场景只约束分类,底层计算模式始终由材料组合决定。"""
|
||
|
|
if not template_scenario:
|
||
|
|
return True
|
||
|
|
if template_scenario == detected_scenario:
|
||
|
|
return True
|
||
|
|
config = get_scenario_config(template_scenario)
|
||
|
|
if not config:
|
||
|
|
return False
|
||
|
|
if config.get("generationMode") != generation_mode_for_scenario(detected_scenario):
|
||
|
|
return False
|
||
|
|
base = config.get("baseScenario")
|
||
|
|
return not base or base == detected_scenario
|
||
|
|
|
||
|
|
|
||
|
|
def scenario_codes_for_auto_match(detected_scenario: str) -> list[str]:
|
||
|
|
"""返回可自动匹配的场景代码,精确内置场景优先。"""
|
||
|
|
result = [detected_scenario]
|
||
|
|
try:
|
||
|
|
from insurance.models.ppt_config import PptScenario
|
||
|
|
|
||
|
|
rows = PptScenario.query.filter_by(
|
||
|
|
base_scenario=detected_scenario,
|
||
|
|
status=1,
|
||
|
|
deleted_at=None,
|
||
|
|
).order_by(PptScenario.sort_order.asc()).all()
|
||
|
|
result.extend(row.code for row in rows if row.code not in result)
|
||
|
|
except Exception:
|
||
|
|
pass
|
||
|
|
return result
|