Commit f0e573bf by 章家宝

修复获取值bug

1 parent 6b0f58b7
...@@ -34,7 +34,6 @@ public class PerformanceConfigDetailDTO implements Serializable { ...@@ -34,7 +34,6 @@ public class PerformanceConfigDetailDTO implements Serializable {
@ApiModelProperty(name = "performanceConfigRule", notes = "提成方案配置规则") @ApiModelProperty(name = "performanceConfigRule", notes = "提成方案配置规则")
private PerformanceConfigRuleDTO performanceConfigRule; private PerformanceConfigRuleDTO performanceConfigRule;
@ApiModelProperty(name = "merchantBrandRefList", notes = "商户品牌列表") @ApiModelProperty(name = "merchantBrandRefList", notes = "商户品牌列表")
private List<PerformanceConfigMerchantBrandRefDTO> merchantBrandRefList; private List<PerformanceConfigMerchantBrandRefDTO> merchantBrandRefList;
......
...@@ -58,7 +58,7 @@ public interface PerformanceConfigRemote { ...@@ -58,7 +58,7 @@ public interface PerformanceConfigRemote {
@ApiMethod("查询配置详情接口(门店数据调整获取详情)") @ApiMethod("查询配置详情接口(门店数据调整获取详情)")
@ApiParam(name = "dto", notes = "门店id", dataType = DataTypeEnum.INT, required = true) @ApiParam(name = "dto", notes = "门店id", dataType = DataTypeEnum.INT, required = true)
@ApiResponse("提成方案") @ApiResponse("提成方案")
RpcResponse<PerformanceConfigDTO> performanceConfigDetailWithMerchant(PerformanceConfigDTO dto); RpcResponse<PerformanceConfigDetailDTO> performanceConfigDetailWithMerchant(PerformanceConfigDTO dto);
@ApiMethod("通过门店id获取门店所有生效中的方案对应的品牌") @ApiMethod("通过门店id获取门店所有生效中的方案对应的品牌")
@ApiParam(name = "dto", notes = "门店id", dataType = DataTypeEnum.INT, required = true) @ApiParam(name = "dto", notes = "门店id", dataType = DataTypeEnum.INT, required = true)
......
...@@ -66,7 +66,7 @@ public class PerformanceConfigRemoteImpl implements PerformanceConfigRemote { ...@@ -66,7 +66,7 @@ public class PerformanceConfigRemoteImpl implements PerformanceConfigRemote {
} }
@Override @Override
public RpcResponse<PerformanceConfigDTO> performanceConfigDetailWithMerchant(PerformanceConfigDTO dto) { public RpcResponse<PerformanceConfigDetailDTO> performanceConfigDetailWithMerchant(PerformanceConfigDTO dto) {
return RpcResponse.success(performanceConfigService.performanceConfigDetailWithMerchant(dto)); return RpcResponse.success(performanceConfigService.performanceConfigDetailWithMerchant(dto));
} }
......
...@@ -236,7 +236,7 @@ public class PerformanceConfigService { ...@@ -236,7 +236,7 @@ public class PerformanceConfigService {
performanceConfigMapper.updateById(config); performanceConfigMapper.updateById(config);
} }
public PerformanceConfigDTO performanceConfigDetailWithMerchant(PerformanceConfigDTO dto) { public PerformanceConfigDetailDTO performanceConfigDetailWithMerchant(PerformanceConfigDTO dto) {
log.info("selectEffectiveConfig dto: {}", dto); log.info("selectEffectiveConfig dto: {}", dto);
RpcAssert.assertNotNull(dto, DefaultErrorEnum.DATA_NULL, "dto不能为空"); RpcAssert.assertNotNull(dto, DefaultErrorEnum.DATA_NULL, "dto不能为空");
RpcAssert.assertNotNull(dto.getId(), DefaultErrorEnum.DATA_NULL, "id不能为空"); RpcAssert.assertNotNull(dto.getId(), DefaultErrorEnum.DATA_NULL, "id不能为空");
...@@ -244,23 +244,27 @@ public class PerformanceConfigService { ...@@ -244,23 +244,27 @@ public class PerformanceConfigService {
if (performanceConfigDTO == null) { if (performanceConfigDTO == null) {
return null; return null;
} }
performanceConfigDTO.setOriginPerformanceConfigId(performanceConfigDTO.getId()); PerformanceConfigDetailDTO result = new PerformanceConfigDetailDTO();
performanceConfigDTO.setSchemeType(2); result.setOriginPerformanceConfigId(performanceConfigDTO.getId());
performanceConfigDTO.setId(null); result.setSchemeType(2);
result.setId(null);
result.setSchemeName(performanceConfigDTO.getSchemeName());
result.setBusinessType(performanceConfigDTO.getBusinessType());
result.setEffectiveMonth(performanceConfigDTO.getEffectiveMonth());
// 查询rule // 查询rule
PerformanceConfigRuleDTO ruleDTO = performanceConfigRuleService PerformanceConfigRuleDTO ruleDTO = performanceConfigRuleService
.listByConfigId(dto.getId()); .listByConfigId(dto.getId());
performanceConfigDTO.setPerformanceConfigRule(ruleDTO); result.setPerformanceConfigRule(ruleDTO);
// 查询参数配置 // 查询参数配置
List<PerformanceParamConfigDTO> performanceParamConfigs = performanceParamConfigService List<PerformanceParamConfigDTO> performanceParamConfigs = performanceParamConfigService
.listByConfigId(dto.getId()); .listByConfigId(dto.getId());
performanceConfigDTO.setPerformanceParamConfigs(performanceParamConfigs); result.setParamConfigList(performanceParamConfigs);
// 查询商户品牌 // 查询商户品牌
List<PerformanceConfigMerchantBrandRefDTO> merchantBrandRefs = performanceConfigMerchantBrandRefService List<PerformanceConfigMerchantBrandRefDTO> merchantBrandRefs = performanceConfigMerchantBrandRefService
.listByConfigId(dto.getId()); .listByConfigId(dto.getId());
merchantBrandRefs.removeIf(merchantBrandRef -> !merchantBrandRef.getMerchantId().equals(dto.getMerchantId())); merchantBrandRefs.removeIf(merchantBrandRef -> !merchantBrandRef.getMerchantId().equals(dto.getMerchantId()));
performanceConfigDTO.setMerchantBrandModelPageBrands(merchantBrandRefs); result.setMerchantBrandRefList(merchantBrandRefs);
return performanceConfigDTO; return result;
} }
public void enblePerformanceConfig() { public void enblePerformanceConfig() {
......
  • @wangxw1
    commented
    Master

    你好,我是负责此次代码审查的资深软件开发工程师。

    你提交的代码主要涉及 RPC 接口返回类型的变更以及业务逻辑层的数据组装逻辑优化。虽然代码看似修复了某些数据获取的问题,但在分布式架构的兼容性和工程规范方面存在较明显的风险。

    以下是我的审查意见:

    一、关键问题与优化建议(Top 3)

    1. RPC 接口返回类型变更导致的不兼容风险(高危)

    • 问题描述:在 PerformanceConfigRemote 接口中,方法 performanceConfigDetailWithMerchant 的返回泛型从 PerformanceConfigDTO 修改为了 PerformanceConfigDetailDTO。
    • 影响分析:这是一个破坏性变更(Breaking Change)。如果这是一个被其他微服务引用的 RPC 接口(如 Dubbo、Feign),老版本的客户端在反序列化响应时,或者在运行时调用该方法时(找不到对应签名的方法),会直接报错(如 NoSuchMethodError 或序列化异常)。除非你能确保所有客户端与服务端同时停机发布,否则会导致线上故障。
    • 优化建议:
      • 方案 A(推荐):保留原方法,标记为 @Deprecated,新增一个方法(如 getPerformanceConfigDetailV2)返回新的 DTO。
      • 方案 B:如果必须修改原方法,需确认该接口是否仅内部使用且能保证原子发布。 ```java // 建议示例:新增接口,兼容旧版 @Deprecated RpcResponse performanceConfigDetailWithMerchant(PerformanceConfigDTO dto);

    @ApiMethod("查询配置详情接口(新版)") RpcResponse getPerformanceConfigDetail(PerformanceConfigDTO dto);

    
    **2. 硬编码(Magic Number)问题**
    - **问题描述**:在 `PerformanceConfigService.java` 第 249 行存在硬编码 `result.setSchemeType(2);`。
    - **影响分析**:数字 `2` 含义不明,缺乏业务语义,且难以维护。如果未来该类型值发生变化或需要在其他地方引用,极易出错。
    - **优化建议**:使用枚举(Enum)或常量类来定义该值,增加代码可读性。
      ```java
      // 建议示例
      result.setSchemeType(SchemeTypeEnum.STORE_ADJUSTMENT.getCode()); // 假设 2 代表门店调整
    

    3. 冗余的手动属性拷贝与对象创建

    • 问题描述:在 Service 层中,手动将 performanceConfigDTO 的字段逐一赋值给 result 对象(如 setSchemeName, setBusinessType 等)。
    • 影响分析:当字段较多时,手动赋值代码冗长且容易遗漏新增字段。此外,代码中先判断 performanceConfigDTO 非空,后续逻辑较为分散。
    • 优化建议:建议使用 BeanUtils.copyProperties 或 MapStruct 等工具进行对象转换,减少样板代码。 java // 建议示例 PerformanceConfigDetailDTO result = new PerformanceConfigDetailDTO(); BeanUtils.copyProperties(performanceConfigDTO, result); // 单独处理特殊字段 result.setOriginPerformanceConfigId(performanceConfigDTO.getId()); result.setId(null); // ... 设置其他关联数据

    二、评分明细

    1. 功能实现的正确性与健壮性(30/40分)

      • 逻辑上修复了数据组装问题,但 RPC 接口签名的直接修改破坏了服务间的契约,存在极大的运行时风险,扣除 10 分。
    2. 安全性与潜在风险(30/30分)

      • 未发现明显的 SQL 注入、XSS 或越权风险。
    3. 最佳实践与可维护性(12/20分)

      • 存在魔法数字(Magic Number)。
      • 手动进行对象属性拷贝,代码不够简洁。
      • DTO 命名规范尚可。
    4. 性能与资源利用(5/5分)

      • 无明显性能瓶颈,资源利用合理。
    5. 提交信息质量(1/5分)

      • Commit 信息 "修复获取值bug (by jiabao)" 质量极低。未说明修复了什么具体的 Bug、原因是什么、修改逻辑是什么。这对于后续的代码回溯没有任何帮助。

    三、总分

    总分:78分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!