Commit cbfa59c8 by 周立明

fix(merchantSettle): 新增订单类型参数到分账规则匹配流程

扩展商户分账规则查询方法,新增orderDTO参数传递订单类型,
在商品分组分账规则匹配时传入订单类型用于更精准的规则匹配
1 parent efcec544
......@@ -201,7 +201,7 @@ public class MerchantDistributionRuleService {
}
}
public MerchantDistributionRuleDTO getByProfitExpenseCategoryCalWithOwning(OrderExpenseCategoryCalculatedDTO profitCategoryCalculated, MerchantDivisionRuleDTO divisionRule){
public MerchantDistributionRuleDTO getByProfitExpenseCategoryCalWithOwning(OrderExpenseCategoryCalculatedDTO profitCategoryCalculated, MerchantDivisionRuleDTO divisionRule,final GoodsOrderDTO orderDTO){
RpcAssert.assertNotNull(profitCategoryCalculated, DefaultErrorEnum.DATA_NULL,"profitCategoryCalculated not be null");
RpcAssert.assertNotNull(divisionRule, DefaultErrorEnum.DATA_NULL,"divisionRule not be null");
Integer divisionRuleId = divisionRule.getId();
......@@ -222,7 +222,7 @@ public class MerchantDistributionRuleService {
profitCategoryCalculated.getOrderCode(),
profitCategoryCalculated.getSubOrderCode(),
profitCategoryCalculated.getExpenseCategoryId());
return getByProfitExpenseCategoryCalForProcessExpenseCategoryWithOwning(profitCategoryCalculated, divisionRule);
return getByProfitExpenseCategoryCalForProcessExpenseCategoryWithOwning(profitCategoryCalculated, divisionRule,orderDTO);
}
// 普通费用类目
if (canMatchWithoutDB(profitCategoryCalculated)) {
......@@ -407,7 +407,8 @@ public class MerchantDistributionRuleService {
return null;
}
public MerchantDistributionRuleDTO getByProfitExpenseCategoryCalForProcessExpenseCategoryWithOwning(OrderExpenseCategoryCalculatedDTO profitCategoryCalculated, MerchantDivisionRuleDTO divisionRule) {
public MerchantDistributionRuleDTO getByProfitExpenseCategoryCalForProcessExpenseCategoryWithOwning(OrderExpenseCategoryCalculatedDTO profitCategoryCalculated, MerchantDivisionRuleDTO divisionRule,
final GoodsOrderDTO orderDTO) {
if (StringUtils.isNotBlank(profitCategoryCalculated.getSubOrderCode())
&& profitCategoryCalculated.getExpenseCategoryId() != null
&& CollectionUtils.isNotEmpty(divisionRule.getGoodsTypeGroupDivisionRules())) {
......@@ -417,7 +418,9 @@ public class MerchantDistributionRuleService {
}
// 获取匹配的分组分账规则(商品>分类>全部品类)
MerchantGoodsTypeGroupDivisionRuleDTO groupDivisionRule = merchantGoodsTypeGroupDivisionRuleService.matchRule(
divisionRule.getGoodsTypeGroupDivisionRules(), subOrder.getGoodsSource(), subOrder.getPackageCode(), subOrder.getMerchantGoodsCode(), subOrder.getUpgradeGoodsId(), subOrder.getUpgradeGoodsType());
divisionRule.getGoodsTypeGroupDivisionRules(), subOrder.getGoodsSource(), subOrder.getPackageCode(),
subOrder.getMerchantGoodsCode(), subOrder.getUpgradeGoodsId(), subOrder.getUpgradeGoodsType(),
orderDTO.getOrderType());
if (CollectionUtils.isNotEmpty(groupDivisionRule.getOwningMerchantDistributionRules())) {
log.info("流程费用类目匹配到分账归属规则组,orderCode={}, subOrderCode={}, expenseCategoryId={}, groupRuleId={}, ruleCount={}",
profitCategoryCalculated.getOrderCode(),
......
......@@ -248,7 +248,7 @@ public class MerchantExpenseDistributionService {
profitCategoryCalculated.getNodeType());
return null;
}
MerchantDistributionRuleDTO merchantDistributionRuleDTO = merchantDistributionRuleService.getByProfitExpenseCategoryCalWithOwning(profitCategoryCalculated, divisionRule);
MerchantDistributionRuleDTO merchantDistributionRuleDTO = merchantDistributionRuleService.getByProfitExpenseCategoryCalWithOwning(profitCategoryCalculated, divisionRule,orderDTO);
if (merchantDistributionRuleDTO == null) {
log.info("找不到匹配的商户分账规则,历史规则未设置费用归属, profitCategoryCalculated:{}, divisionRule:{}", profitCategoryCalculated, divisionRule);
return null;
......
  • @wangxw1
    commented
    Master

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

    1. 潜在的空指针异常(NPE)风险(功能健壮性)

    • 问题描述:在 MerchantDistributionRuleService.java 中,新引入的参数 orderDTO 在向下传递后,直接调用了 orderDTO.getOrderType()。但在入口方法 getByProfitExpenseCategoryCalWithOwning 中,仅对原有的 profitCategoryCalculated 和 divisionRule 进行了 RpcAssert.assertNotNull 校验,未对新增的 orderDTO 进行非空校验。
    • 影响分析:如果上游调用方(如 MerchantExpenseDistributionService)因为某些异常情况传入了 null 的 orderDTO,将直接导致 NullPointerException,阻断分账规则匹配的主流程。
    • 优化建议:在方法入口处增加对 orderDTO 的非空断言,或者在调用 getOrderType() 时进行安全的空值判断。 java public MerchantDistributionRuleDTO getByProfitExpenseCategoryCalWithOwning(OrderExpenseCategoryCalculatedDTO profitCategoryCalculated, MerchantDivisionRuleDTO divisionRule, final GoodsOrderDTO orderDTO){ RpcAssert.assertNotNull(profitCategoryCalculated, DefaultErrorEnum.DATA_NULL,"profitCategoryCalculated not be null"); RpcAssert.assertNotNull(divisionRule, DefaultErrorEnum.DATA_NULL,"divisionRule not be null"); // 增加非空校验 RpcAssert.assertNotNull(orderDTO, DefaultErrorEnum.DATA_NULL,"orderDTO not be null"); // ... }

    2. 违反迪米特法则,存在过度耦合(最佳实践)

    • 问题描述:方法 getByProfitExpenseCategoryCalWithOwning 及其内部调用的方法新增了整个 GoodsOrderDTO 对象作为参数,但实际上底层业务逻辑仅仅使用了该对象的 orderType 字段(orderDTO.getOrderType())。
    • 影响分析:传递整个大对象不仅增加了方法间的耦合度(使分账服务强依赖于订单全量模型),还降低了代码的可复用性。如果未来有其他非标准订单场景也需要匹配该规则,但无法提供完整的 GoodsOrderDTO,将难以复用此方法。
    • 优化建议:按需传递,将参数 final GoodsOrderDTO orderDTO 更改为具体的字段类型(如 final Integer orderType 或 String orderType,取决于实际类型),降低模块间的耦合。

    3. 需警惕 Dubbo 接口参数变更风险(重要规则校验)

    • 问题描述:代码直接修改了 getByProfitExpenseCategoryCalWithOwning 等方法的签名(新增了入参)。
    • 影响分析:根据审查重要规则,如果 MerchantDistributionRuleService 是暴露给外部的 Dubbo 服务提供者(Remote 接口的实现),直接修改已有方法的请求参数将导致新老版本不兼容。消费者调用旧接口时会报 NoSuchMethodException 或序列化异常,引发严重的生产故障。
    • 优化建议:请确认该类是否为 Dubbo 暴露的接口实现类。如果是:绝对不允许直接修改原方法签名。应采用方法重载(Overload)的方式新增带有 orderDTO 的方法,并在老方法中调用新方法(传入默认值或 null),以保证向下兼容性。如果仅为本地 Spring Bean 服务,则无此风险,但仍建议结合问题 2 优化入参。

    二、评分明细

    • 功能实现的正确性与健壮性(32/40分) 扣分理由:业务逻辑的传参链路是正确的,但遗漏了新增参数对象的非空校验,在复杂业务场景下存在引发空指针异常的隐患。

    • 安全性与潜在风险(30/30分) 得分理由:本次修改仅涉及内部参数传递与规则匹配,未引入 SQL 注入、越权、敏感信息泄露等安全漏洞。

    • 最佳实践与可维护性(15/20分) 扣分理由:方法签名越来越长(底层 matchRule 已达 7 个参数);为了获取单一字段传递了整个 DTO 对象,不符合接口隔离与最小知识原则(迪米特法则),增加了对象耦合。

    • 性能与资源利用(5/5分) 得分理由:仅增加了对象引用的传递,未引入复杂的计算或阻塞操作,无性能瓶颈或资源浪费。

    • 提交信息质量(5/5分) 得分理由:Commit 信息(fix(merchantSettle): 新增订单类型参数到分账规则匹配流程)遵循了 Angular 规范,清晰准确地描述了修改内容及其业务目的,可追溯性极强。

    总分:87分

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