feat(erp-api): 对外上下架全量请求日志开关 external.goods.log-full-request

- ExternalGoodsApiLogProperties + EnableConfigurationProperties
- upsert/delist 入口 INFO 打印完整 JSON(无脱敏)
- application.yml / nacos 模板默认开启,生产可关
- 作者: guochengyu

Made-with: Cursor
This commit is contained in:
huangyujie 2026-03-24 14:29:29 +08:00
parent 6ddf5d7fff
commit 986b0ddeef
5 changed files with 45 additions and 0 deletions

View File

@ -1,7 +1,9 @@
package cn.qihangerp.erp; package cn.qihangerp.erp;
import cn.qihangerp.erp.config.ExternalGoodsApiLogProperties;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
//import org.springframework.cloud.client.discovery.EnableDiscoveryClient; //import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.client.loadbalancer.LoadBalanced;
@ -15,6 +17,7 @@ import org.springframework.web.client.RestTemplate;
@EnableFeignClients(basePackages = "cn.qihangerp.erp") @EnableFeignClients(basePackages = "cn.qihangerp.erp")
@EnableDiscoveryClient @EnableDiscoveryClient
@ComponentScan(basePackages={"cn.qihangerp"}) @ComponentScan(basePackages={"cn.qihangerp"})
@EnableConfigurationProperties(ExternalGoodsApiLogProperties.class)
@SpringBootApplication @SpringBootApplication
public class ErpApi { public class ErpApi {
public static void main( String[] args ) public static void main( String[] args )

View File

@ -0,0 +1,25 @@
package cn.qihangerp.erp.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* 对外商品上下架接口请求日志开关生产上线后请关闭
*
* @author guochengyu
*/
@ConfigurationProperties(prefix = "external.goods")
public class ExternalGoodsApiLogProperties {
/**
* 是否打印 upsert/delist 的完整请求体JSON pddPopAuth 等敏感字段生产务必关闭
*/
private boolean logFullRequest = false;
public boolean isLogFullRequest() {
return logFullRequest;
}
public void setLogFullRequest(boolean logFullRequest) {
this.logFullRequest = logFullRequest;
}
}

View File

@ -6,9 +6,12 @@ import cn.qihangerp.model.request.ExternalGoodsDelistRequest;
import cn.qihangerp.model.request.ExternalGoodsUpsertRequest; import cn.qihangerp.model.request.ExternalGoodsUpsertRequest;
import cn.qihangerp.model.vo.ExternalGoodsUpsertResultVo; import cn.qihangerp.model.vo.ExternalGoodsUpsertResultVo;
import cn.qihangerp.security.common.BaseController; import cn.qihangerp.security.common.BaseController;
import cn.qihangerp.erp.config.ExternalGoodsApiLogProperties;
import cn.qihangerp.service.external.ExternalGoodsAppService; import cn.qihangerp.service.external.ExternalGoodsAppService;
import cn.qihangerp.service.external.pdd.ExternalPddProperties; import cn.qihangerp.service.external.pdd.ExternalPddProperties;
import com.alibaba.fastjson2.JSON;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -27,15 +30,20 @@ import java.util.List;
* *
* @author guochengyu * @author guochengyu
*/ */
@Slf4j
@AllArgsConstructor @AllArgsConstructor
@RestController @RestController
@RequestMapping("/external/goods") @RequestMapping("/external/goods")
public class ExternalGoodsController extends BaseController { public class ExternalGoodsController extends BaseController {
private final ExternalGoodsAppService externalGoodsAppService; private final ExternalGoodsAppService externalGoodsAppService;
private final ExternalPddProperties externalPddProperties; private final ExternalPddProperties externalPddProperties;
private final ExternalGoodsApiLogProperties goodsApiLogProperties;
@PostMapping("/upsert") @PostMapping("/upsert")
public AjaxResult upsert(@RequestBody ExternalGoodsUpsertRequest req) { public AjaxResult upsert(@RequestBody ExternalGoodsUpsertRequest req) {
if (goodsApiLogProperties.isLogFullRequest()) {
log.info("[external/goods/upsert] request={}", req == null ? "null" : JSON.toJSONString(req));
}
if (req == null || req.getShopId() == null || req.getShopId() <= 0) { if (req == null || req.getShopId() == null || req.getShopId() <= 0) {
return AjaxResult.error("参数错误shopId不能为空"); return AjaxResult.error("参数错误shopId不能为空");
} }
@ -92,6 +100,9 @@ public class ExternalGoodsController extends BaseController {
*/ */
@PostMapping("/delist") @PostMapping("/delist")
public AjaxResult delist(@RequestBody ExternalGoodsDelistRequest req) { public AjaxResult delist(@RequestBody ExternalGoodsDelistRequest req) {
if (goodsApiLogProperties.isLogFullRequest()) {
log.info("[external/goods/delist] request={}", req == null ? "null" : JSON.toJSONString(req));
}
if (req == null || req.getShopId() == null || req.getShopId() <= 0) { if (req == null || req.getShopId() == null || req.getShopId() <= 0) {
return AjaxResult.error("参数错误shopId不能为空"); return AjaxResult.error("参数错误shopId不能为空");
} }

View File

@ -31,5 +31,8 @@ external:
api-key: xh-uat-erp-api-ak api-key: xh-uat-erp-api-ak
secret-key: xh-uat-erp-api-sk-9f2d3c4b5a6e7d8c secret-key: xh-uat-erp-api-sk-9f2d3c4b5a6e7d8c
timestamp-skew-ms: 300000 timestamp-skew-ms: 300000
# 上下架接口全量请求体日志;生产上线后改为 false
goods:
log-full-request: true
# 说明:对外商品接口见 temp/yunxi-erp-open-goods-upsert-api.mdNacos 对齐见 temp/erp-open-erp-api-nacos-yunxi-reference.md # 说明:对外商品接口见 temp/yunxi-erp-open-goods-upsert-api.mdNacos 对齐见 temp/erp-open-erp-api-nacos-yunxi-reference.md

View File

@ -35,6 +35,9 @@ external:
api-key: external-uat-ak-001 api-key: external-uat-ak-001
secret-key: external-uat-sk-001-9f2d3c4b5a6e7d8c secret-key: external-uat-sk-001-9f2d3c4b5a6e7d8c
timestamp-skew-ms: 300000 timestamp-skew-ms: 300000
goods:
# 生产上线后改为 false
log-full-request: true
# 拼多多:默认关闭发布;开启时请取消注释并补全 category-map / cost-template-map / sku-overrides # 拼多多:默认关闭发布;开启时请取消注释并补全 category-map / cost-template-map / sku-overrides
#pdd: #pdd: