Commit 73d9b092 by 章家宝

门店id判空

1 parent ae7eba94
...@@ -6,6 +6,8 @@ import cn.com.glsx.dj.staff.dto.performance.*; ...@@ -6,6 +6,8 @@ import cn.com.glsx.dj.staff.dto.performance.*;
import cn.com.glsx.dj.staff.service.staffPerformance.PerformanceConfigService; import cn.com.glsx.dj.staff.service.staffPerformance.PerformanceConfigService;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination; import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse; import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.util.RpcAssert;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -59,6 +61,7 @@ public class PerformanceConfigRemoteImpl implements PerformanceConfigRemote { ...@@ -59,6 +61,7 @@ public class PerformanceConfigRemoteImpl implements PerformanceConfigRemote {
@Override @Override
public RpcResponse<Boolean> hasEffectivePerformanceConfigForMerchant(Integer merchantId) { public RpcResponse<Boolean> hasEffectivePerformanceConfigForMerchant(Integer merchantId) {
RpcAssert.assertNotNull(merchantId, DefaultErrorEnum.PARAMETER_NULL,"门店id不能为空");
return RpcResponse.success(performanceConfigService.hasEffectivePerformanceConfigForMerchant(merchantId)); return RpcResponse.success(performanceConfigService.hasEffectivePerformanceConfigForMerchant(merchantId));
} }
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议

    • 问题 1:异常处理的一致性风险(正确性与健壮性)

      • 问题描述:代码中使用了 RpcAssert.assertNotNull 进行参数校验。在 Dubbo 远程调用中,该断言通常会抛出自定义的 RuntimeException。
      • 影响分析:如果当前 Provider 端没有配置统一的全局异常拦截器(如 Dubbo Filter 或 AOP 拦截)来捕获并封装这些异常为 RpcResponse 对象,异常将直接穿透到 Consumer 端。这会导致消费者端接收到 RPC 框架层面的异常(如 RpcException),而非结构化的 RpcResponse 错误信息,破坏了接口契约的一致性。
      • 优化建议:确认项目中是否已配置全局异常处理机制,能将 RpcAssert 抛出的异常自动转换为 RpcResponse.fail()。若无此机制,建议改为显式判断: java if (merchantId == null) { return RpcResponse.fail(DefaultErrorEnum.PARAMETER_NULL.getCode(), "门店id不能为空"); }
    • 问题 2:入参校验逻辑的严谨性(正确性与健壮性)

      • 问题描述:当前仅使用 assertNotNull 校验了 merchantId 是否为 null。
      • 影响分析:对于数据库主键 ID 类型,通常业务逻辑上不应接受小于等于 0 的非法值。若调用方传入 0 或 -1,当前校验会通过,但后续查询 performanceConfigService 可能会产生无效的数据库扫描或业务逻辑错误。
      • 优化建议:建议使用更严谨的校验方式,确保 ID 大于 0。 java RpcAssert.assertTrue(merchantId != null && merchantId > 0, DefaultErrorEnum.PARAMETER_INVALID, "门店id必须为正整数");
    • 问题 3:提交信息(Commit Message)不规范(最佳实践)

      • 问题描述:提交信息 "门店id判空 (by jiabao)" 过于简单,且包含冗余信息。
      • 影响分析:缺乏关联的业务需求单号(如 Jira 链接)或 Bug ID,且 Git 提交历史中已经包含 Author 信息,在 Message 中手动标注 "(by jiabao)" 属于冗余,不符合工业化工程实践。
      • 优化建议:采用更标准的提交格式,例如:feat: 增加门店绩效配置查询的入参非空校验 #ISSUE-123 或 fix: 修复查询接口缺少参数校验导致空指针的问题。

    二、评分明细

    • 功能实现的正确性与健壮性(35/40分):增加了必要的参数校验,提升了接口稳定性,但校验范围可进一步细化(如正整数判断)。
    • 安全性与潜在风险(30/30分):参数校验是防止非法数据进入业务层的有效手段,降低了潜在的空指针风险。
    • 最佳实践与可维护性(18/20分):代码结构清晰,使用了框架提供的 RpcAssert 工具类,符合团队技术栈规范。
    • 性能与资源利用(5/5分):逻辑简单,无性能瓶颈。
    • 提交信息质量(3/5分):描述了变更内容,但格式不标准,缺乏可追溯性。

    三、总分

    总分:91分

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