91 lines
3.1 KiB
Python
91 lines
3.1 KiB
Python
|
|
"""迁移 024: 注册三套场景 PPTX 模板资产。"""
|
|||
|
|
import json
|
|||
|
|
import logging
|
|||
|
|
|
|||
|
|
from sqlalchemy import text
|
|||
|
|
|
|||
|
|
logger = logging.getLogger(__name__)
|
|||
|
|
|
|||
|
|
|
|||
|
|
TEMPLATES = [
|
|||
|
|
{
|
|||
|
|
"id": "scenario_single_savings",
|
|||
|
|
"name": "单份储蓄计划|专业版",
|
|||
|
|
"scenario_tag": "single_savings",
|
|||
|
|
"plan_type": "savings",
|
|||
|
|
"style_preset": "broker",
|
|||
|
|
"asset_id": "builtin://single_savings.pptx",
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"id": "scenario_multi_savings",
|
|||
|
|
"name": "双储蓄险|专业对比",
|
|||
|
|
"scenario_tag": "multi_savings_comparison",
|
|||
|
|
"plan_type": "savings",
|
|||
|
|
"style_preset": "broker",
|
|||
|
|
"asset_id": "builtin://multi_savings_comparison.pptx",
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"id": "scenario_savings_iul",
|
|||
|
|
"name": "储蓄险 + IUL|综合方案",
|
|||
|
|
"scenario_tag": "savings_iul_comprehensive",
|
|||
|
|
"plan_type": "savings",
|
|||
|
|
"style_preset": "broker",
|
|||
|
|
"asset_id": "builtin://savings_iul_comprehensive.pptx",
|
|||
|
|
},
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
|
|||
|
|
def migrate():
|
|||
|
|
"""解析内置 PPTX,并将模板元数据幂等写入模板表。"""
|
|||
|
|
from insurance.db.compat import db
|
|||
|
|
from insurance.ppt.template_asset_service import (
|
|||
|
|
parse_template_pptx,
|
|||
|
|
resolve_template_asset,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
for seed in TEMPLATES:
|
|||
|
|
file_path = resolve_template_asset(seed["asset_id"])
|
|||
|
|
parsed = parse_template_pptx(file_path)
|
|||
|
|
existing = db.session.execute(
|
|||
|
|
text("SELECT id FROM insurance_ppt_templates WHERE id = :id"),
|
|||
|
|
{"id": seed["id"]},
|
|||
|
|
).first()
|
|||
|
|
values = {
|
|||
|
|
**seed,
|
|||
|
|
"clone_renderer": "python-pptx-theme-v1",
|
|||
|
|
"required_page_types_json": json.dumps(
|
|||
|
|
parsed["requiredPageTypes"], ensure_ascii=False
|
|||
|
|
),
|
|||
|
|
"slides_config_json": json.dumps(
|
|||
|
|
parsed["slidesConfig"], ensure_ascii=False
|
|||
|
|
),
|
|||
|
|
}
|
|||
|
|
if existing:
|
|||
|
|
db.session.execute(text(
|
|||
|
|
"UPDATE insurance_ppt_templates SET "
|
|||
|
|
"name = :name, scenario_tag = :scenario_tag, "
|
|||
|
|
"source_template_asset_id = :asset_id, clone_ready = true, "
|
|||
|
|
"clone_renderer = :clone_renderer, "
|
|||
|
|
"required_page_types_json = :required_page_types_json, "
|
|||
|
|
"slides_config_json = :slides_config_json "
|
|||
|
|
"WHERE id = :id"
|
|||
|
|
), values)
|
|||
|
|
else:
|
|||
|
|
db.session.execute(text(
|
|||
|
|
"INSERT INTO insurance_ppt_templates "
|
|||
|
|
"(id, name, scenario_tag, plan_type, style_preset, "
|
|||
|
|
"source_template_asset_id, clone_ready, clone_renderer, "
|
|||
|
|
"required_page_types_json, slides_config_json, status) "
|
|||
|
|
"VALUES (:id, :name, :scenario_tag, :plan_type, :style_preset, "
|
|||
|
|
":asset_id, true, :clone_renderer, :required_page_types_json, "
|
|||
|
|
":slides_config_json, 1)"
|
|||
|
|
), values)
|
|||
|
|
|
|||
|
|
logger.info(
|
|||
|
|
"[migrate_024] 已注册模板 %s(%s 页)",
|
|||
|
|
seed["id"],
|
|||
|
|
parsed["slideCount"],
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
db.session.commit()
|