feat(erp-api): 开启 external.pdd.publish-enabled 并补全默认映射模板;upsert 增加 PDD 配置与结果摘要日志

Made-with: Cursor
This commit is contained in:
huangyujie 2026-03-24 19:43:51 +08:00
parent d1cf874ab8
commit 931eb62022
3 changed files with 60 additions and 9 deletions

View File

@ -80,6 +80,15 @@ public class ExternalGoodsController extends BaseController {
return AjaxResult.error("platform不合法");
}
if (EnumShopType.PDD.equals(platform)) {
log.info("[external/goods/upsert] pdd.publish-enabled={} gatewayHost={} categoryMapKeys={}",
externalPddProperties.isPublishEnabled(),
safeHostForLog(externalPddProperties.getGatewayUrl()),
externalPddProperties.getCategoryMap() != null
? externalPddProperties.getCategoryMap().keySet().toString()
: "null");
}
if (EnumShopType.PDD.equals(platform) && externalPddProperties.isPublishEnabled()) {
if (req.getPddPopAuth() == null) {
return AjaxResult.error("参数错误:开启拼多多发布时 pddPopAuth 不能为空");
@ -95,8 +104,10 @@ public class ExternalGoodsController extends BaseController {
log.info("[external/goods/upsert] response shopId={} outGoodsId={} erpGoodsId={} platform={}",
req.getShopId(), req.getOutGoodsId(), vo.getGoodsId(), req.getPlatform());
if (EnumShopType.PDD.equals(platform)) {
log.info("[external/goods/upsert] pddPublish attempted={} success={}",
vo.getPddPublishAttempted(), vo.getPddPublishSuccess());
log.info("[external/goods/upsert] pddPublish attempted={} success={} message={}",
vo.getPddPublishAttempted(),
vo.getPddPublishSuccess(),
truncateLog(vo.getPddPublishMessage(), 800));
}
return AjaxResult.success(vo);
}
@ -123,6 +134,26 @@ public class ExternalGoodsController extends BaseController {
}
}
private static String safeHostForLog(String gatewayUrl) {
if (!StringUtils.hasText(gatewayUrl)) {
return "";
}
try {
java.net.URI u = java.net.URI.create(gatewayUrl.trim());
String h = u.getHost();
return h != null ? h : gatewayUrl.trim();
} catch (Exception e) {
return gatewayUrl.trim();
}
}
private static String truncateLog(String s, int max) {
if (s == null) {
return "";
}
return s.length() <= max ? s : s.substring(0, max) + "...";
}
private static boolean hasMainVisual(ExternalGoodsUpsertRequest req) {
if (StringUtils.hasText(req.getMainImage())) {
return true;

View File

@ -35,4 +35,20 @@ external:
goods:
log-full-request: true
# 拼多多 POPupsert 落库后是否调用 pdd.goods.add须与 maindata yundt.maindata.erp-open.default-category-code 等对齐)
pdd:
publish-enabled: true
gateway-url: https://gw-api.pinduoduo.com/api/router
# 发布前可选拉类目规则(诊断用)
auto-fetch-cat-rule: false
# sku-overrides 为空时按类目规则 + spec.id 自动拼规格(与 SKU 条数一致时才继续调 goods.add
auto-resolve-spec-ids-when-sku-overrides-empty: true
# categoryCode请求体-> 拼多多叶子类目 cat_idDEFAULT 与 maindata 默认 categoryCode 一致0 表示未配置须改为真实 ID
category-map:
DEFAULT: 0
# logisticsTemplateCode -> cost_template_id0 表示未配置须改为店铺运费模板 ID
cost-template-map:
DEFAULT: 0
sku-overrides: []
# 说明:对外商品接口见 temp/yunxi-erp-open-goods-upsert-api.mdNacos 对齐见 temp/erp-open-erp-api-nacos-yunxi-reference.md

View File

@ -39,10 +39,14 @@ external:
# 生产上线后改为 false
log-full-request: true
# 拼多多:默认关闭发布;开启时请取消注释并补全 category-map / cost-template-map / sku-overrides
#pdd:
# publish-enabled: false
# gateway-url: https://gw-api.pinduoduo.com/api/router
# category-map: {}
# cost-template-map: {}
# sku-overrides: []
# 拼多多 POP与 jar 内 application.yml 对齐Nacos 下发会覆盖本地
pdd:
publish-enabled: true
gateway-url: https://gw-api.pinduoduo.com/api/router
auto-fetch-cat-rule: false
auto-resolve-spec-ids-when-sku-overrides-empty: true
category-map:
DEFAULT: 0
cost-template-map:
DEFAULT: 0
sku-overrides: []