模板导出增强 + 模特性别分组 + 三合一提示词精简
1) 模板导出:识别「基码表-胸围」填 sku.bust(多个胸围列都填);申报价格模糊匹配多列统一按加价后价格填写;详情图文不再拼接 img_url_2;SPU 款式来源统一填「现货款」;商品产地国家简称映射(沙特→沙特阿拉伯) 2) 模特性别分组:model_features 按男女分组,按模板类目含男/女固定取对应性别模特(含 Pinterest 模式 pipeline) 3) 三合一提示词:去掉 DESIGN CONTENT 四要素描述(设计已由设计稿提供) 4) 生图尺寸:全部改为读 config 不再硬编码(设计图 compose.design_size / 合成图 compose.size / 种草图 seed_shot.size)
This commit is contained in:
@@ -73,19 +73,18 @@ def template_export_node(state: Dict[str, Any]) -> Dict[str, Any]:
|
||||
db_path = root / db_path
|
||||
break
|
||||
|
||||
from graph.template_export import export_product
|
||||
from graph.template_export import export_products
|
||||
tdir = (pcfg.get("template_dir") or "").strip() or str(Path(tp).parent)
|
||||
prod_dir = output_dir / "product"
|
||||
prod_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
exported: List[str] = []
|
||||
# 批量合并导出:所有产品一次性写入同一模板,只打开/保存一次(避免逐产品频繁读写)
|
||||
batch: List[Dict[str, Any]] = []
|
||||
skipped = 0
|
||||
merged_out: Optional[str] = None # 合并模式:一次任务所有产品填同一个模板
|
||||
is_first = True
|
||||
for r in products:
|
||||
# 失败跳过:合成图(composite/printed)与标题都失败的产品不写进模板
|
||||
has_img = bool(r.get("composite_path") or r.get("printed_path"))
|
||||
has_title = bool((r.get("cn_title") or "").strip())
|
||||
has_title = bool((r.get("en_title") or "").strip()) # 商品名称统一用 en_title
|
||||
if not (has_img and has_title):
|
||||
skipped += 1
|
||||
print(f"[template] 跳过失败产品 {r.get('spu_code')}/{r.get('img_code','')}: "
|
||||
@@ -94,31 +93,37 @@ def template_export_node(state: Dict[str, Any]) -> Dict[str, Any]:
|
||||
sku_codes = [cc.get("sku_code") for cc in (r.get("color_composites") or [])]
|
||||
if not sku_codes:
|
||||
sku_codes = [r.get("sku_code") or ""]
|
||||
batch.append({
|
||||
"spu_code": r.get("spu_code", ""),
|
||||
"sku_codes": sku_codes,
|
||||
"images": [],
|
||||
"spu_per_color": True, # 每颜色一个独立 SPU 块(单色多 SPU)
|
||||
"oss_code": r.get("oss_code") or (r.get("color_composites") or [{}])[0].get("code", ""),
|
||||
"cn_title": r.get("cn_title", ""),
|
||||
"en_title": r.get("en_title", ""),
|
||||
"ja_title": r.get("ja_title", ""),
|
||||
"es_title": r.get("es_title", ""),
|
||||
"composite_urls": r.get("color_composites") or [],
|
||||
"seed_shot_urls": r.get("seed_shot_urls") or [],
|
||||
})
|
||||
|
||||
exported: List[str] = []
|
||||
if batch:
|
||||
out = _template_out_path(prod_dir, "商品上传")
|
||||
try:
|
||||
if is_first:
|
||||
merged_out = str(_template_out_path(prod_dir, "商品上传"))
|
||||
out = export_product(
|
||||
db_path, r.get("spu_code", ""), sku_codes, tdir, tp,
|
||||
merged_out,
|
||||
images=[],
|
||||
spu_per_color=True, # 每颜色一个独立 SPU 块(单色多 SPU)
|
||||
oss_code=r.get("oss_code") or (r.get("color_composites") or [{}])[0].get("code", ""),
|
||||
cn_title=r.get("cn_title", ""),
|
||||
en_title=r.get("en_title", ""),
|
||||
ja_title=r.get("ja_title", ""),
|
||||
composite_urls=r.get("color_composites") or [],
|
||||
seed_shot_urls=r.get("seed_shot_urls") or [],
|
||||
append_to="" if is_first else merged_out, # 首个产品从模板创建,后续追加合并
|
||||
out = export_products(
|
||||
db_path, batch, tdir, tp, str(out),
|
||||
markup_percent=float(pcfg.get("markup_percent") or 0),
|
||||
)
|
||||
r["template_path"] = str(out)
|
||||
for r in products:
|
||||
if (r.get("composite_path") or r.get("printed_path")) and (r.get("en_title") or "").strip():
|
||||
r["template_path"] = str(out)
|
||||
exported.append(str(out))
|
||||
print(f"[template] 商品上传模板已生成({len(exported)}/{len(products)} 合并): {out}")
|
||||
print(f"[template] 商品上传模板已生成({len(batch)} 个产品一次合并): {out}")
|
||||
except Exception as e: # noqa: BLE001
|
||||
errors.append({"node": "template_export", "type": type(e).__name__,
|
||||
"message": f"模板导出失败 {r.get('spu_code')}: {e}", "trace": ""})
|
||||
print(f"[template] 模板导出失败 {r.get('spu_code')}: {e}")
|
||||
is_first = False
|
||||
"message": f"模板批量导出失败: {e}", "trace": ""})
|
||||
print(f"[template] 模板批量导出失败: {e}")
|
||||
|
||||
stats["template_export"] = {"exported": len(exported)}
|
||||
return {"product": products, "errors": errors, "stats": stats}
|
||||
|
||||
Reference in New Issue
Block a user