chore(pdd): cat.rule.get 日志增强(摘要 catRuleSummary、加长 bodySnippet、DEBUG 全量)

Made-with: Cursor
This commit is contained in:
huangyujie 2026-03-25 17:09:58 +08:00
parent 412be97158
commit d375b548b0
2 changed files with 91 additions and 0 deletions

View File

@ -573,6 +573,79 @@ public final class PddOpenApiSupport {
} }
} }
/** {@code pdd.goods.cat.rule.get} 成功体在日志中的加长片段上限(字符) */
public static final int CAT_RULE_GET_LOG_BODY_SNIPPET_MAX = 12000;
/**
* {@code pdd.goods.cat.rule.get} 响应压缩为一行摘要便于检索与对照发品逻辑不含完整 JSON
*/
public static String summarizeCatRuleGetForLog(String catRuleBody) {
if (!StringUtils.hasText(catRuleBody)) {
return "(empty)";
}
if (isError(catRuleBody)) {
return "ERROR " + formatError(catRuleBody);
}
try {
JSONObject root = JSON.parseObject(catRuleBody);
if (root == null) {
return "(parse root null)";
}
JSONObject inner = unwrapCatRulePayload(root);
if (inner == null) {
return "(no cat_rule_get_response/goods_cat_rule_get_response)";
}
StringBuilder sb = new StringBuilder(256);
JSONObject gpr = inner.getJSONObject("goods_properties_rule");
if (gpr != null) {
sb.append("input_max_spec_num=").append(gpr.getIntValue("input_max_spec_num"));
JSONArray props = gpr.getJSONArray("properties");
int n = props == null ? 0 : props.size();
sb.append(" goodsPropTotal=").append(n);
int reqSku = 0;
int reqGoods = 0;
if (props != null) {
for (int i = 0; i < props.size(); i++) {
Object el = props.get(i);
if (!(el instanceof JSONObject p)) {
continue;
}
if (!isTruthyRequired(p.get("required"))) {
continue;
}
boolean sku = p.getBooleanValue("is_sku") || p.getBooleanValue("isSku");
if (sku) {
reqSku++;
} else {
reqGoods++;
}
}
}
sb.append(" requiredNonSku=").append(reqGoods).append(" requiredSku=").append(reqSku);
} else {
sb.append("goods_properties_rule=(absent)");
}
List<CatGoodsPropertyRuleRow> reqGoodsRows = listRequiredGoodsLevelPropertyRules(catRuleBody);
if (!reqGoodsRows.isEmpty()) {
sb.append(" requiredGoodsProps=[");
for (int i = 0; i < reqGoodsRows.size(); i++) {
if (i > 0) {
sb.append(';');
}
CatGoodsPropertyRuleRow r = reqGoodsRows.get(i);
sb.append(r.getRefPid()).append(':');
sb.append(r.getName() == null ? "" : r.getName());
}
sb.append(']');
}
Long saleParent = findFirstSaleParentSpecId(catRuleBody);
sb.append(" saleParentSpecId=").append(saleParent != null && saleParent > 0 ? saleParent : "none");
return sb.toString();
} catch (Exception e) {
return "(summarizeFail " + e.getClass().getSimpleName() + ": " + e.getMessage() + ")";
}
}
private static boolean isTruthyRequired(Object v) { private static boolean isTruthyRequired(Object v) {
if (v == null) { if (v == null) {
return false; return false;

View File

@ -133,6 +133,24 @@ public class PddPopClient {
String raw = resp.body(); String raw = resp.body();
boolean httpOk = httpStatus >= 200 && httpStatus < 300; boolean httpOk = httpStatus >= 200 && httpStatus < 300;
boolean popBizError = PddOpenApiSupport.isError(raw); boolean popBizError = PddOpenApiSupport.isError(raw);
if ("pdd.goods.cat.rule.get".equals(type)) {
String catSummary = PddOpenApiSupport.summarizeCatRuleGetForLog(raw);
String bodyLong = PddOpenApiSupport.snippet(raw, PddOpenApiSupport.CAT_RULE_GET_LOG_BODY_SNIPPET_MAX);
if (log.isDebugEnabled()) {
log.debug("PDD_POP api={} host={} clientId={} httpStatus={} durationMs={} catRuleSummary={} fullBody={}",
type, host, clientMasked, httpStatus, durationMs, catSummary, raw);
}
if (!httpOk || popBizError) {
String errSummary = popBizError ? PddOpenApiSupport.formatError(raw) : "";
log.warn("PDD_POP api={} host={} clientId={} httpStatus={} durationMs={} popBizError={} errSummary={} paramPayloadSnippet={} catRuleSummary={} bodySnippet={}",
type, host, clientMasked, httpStatus, durationMs, popBizError, errSummary,
paramLogSnippet != null ? paramLogSnippet : "", catSummary, bodyLong);
} else {
log.info("PDD_POP api={} host={} clientId={} httpStatus={} durationMs={} catRuleSummary={} bodySnippet={}",
type, host, clientMasked, httpStatus, durationMs, catSummary, bodyLong);
}
return raw;
}
String snippet = PddOpenApiSupport.snippet(raw, 600); String snippet = PddOpenApiSupport.snippet(raw, 600);
if (!httpOk || popBizError) { if (!httpOk || popBizError) {
String errSummary = popBizError ? PddOpenApiSupport.formatError(raw) : ""; String errSummary = popBizError ? PddOpenApiSupport.formatError(raw) : "";