修改配置

This commit is contained in:
huangyujie 2026-03-25 10:55:19 +08:00
parent 47750a72a3
commit 11799310ca
3 changed files with 29 additions and 7 deletions

View File

@ -126,7 +126,7 @@ public class ExternalPddPublishService {
if (props.isAutoFetchCatRule() && !catFetched) { if (props.isAutoFetchCatRule() && !catFetched) {
try { try {
JSONObject body = new JSONObject(); JSONObject body = new JSONObject();
body.put("cat_id", catId); body.put("cat_id", String.valueOf(catId));
String raw = pddPopClient.invoke(gateway, cred.getAppKey(), cred.getAppSecret(), cred.getAccessToken(), String raw = pddPopClient.invoke(gateway, cred.getAppKey(), cred.getAppSecret(), cred.getAccessToken(),
"pdd.goods.cat.rule.get", JSON.toJSONString(body)); "pdd.goods.cat.rule.get", JSON.toJSONString(body));
catRuleSnippet = PddOpenApiSupport.snippet(raw, 2000); catRuleSnippet = PddOpenApiSupport.snippet(raw, 2000);

View File

@ -72,8 +72,12 @@ public class PddCatRuleSpecAutoResolver {
* 调用 pdd.goods.cat.rule.get * 调用 pdd.goods.cat.rule.get
*/ */
public String fetchCatRuleJson(PddShopCredential cred, String gatewayUrl, long catId) throws Exception { public String fetchCatRuleJson(PddShopCredential cred, String gatewayUrl, long catId) throws Exception {
if (catId <= 0) {
throw new IllegalArgumentException("cat_id 必须为正数,当前=" + catId);
}
JSONObject p = new JSONObject(); JSONObject p = new JSONObject();
p.put("cat_id", catId); // POP 文档示例一致param_json cat_id 使用字符串避免网关报cat_id 不能为空
p.put("cat_id", String.valueOf(catId));
return popClient.invoke( return popClient.invoke(
gatewayUrl, gatewayUrl,
cred.getAppKey(), cred.getAppKey(),
@ -102,7 +106,7 @@ public class PddCatRuleSpecAutoResolver {
throw new IllegalStateException("无法解析 SKU 规格名outSkuId=" + row.getOuterErpSkuId()); throw new IllegalStateException("无法解析 SKU 规格名outSkuId=" + row.getOuterErpSkuId());
} }
JSONObject p = new JSONObject(); JSONObject p = new JSONObject();
p.put("cat_id", catId); p.put("cat_id", String.valueOf(catId));
p.put("parent_spec_id", parentSpecId); p.put("parent_spec_id", parentSpecId);
p.put("spec_name", specName.trim()); p.put("spec_name", specName.trim());

View File

@ -14,6 +14,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Canonical 落库结果组装为 pdd.goods.add param_json * Canonical 落库结果组装为 pdd.goods.add param_json
@ -55,7 +56,8 @@ public class PddGoodsAddParamBuilder {
JSONObject root = new JSONObject(); JSONObject root = new JSONObject();
root.put("auto_fill_spu_property", true); root.put("auto_fill_spu_property", true);
root.put("cat_id", catId); // POP 文档示例多为字符串型 cat_id网关对纯数字字段部分场景校验更稳
root.put("cat_id", String.valueOf(catId));
root.put("cost_template_id", costTpl); root.put("cost_template_id", costTpl);
root.put("country_id", props.getDefaultCountryId()); root.put("country_id", props.getDefaultCountryId());
root.put("goods_type", props.getDefaultGoodsType()); root.put("goods_type", props.getDefaultGoodsType());
@ -154,11 +156,27 @@ public class PddGoodsAddParamBuilder {
return props.getDefaultShipmentLimitSecond(); return props.getDefaultShipmentLimitSecond();
} }
/**
* categoryCode 对应映射须为正数若键存在但值为 null/0再尝试 {@code DEFAULT}
*/
private static Long resolveCatId(String categoryCode, ExternalPddProperties props) { private static Long resolveCatId(String categoryCode, ExternalPddProperties props) {
if (StringUtils.hasText(categoryCode) && props.getCategoryMap().containsKey(categoryCode)) { Map<String, Long> m = props.getCategoryMap();
return props.getCategoryMap().get(categoryCode); if (m == null || m.isEmpty()) {
return null;
} }
return props.getCategoryMap().get("DEFAULT"); Long v = pickPositiveCatId(m, categoryCode);
if (v != null) {
return v;
}
return pickPositiveCatId(m, "DEFAULT");
}
private static Long pickPositiveCatId(Map<String, Long> m, String key) {
if (!StringUtils.hasText(key) || !m.containsKey(key)) {
return null;
}
Long v = m.get(key);
return (v != null && v > 0) ? v : null;
} }
private static Long resolveCostTemplate(String logisticsTemplateCode, ExternalPddProperties props) { private static Long resolveCostTemplate(String logisticsTemplateCode, ExternalPddProperties props) {