Commit b601a245 by 章家宝

联调,帮前端规整数据

1 parent 1858711f
package cn.com.glsx.dj.staff.dto.performance;
import lombok.Data;
import java.io.Serializable;
/**
*
*
* @time 2026-01-29 22:12
*/
@Data
public class MerchantBrandListByMerchantIdFromValidPerformanceConfigDTO implements Serializable {
private Byte businessType;
private Integer id;
private String childBrandNames;
}
......@@ -63,5 +63,5 @@ public interface PerformanceConfigRemote {
@ApiMethod("通过门店id获取门店所有生效中的方案对应的品牌")
@ApiParam(name = "dto", notes = "门店id", dataType = DataTypeEnum.INT, required = true)
@ApiResponse("提成方案")
RpcResponse<List<PerformanceConfigMerchantBrandRefDTO>> getMerchantBrandListByMerchantIdFromValidPerformanceConfig(PerformanceConfigMerchantBrandRefDTO dto);
RpcResponse<List<MerchantBrandListByMerchantIdFromValidPerformanceConfigDTO>> getMerchantBrandListByMerchantIdFromValidPerformanceConfig(PerformanceConfigMerchantBrandRefDTO dto);
}
......@@ -71,7 +71,7 @@ public class PerformanceConfigRemoteImpl implements PerformanceConfigRemote {
}
@Override
public RpcResponse<List<PerformanceConfigMerchantBrandRefDTO>> getMerchantBrandListByMerchantIdFromValidPerformanceConfig(PerformanceConfigMerchantBrandRefDTO dto) {
public RpcResponse<List<MerchantBrandListByMerchantIdFromValidPerformanceConfigDTO>> getMerchantBrandListByMerchantIdFromValidPerformanceConfig(PerformanceConfigMerchantBrandRefDTO dto) {
return RpcResponse.success(performanceConfigService.getMerchantBrandListByMerchantIdFromValidPerformanceConfig(dto));
}
......
......@@ -265,7 +265,23 @@ public class PerformanceConfigService {
performanceConfigMapper.enblePerformanceConfig();
}
public List<PerformanceConfigMerchantBrandRefDTO> getMerchantBrandListByMerchantIdFromValidPerformanceConfig(PerformanceConfigMerchantBrandRefDTO dto) {
return performanceConfigMerchantBrandRefService.getMerchantBrandListByMerchantIdFromValidPerformanceConfig(dto);
public List<MerchantBrandListByMerchantIdFromValidPerformanceConfigDTO> getMerchantBrandListByMerchantIdFromValidPerformanceConfig(PerformanceConfigMerchantBrandRefDTO dto) {
List<PerformanceConfigMerchantBrandRefDTO> merchantBrandListByMerchantIdFromValidPerformanceConfig = performanceConfigMerchantBrandRefService.getMerchantBrandListByMerchantIdFromValidPerformanceConfig(dto);
if (merchantBrandListByMerchantIdFromValidPerformanceConfig == null || merchantBrandListByMerchantIdFromValidPerformanceConfig.isEmpty()) {
return null;
}
List<MerchantBrandListByMerchantIdFromValidPerformanceConfigDTO> result = new ArrayList<>();
Map<Integer, List<PerformanceConfigMerchantBrandRefDTO>> collect = merchantBrandListByMerchantIdFromValidPerformanceConfig.stream().collect(Collectors.groupingBy(PerformanceConfigMerchantBrandRefDTO::getPerformanceConfigId));
for (List<PerformanceConfigMerchantBrandRefDTO> value : collect.values()) {
MerchantBrandListByMerchantIdFromValidPerformanceConfigDTO d = new MerchantBrandListByMerchantIdFromValidPerformanceConfigDTO();
d.setBusinessType(value.get(0).getBusinessType());
d.setId(value.get(0).getPerformanceConfigId());
Set<String> childBrandNames = new HashSet<>();
for (PerformanceConfigMerchantBrandRefDTO v : value) {
childBrandNames.add(v.getChildName());
}
d.setChildBrandNames(String.join("/", childBrandNames));
}
return result;
}
}
  • @wangxw1
    commented
    Master

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

    你提交的代码主要是为了配合前端展示需求,对原有的 RPC 接口返回数据进行了聚合处理。经过详细审查,我发现代码中存在严重的逻辑漏洞,会导致接口返回空数据,同时存在命名与工程规范上的问题。

    以下是具体的审查报告:

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

    1. 严重逻辑错误:转换后的对象未添加到返回列表

    • 问题描述:在 PerformanceConfigService.java 的 getMerchantBrandListByMerchantIdFromValidPerformanceConfig 方法中,你创建了 result 列表,并在循环中构建了 MerchantBrandListByMerchantIdFromValidPerformanceConfigDTO 对象 d,但忘记将 d 添加到 result 列表中。
    • 影响分析:这是致命的逻辑错误。无论数据库中是否有数据,该接口最终只会返回一个空的 List(或者 null),前端将无法获取任何数据。
    • 优化建议:在循环结束前执行 result.add(d);。
    // 修复示例
    for (List<PerformanceConfigMerchantBrandRefDTO> value : collect.values()) {
        MerchantBrandListByMerchantIdFromValidPerformanceConfigDTO d = new MerchantBrandListByMerchantIdFromValidPerformanceConfigDTO();
        // ... 属性赋值 ...
        d.setChildBrandNames(String.join("/", childBrandNames));
    
        // 【必须添加这一行】
        result.add(d); 
    }
    

    2. 异常处理规范:不应返回 null 集合

    • 问题描述:在 Service 层中,当查询结果为空时,你直接返回了 null。
    • 影响分析:RPC 接口返回 null 集合是极差的实践。这迫使调用方(Controller 或 Frontend)必须进行额外的判空处理,否则极易引发 NullPointerException。且该逻辑与下方的 return result(返回空列表)行为不一致。
    • 优化建议:始终返回空列表。
    // 优化示例
    if (merchantBrandListByMerchantIdFromValidPerformanceConfig == null || merchantBrandListByMerchantIdFromValidPerformanceConfig.isEmpty()) {
        return Collections.emptyList(); // 或 return new ArrayList<>();
    }
    

    3. 命名规范:类名过长且冗余

    • 问题描述:新增的 DTO 类名 MerchantBrandListByMerchantIdFromValidPerformanceConfigDTO 长达 58 个字符。
    • 影响分析:极度影响代码可读性,增加 IDE 自动补全的干扰,且在日志打印时占用过多空间。类名应体现其“是什么”(数据模型),而不是“怎么来的”(业务逻辑)。
    • 优化建议:根据业务含义简化命名。该对象似乎代表“生效提成方案下的品牌聚合信息”。
      • 建议重命名为:PerformanceBrandSummaryDTO 或 ValidConfigBrandDTO。

    二、评分明细

    1. 功能实现的正确性与健壮性(10/40分)
      • 扣分项:存在严重的逻辑 Bug(未将对象加入列表),导致功能完全不可用;错误地返回 null 而非空列表。
    2. 安全性与潜在风险(30/30分)
      • 得分项:使用 DTO 传输数据,未见明显的 SQL 注入或敏感信息泄露风险。
    3. 最佳实践与可维护性(10/20分)
      • 扣分项:类名命名严重违反简洁性原则;代码中包含奇怪的时间注释(2026年)。
    4. 性能与资源利用(4/5分)
      • 得分项:使用 Stream 进行分组处理,性能尚可。
    5. 提交信息质量(3/5分)
      • 扣分项:提交信息较为随意,虽说明了目的(联调),但未描述具体变更逻辑。

    三、总分

    总分:57分

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