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:
parent
6ddf5d7fff
commit
986b0ddeef
|
|
@ -1,7 +1,9 @@
|
|||
package cn.qihangerp.erp;
|
||||
|
||||
import cn.qihangerp.erp.config.ExternalGoodsApiLogProperties;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
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.loadbalancer.LoadBalanced;
|
||||
|
|
@ -15,6 +17,7 @@ import org.springframework.web.client.RestTemplate;
|
|||
@EnableFeignClients(basePackages = "cn.qihangerp.erp")
|
||||
@EnableDiscoveryClient
|
||||
@ComponentScan(basePackages={"cn.qihangerp"})
|
||||
@EnableConfigurationProperties(ExternalGoodsApiLogProperties.class)
|
||||
@SpringBootApplication
|
||||
public class ErpApi {
|
||||
public static void main( String[] args )
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,9 +6,12 @@ import cn.qihangerp.model.request.ExternalGoodsDelistRequest;
|
|||
import cn.qihangerp.model.request.ExternalGoodsUpsertRequest;
|
||||
import cn.qihangerp.model.vo.ExternalGoodsUpsertResultVo;
|
||||
import cn.qihangerp.security.common.BaseController;
|
||||
import cn.qihangerp.erp.config.ExternalGoodsApiLogProperties;
|
||||
import cn.qihangerp.service.external.ExternalGoodsAppService;
|
||||
import cn.qihangerp.service.external.pdd.ExternalPddProperties;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
|
@ -27,15 +30,20 @@ import java.util.List;
|
|||
*
|
||||
* @author guochengyu
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/external/goods")
|
||||
public class ExternalGoodsController extends BaseController {
|
||||
private final ExternalGoodsAppService externalGoodsAppService;
|
||||
private final ExternalPddProperties externalPddProperties;
|
||||
private final ExternalGoodsApiLogProperties goodsApiLogProperties;
|
||||
|
||||
@PostMapping("/upsert")
|
||||
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) {
|
||||
return AjaxResult.error("参数错误:shopId不能为空");
|
||||
}
|
||||
|
|
@ -92,6 +100,9 @@ public class ExternalGoodsController extends BaseController {
|
|||
*/
|
||||
@PostMapping("/delist")
|
||||
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) {
|
||||
return AjaxResult.error("参数错误:shopId不能为空");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,5 +31,8 @@ external:
|
|||
api-key: xh-uat-erp-api-ak
|
||||
secret-key: xh-uat-erp-api-sk-9f2d3c4b5a6e7d8c
|
||||
timestamp-skew-ms: 300000
|
||||
# 上下架接口全量请求体日志;生产上线后改为 false
|
||||
goods:
|
||||
log-full-request: true
|
||||
|
||||
# 说明:对外商品接口见 temp/yunxi-erp-open-goods-upsert-api.md;Nacos 对齐见 temp/erp-open-erp-api-nacos-yunxi-reference.md
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ external:
|
|||
api-key: external-uat-ak-001
|
||||
secret-key: external-uat-sk-001-9f2d3c4b5a6e7d8c
|
||||
timestamp-skew-ms: 300000
|
||||
goods:
|
||||
# 生产上线后改为 false
|
||||
log-full-request: true
|
||||
|
||||
# 拼多多:默认关闭发布;开启时请取消注释并补全 category-map / cost-template-map / sku-overrides
|
||||
#pdd:
|
||||
|
|
|
|||
Loading…
Reference in New Issue