Commit 6bf950dc by 林冲

全局修改根据"UGID_" + upgradeGoodsId 增加test订单判断

1 parent cbfa59c8
...@@ -1623,7 +1623,7 @@ public class GoodsOrderProfitAllocationService { ...@@ -1623,7 +1623,7 @@ public class GoodsOrderProfitAllocationService {
record.setBaseSceneCode(orderDTO.getBaseSceneCode()); record.setBaseSceneCode(orderDTO.getBaseSceneCode());
List<Byte> matchSubOrderCategoryTypes = Arrays.asList(GoodsGroupCategoryTypeEnum.GOODS_TYPE.getValue(), GoodsGroupCategoryTypeEnum.UPGRADE_GOODS.getValue()); List<Byte> matchSubOrderCategoryTypes = Arrays.asList(GoodsGroupCategoryTypeEnum.GOODS_TYPE.getValue(), GoodsGroupCategoryTypeEnum.UPGRADE_GOODS.getValue());
MerchantGoodsTypeGroupSettleRuleDTO goodsTypeGroupRule = merchantSettleAccountRuleService.matchGoodsTypeGroupRule(accountRule, MerchantGoodsTypeGroupSettleRuleDTO goodsTypeGroupRule = merchantSettleAccountRuleService.matchGoodsTypeGroupRule(accountRule,
subOrder.getGoodsSource(), subOrder.getPackageCode(), subOrder.getMerchantGoodsCode(), subOrder.getUpgradeGoodsId(), subOrder.getUpgradeGoodsType()); subOrder.getGoodsSource(), subOrder.getPackageCode(), subOrder.getMerchantGoodsCode(), subOrder.getUpgradeGoodsId(), subOrder.getUpgradeGoodsType(), orderDTO);
if (goodsTypeGroupRule == null) { if (goodsTypeGroupRule == null) {
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, "goodsTypeGroupRule can't be null"); throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, "goodsTypeGroupRule can't be null");
} }
......
...@@ -803,14 +803,18 @@ public class MerchantExpenseCategoryRuleService { ...@@ -803,14 +803,18 @@ public class MerchantExpenseCategoryRuleService {
return relation.getUpgradeGoodsId() != null && Objects.equals(relation.getUpgradeGoodsId(), upgradeGoodsId); return relation.getUpgradeGoodsId() != null && Objects.equals(relation.getUpgradeGoodsId(), upgradeGoodsId);
} }
private String buildSpecificGoodsKey(GoodsTypeGroupRelation relation) { private String buildSpecificGoodsKey(GoodsTypeGroupRelation relation, Byte orderType) {
if (relation == null) { if (relation == null) {
return null; return null;
} }
return buildSpecificGoodsKey(relation.getMerchantGoodsCode(), relation.getUpgradeGoodsId()); return buildSpecificGoodsKey(relation.getMerchantGoodsCode(), relation.getUpgradeGoodsId(), orderType);
} }
private String buildSpecificGoodsKey(String merchantGoodsCode, Integer upgradeGoodsId) { private String buildSpecificGoodsKey(String merchantGoodsCode, Integer upgradeGoodsId, Byte orderType) {
if (Objects.equals(CarLifeEnum.OrderType.NORMAL_TEST.getValue(), orderType)) {
log.info("测试订单,根据upgradeGoodsId匹配,upgradeGoodsId={}, orderType={}", upgradeGoodsId, orderType);
return "normal_test_" + upgradeGoodsId;
}
if (StringUtils.isNotBlank(merchantGoodsCode)) { if (StringUtils.isNotBlank(merchantGoodsCode)) {
return merchantGoodsCode; return merchantGoodsCode;
} }
...@@ -956,7 +960,7 @@ public class MerchantExpenseCategoryRuleService { ...@@ -956,7 +960,7 @@ public class MerchantExpenseCategoryRuleService {
if (CollectionUtils.isNotEmpty(noMatchGPackageRuleSubOrders)) { if (CollectionUtils.isNotEmpty(noMatchGPackageRuleSubOrders)) {
// 根据商品匹配 // 根据商品匹配
List<GoodsSubOrderDTO> noMatchGoodsRuleSubOrders = new ArrayList<>(); List<GoodsSubOrderDTO> noMatchGoodsRuleSubOrders = new ArrayList<>();
List<MerchantExpenseCategoryRuleDTO> matchGoodsExpenseRules = filterMatchGoodsExpenseRules(accountRule, noMatchGPackageRuleSubOrders, targetTypes, noMatchGoodsRuleSubOrders); List<MerchantExpenseCategoryRuleDTO> matchGoodsExpenseRules = filterMatchGoodsExpenseRules(accountRule, noMatchGPackageRuleSubOrders, targetTypes, noMatchGoodsRuleSubOrders, orderDTO);
ruleDTOS.addAll(matchGoodsExpenseRules); ruleDTOS.addAll(matchGoodsExpenseRules);
log.info("具体商品费用类目规则匹配完成,orderCode={}, 命中规则数={}, 待继续匹配子单数={}", log.info("具体商品费用类目规则匹配完成,orderCode={}, 命中规则数={}, 待继续匹配子单数={}",
orderDTO == null ? null : orderDTO.getOrderCode(), orderDTO == null ? null : orderDTO.getOrderCode(),
...@@ -1268,7 +1272,7 @@ public class MerchantExpenseCategoryRuleService { ...@@ -1268,7 +1272,7 @@ public class MerchantExpenseCategoryRuleService {
} }
private List<MerchantExpenseCategoryRuleDTO> filterMatchGoodsExpenseRules(MerchantSettleAccountRuleDTO accountRule, List<GoodsSubOrderDTO> subOrders, List<Byte> targetTypes, List<GoodsSubOrderDTO> noMatchGoodsRuleSubOrders) { private List<MerchantExpenseCategoryRuleDTO> filterMatchGoodsExpenseRules(MerchantSettleAccountRuleDTO accountRule, List<GoodsSubOrderDTO> subOrders, List<Byte> targetTypes, List<GoodsSubOrderDTO> noMatchGoodsRuleSubOrders, GoodsOrderDTO orderDTO) {
List<MerchantExpenseCategoryRuleDTO> matchGoodsExpenseRules = new ArrayList<>(); List<MerchantExpenseCategoryRuleDTO> matchGoodsExpenseRules = new ArrayList<>();
if (CollectionUtils.isNotEmpty(subOrders) if (CollectionUtils.isNotEmpty(subOrders)
&& accountRule != null && accountRule != null
...@@ -1286,7 +1290,7 @@ public class MerchantExpenseCategoryRuleService { ...@@ -1286,7 +1290,7 @@ public class MerchantExpenseCategoryRuleService {
Map<String, MerchantGoodsTypeGroupSettleRuleDTO> specificGoodsGroupRuleMap = new HashMap<>(); Map<String, MerchantGoodsTypeGroupSettleRuleDTO> specificGoodsGroupRuleMap = new HashMap<>();
for (MerchantGoodsTypeGroupSettleRuleDTO specificGoodsGroupRule : specificGoodsGroupRules) { for (MerchantGoodsTypeGroupSettleRuleDTO specificGoodsGroupRule : specificGoodsGroupRules) {
for (GoodsTypeGroupRelation relation : specificGoodsGroupRule.getGoodsTypeGroupRelations()) { for (GoodsTypeGroupRelation relation : specificGoodsGroupRule.getGoodsTypeGroupRelations()) {
String specificGoodsKey = buildSpecificGoodsKey(relation); String specificGoodsKey = buildSpecificGoodsKey(relation, orderDTO.getOrderType());
if (StringUtils.isNotBlank(specificGoodsKey)) { if (StringUtils.isNotBlank(specificGoodsKey)) {
specificGoodsGroupRuleMap.put(specificGoodsKey, specificGoodsGroupRule); specificGoodsGroupRuleMap.put(specificGoodsKey, specificGoodsGroupRule);
} }
...@@ -1310,7 +1314,7 @@ public class MerchantExpenseCategoryRuleService { ...@@ -1310,7 +1314,7 @@ public class MerchantExpenseCategoryRuleService {
subOrder.getGoodsSource(), subOrder.getGoodsSource(),
subOrder.getMerchantGoodsCode(), subOrder.getMerchantGoodsCode(),
subOrder.getUpgradeGoodsId()); subOrder.getUpgradeGoodsId());
String specificGoodsKey = buildSpecificGoodsKey(subOrder.getMerchantGoodsCode(), subOrder.getUpgradeGoodsId()); String specificGoodsKey = buildSpecificGoodsKey(subOrder.getMerchantGoodsCode(), subOrder.getUpgradeGoodsId(), orderDTO.getOrderType());
MerchantGoodsTypeGroupSettleRuleDTO goodsTypeGroupSettleRule = specificGoodsGroupRuleMap.get(specificGoodsKey); MerchantGoodsTypeGroupSettleRuleDTO goodsTypeGroupSettleRule = specificGoodsGroupRuleMap.get(specificGoodsKey);
if (goodsTypeGroupSettleRule != null) { if (goodsTypeGroupSettleRule != null) {
isMatch = true; isMatch = true;
......
...@@ -542,17 +542,17 @@ public class MerchantSettleAccountRuleService { ...@@ -542,17 +542,17 @@ public class MerchantSettleAccountRuleService {
* @date 2024年03月13日 11:49:58 * @date 2024年03月13日 11:49:58
*/ */
public MerchantGoodsTypeGroupSettleRuleDTO matchGoodsTypeGroupRule(MerchantSettleAccountRuleDTO merchantSettleAccountRuleDTO, Byte goodsSource, String packageCode, public MerchantGoodsTypeGroupSettleRuleDTO matchGoodsTypeGroupRule(MerchantSettleAccountRuleDTO merchantSettleAccountRuleDTO, Byte goodsSource, String packageCode,
String merchantGoodsCode, Integer upgradeGoodsId, Integer goodsType){ String merchantGoodsCode, Integer upgradeGoodsId, Integer goodsType, GoodsOrderDTO orderDTO){
try{ try{
return merchantGoodsTypeGroupSettleRuleService.matchGoodsTypeGroupRule(merchantSettleAccountRuleDTO.getGoodsTypeGroupSettleRules(), goodsSource, packageCode, merchantGoodsCode, upgradeGoodsId, goodsType); return merchantGoodsTypeGroupSettleRuleService.matchGoodsTypeGroupRule(merchantSettleAccountRuleDTO.getGoodsTypeGroupSettleRules(), goodsSource, packageCode, merchantGoodsCode, upgradeGoodsId, goodsType, orderDTO);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, e.getMessage()); throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, e.getMessage());
} }
} }
public MerchantGoodsTypeGroupSettleRuleDTO matchGoodsTypeGroupRule(MerchantSettleAccountRuleDTO merchantSettleAccountRuleDTO, Byte goodsSource, String packageCode, Integer upgradeGoodsId, Integer goodsType){ public MerchantGoodsTypeGroupSettleRuleDTO matchGoodsTypeGroupRule(MerchantSettleAccountRuleDTO merchantSettleAccountRuleDTO, Byte goodsSource, String packageCode, Integer upgradeGoodsId, Integer goodsType, GoodsOrderDTO orderDTO){
return matchGoodsTypeGroupRule(merchantSettleAccountRuleDTO, goodsSource, packageCode, null, upgradeGoodsId, goodsType); return matchGoodsTypeGroupRule(merchantSettleAccountRuleDTO, goodsSource, packageCode, null, upgradeGoodsId, goodsType, orderDTO);
} }
......
...@@ -311,7 +311,7 @@ public class MerchantExpenseDistributionService { ...@@ -311,7 +311,7 @@ public class MerchantExpenseDistributionService {
.findFirst(); .findFirst();
if (subOrderDTO.isPresent()) { if (subOrderDTO.isPresent()) {
goodsTypeGroupRule = merchantGoodsTypeGroupSettleRuleService.matchGoodsTypeGroupRule(accountRule.getGoodsTypeGroupSettleRules(), goodsTypeGroupRule = merchantGoodsTypeGroupSettleRuleService.matchGoodsTypeGroupRule(accountRule.getGoodsTypeGroupSettleRules(),
subOrderDTO.get().getGoodsSource(), subOrderDTO.get().getPackageCode(), subOrderDTO.get().getMerchantGoodsCode(), subOrderDTO.get().getUpgradeGoodsId(), subOrderDTO.get().getUpgradeGoodsType()); subOrderDTO.get().getGoodsSource(), subOrderDTO.get().getPackageCode(), subOrderDTO.get().getMerchantGoodsCode(), subOrderDTO.get().getUpgradeGoodsId(), subOrderDTO.get().getUpgradeGoodsType(), orderDTO);
} }
} }
}else{ }else{
......
package cn.com.glsx.dj.smartcarlife.service.merchantSettleDistribution; package cn.com.glsx.dj.smartcarlife.service.merchantSettleDistribution;
import cn.com.glsx.dj.smartcarlife.dto.GoodsOrderDTO;
import cn.com.glsx.dj.smartcarlife.dto.GoodsTypeGroupRelationDTO; import cn.com.glsx.dj.smartcarlife.dto.GoodsTypeGroupRelationDTO;
import cn.com.glsx.dj.smartcarlife.dto.MerchantGoodsTypeGroupSettleRuleDTO; import cn.com.glsx.dj.smartcarlife.dto.MerchantGoodsTypeGroupSettleRuleDTO;
import cn.com.glsx.dj.smartcarlife.dto.settleDistribution.MerchantExpenseCategoryRuleLevelDTO; import cn.com.glsx.dj.smartcarlife.dto.settleDistribution.MerchantExpenseCategoryRuleLevelDTO;
...@@ -225,7 +226,7 @@ public class MerchantGoodsTypeGroupSettleRuleService { ...@@ -225,7 +226,7 @@ public class MerchantGoodsTypeGroupSettleRuleService {
public MerchantGoodsTypeGroupSettleRuleDTO matchGoodsTypeGroupRule(List<MerchantGoodsTypeGroupSettleRuleDTO> goodsTypeGroupSettleRules, Byte goodsSource, String packageCode, public MerchantGoodsTypeGroupSettleRuleDTO matchGoodsTypeGroupRule(List<MerchantGoodsTypeGroupSettleRuleDTO> goodsTypeGroupSettleRules, Byte goodsSource, String packageCode,
String merchantGoodsCode, Integer upgradeGoodsId, Integer goodsType){ String merchantGoodsCode, Integer upgradeGoodsId, Integer goodsType, GoodsOrderDTO orderDTO){
if (goodsSource != null && GoodsSourceEnum.DJ.getValue() != goodsSource) { if (goodsSource != null && GoodsSourceEnum.DJ.getValue() != goodsSource) {
return goodsTypeGroupSettleRules.stream() return goodsTypeGroupSettleRules.stream()
.filter(rule -> rule.getGroupType() == GoodsTypeGroupTypeEnum.TYPES.getValue() .filter(rule -> rule.getGroupType() == GoodsTypeGroupTypeEnum.TYPES.getValue()
...@@ -245,7 +246,7 @@ public class MerchantGoodsTypeGroupSettleRuleService { ...@@ -245,7 +246,7 @@ public class MerchantGoodsTypeGroupSettleRuleService {
} }
RpcAssert.assertIsTrue(StringUtils.isNotBlank(merchantGoodsCode) || upgradeGoodsId != null, DefaultErrorEnum.DATA_NULL, RpcAssert.assertIsTrue(StringUtils.isNotBlank(merchantGoodsCode) || upgradeGoodsId != null, DefaultErrorEnum.DATA_NULL,
"merchantGoodsCode and upgradeGoodsId can not both be null"); "merchantGoodsCode and upgradeGoodsId can not both be null");
MerchantGoodsTypeGroupSettleRuleDTO rule = thiz.getGoodsTypeGroupRuleBySpecificGoods(goodsTypeGroupSettleRules, merchantGoodsCode, upgradeGoodsId); MerchantGoodsTypeGroupSettleRuleDTO rule = thiz.getGoodsTypeGroupRuleBySpecificGoods(goodsTypeGroupSettleRules, merchantGoodsCode, upgradeGoodsId, orderDTO);
if (rule != null) { if (rule != null) {
return rule; return rule;
} }
...@@ -254,9 +255,9 @@ public class MerchantGoodsTypeGroupSettleRuleService { ...@@ -254,9 +255,9 @@ public class MerchantGoodsTypeGroupSettleRuleService {
} }
} }
public MerchantGoodsTypeGroupSettleRuleDTO matchGoodsTypeGroupRule(List<MerchantGoodsTypeGroupSettleRuleDTO> goodsTypeGroupSettleRules, Byte goodsSource, String packageCode, Integer upgradeGoodsId, Integer goodsType){ // public MerchantGoodsTypeGroupSettleRuleDTO matchGoodsTypeGroupRule(List<MerchantGoodsTypeGroupSettleRuleDTO> goodsTypeGroupSettleRules, Byte goodsSource, String packageCode, Integer upgradeGoodsId, Integer goodsType){
return matchGoodsTypeGroupRule(goodsTypeGroupSettleRules, goodsSource, packageCode, null, upgradeGoodsId, goodsType); // return matchGoodsTypeGroupRule(goodsTypeGroupSettleRules, goodsSource, packageCode, null, upgradeGoodsId, goodsType);
} // }
/** /**
...@@ -340,7 +341,7 @@ public class MerchantGoodsTypeGroupSettleRuleService { ...@@ -340,7 +341,7 @@ public class MerchantGoodsTypeGroupSettleRuleService {
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class) @Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public MerchantGoodsTypeGroupSettleRuleDTO getGoodsTypeGroupRuleBySpecificGoods(List<MerchantGoodsTypeGroupSettleRuleDTO> goodsTypeGroupSettleRules, public MerchantGoodsTypeGroupSettleRuleDTO getGoodsTypeGroupRuleBySpecificGoods(List<MerchantGoodsTypeGroupSettleRuleDTO> goodsTypeGroupSettleRules,
String merchantGoodsCode, Integer upgradeGoodsId){ String merchantGoodsCode, Integer upgradeGoodsId, GoodsOrderDTO orderDTO){
RpcAssert.assertNotEmpty(goodsTypeGroupSettleRules, DefaultErrorEnum.DATA_NULL,"goodsTypeGroupSettleRules not be empty"); RpcAssert.assertNotEmpty(goodsTypeGroupSettleRules, DefaultErrorEnum.DATA_NULL,"goodsTypeGroupSettleRules not be empty");
Map<String, MerchantGoodsTypeGroupSettleRuleDTO> groupSettleRuleDTOMap = new HashMap<>(); Map<String, MerchantGoodsTypeGroupSettleRuleDTO> groupSettleRuleDTOMap = new HashMap<>();
for (MerchantGoodsTypeGroupSettleRuleDTO groupSettleRule : goodsTypeGroupSettleRules) { for (MerchantGoodsTypeGroupSettleRuleDTO groupSettleRule : goodsTypeGroupSettleRules) {
...@@ -361,7 +362,7 @@ public class MerchantGoodsTypeGroupSettleRuleService { ...@@ -361,7 +362,7 @@ public class MerchantGoodsTypeGroupSettleRuleService {
} }
for (GoodsTypeGroupRelation goodsTypeGroupRelation : groupSettleRule.getGoodsTypeGroupRelations()) { for (GoodsTypeGroupRelation goodsTypeGroupRelation : groupSettleRule.getGoodsTypeGroupRelations()) {
if (Objects.equals(GoodsGroupCategoryTypeEnum.UPGRADE_GOODS.getValue(), goodsTypeGroupRelation.getCategoryType())) { if (Objects.equals(GoodsGroupCategoryTypeEnum.UPGRADE_GOODS.getValue(), goodsTypeGroupRelation.getCategoryType())) {
String specificGoodsKey = buildSpecificGoodsKey(goodsTypeGroupRelation); String specificGoodsKey = buildSpecificGoodsKey(goodsTypeGroupRelation, orderDTO.getOrderType());
if (StringUtils.isNotBlank(specificGoodsKey)) { if (StringUtils.isNotBlank(specificGoodsKey)) {
groupSettleRuleDTOMap.put(specificGoodsKey, groupSettleRule); groupSettleRuleDTOMap.put(specificGoodsKey, groupSettleRule);
} }
...@@ -369,23 +370,27 @@ public class MerchantGoodsTypeGroupSettleRuleService { ...@@ -369,23 +370,27 @@ public class MerchantGoodsTypeGroupSettleRuleService {
} }
} }
} }
String specificGoodsKey = buildSpecificGoodsKey(merchantGoodsCode, upgradeGoodsId); String specificGoodsKey = buildSpecificGoodsKey(merchantGoodsCode, upgradeGoodsId, orderDTO.getOrderType());
return StringUtils.isBlank(specificGoodsKey) ? null : groupSettleRuleDTOMap.get(specificGoodsKey); return StringUtils.isBlank(specificGoodsKey) ? null : groupSettleRuleDTOMap.get(specificGoodsKey);
} }
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class) // @Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public MerchantGoodsTypeGroupSettleRuleDTO getGoodsTypeGroupRuleByUpgradeGoodsId(List<MerchantGoodsTypeGroupSettleRuleDTO> goodsTypeGroupSettleRules, Integer upgradeGoodsId){ // public MerchantGoodsTypeGroupSettleRuleDTO getGoodsTypeGroupRuleByUpgradeGoodsId(List<MerchantGoodsTypeGroupSettleRuleDTO> goodsTypeGroupSettleRules, Integer upgradeGoodsId, GoodsOrderDTO orderDTO){
return getGoodsTypeGroupRuleBySpecificGoods(goodsTypeGroupSettleRules, null, upgradeGoodsId); // return getGoodsTypeGroupRuleBySpecificGoods(goodsTypeGroupSettleRules, null, upgradeGoodsId, orderDTO);
} // }
private String buildSpecificGoodsKey(GoodsTypeGroupRelation relation) { private String buildSpecificGoodsKey(GoodsTypeGroupRelation relation, Byte orderType) {
if (relation == null) { if (relation == null) {
return null; return null;
} }
return buildSpecificGoodsKey(relation.getMerchantGoodsCode(), relation.getUpgradeGoodsId()); return buildSpecificGoodsKey(relation.getMerchantGoodsCode(), relation.getUpgradeGoodsId(), orderType);
} }
private String buildSpecificGoodsKey(String merchantGoodsCode, Integer upgradeGoodsId) { private String buildSpecificGoodsKey(String merchantGoodsCode, Integer upgradeGoodsId, Byte orderType) {
if (Objects.equals(CarLifeEnum.OrderType.NORMAL_TEST.getValue(), orderType)) {
log.info("测试订单,根据upgradeGoodsId匹配,upgradeGoodsId={}, orderType={}", upgradeGoodsId, orderType);
return "normal_test_" + upgradeGoodsId;
}
if (StringUtils.isNotBlank(merchantGoodsCode)) { if (StringUtils.isNotBlank(merchantGoodsCode)) {
return merchantGoodsCode; return merchantGoodsCode;
} }
......
  • @wangxw1
    commented
    Master

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

    1. 严重的空指针异常(NPE)风险

    • 问题描述:在 MerchantExpenseCategoryRuleService.java 中,新增的逻辑直接调用了 orderDTO.getOrderType()(如第1293行、1317行)。但在该类的上游调用处(第966行 orderDTO == null ? null : orderDTO.getOrderCode()),明确暗示了 orderDTO 是可能为 null 的。
    • 影响分析:当传入的 orderDTO 为 null 时,直接调用 .getOrderType() 会触发 NullPointerException,导致整个费用类目规则匹配流程中断,直接影响核心交易结算链路。
    • 优化建议:在获取 orderType 前必须进行空值判断。 java // 建议修改为: Byte orderType = orderDTO != null ? orderDTO.getOrderType() : null; String specificGoodsKey = buildSpecificGoodsKey(relation, orderType);

    2. 接口签名变更风险与参数透传(代码过度耦合)

    • 问题描述:本次修改在多个 Service 的公共方法签名中强行追加了 GoodsOrderDTO orderDTO 参数。由于当前模块为 rpc-dj-smartcarlife,这些 Service 极有可能是对外暴露的 Dubbo 服务提供者。
    • 影响分析:
      • 致命风险:如果这些接口是 Dubbo Remote 接口,直接修改已有请求参数将导致线上旧版本消费者调用失败(找不到对应签名的方法),引发生产事故(违反重要规则)。
      • 架构腐化:即使是内部方法,仅仅为了底层构建 Key 需要用到 orderType,就将整个庞大的 GoodsOrderDTO 对象穿透多个业务层传递,属于典型的“游离数据(Tramp Data)”反模式,严重增加了底层规则服务与上游订单模型的耦合度。
    • 优化建议:
      • 若为 Dubbo 接口,严禁直接修改原有方法签名。应保留原方法并向下兼容,或者通过 RpcContext.getContext().setAttachment() 隐式传递测试标识。
      • 若仅为内部调用,建议只传递真正需要的最小依赖参数 Byte orderType,而不是整个 GoodsOrderDTO。

    3. 核心逻辑重复(DRY原则)与潜在的字符串拼接缺陷

    • 问题描述:
      • buildSpecificGoodsKey 方法的完整逻辑(包含新增的 normal_test_ 判断)在 MerchantExpenseCategoryRuleService 和 MerchantGoodsTypeGroupSettleRuleService 两个类中被完全复制粘贴了一遍。
      • 逻辑细节存在隐患:当 orderType 为测试订单,但 upgradeGoodsId 为 null 时,代码 return "normal_test_" + upgradeGoodsId; 会返回字符串 "normal_test_null"。
    • 影响分析:违反 DRY 原则导致后续维护成本翻倍(例如未来要修改前缀,极易漏改)。返回 "normal_test_null" 这种包含 "null" 字面量的字符串通常不符合业务预期,容易引发后续匹配逻辑的隐蔽 Bug。
    • 优化建议:
      • 将 buildSpecificGoodsKey 提取到公共的策略类或工具类中复用。
      • 增加对 upgradeGoodsId 为空的防御性处理,并将 "normal_test_" 提取为常量。
      • 清理掉代码中直接注释掉的废弃方法(如 // public MerchantGoodsTypeGroupSettleRuleDTO matchGoodsTypeGroupRule...),保持代码整洁。

    二、评分明细

    • 功能实现的正确性与健壮性(25/40分):存在明显的 NPE 隐患(orderDTO 未判空);字符串拼接逻辑对 null 值处理不够严谨(会产生 "normal_test_null")。
    • 安全性与潜在风险(20/30分):无常规的注入或越权漏洞,但在 RPC 模块中大范围修改 Service 公共方法签名,极易引发 Dubbo 消费者调用失败的系统级故障风险。
    • 最佳实践与可维护性(10/20分):存在明显的代码复制粘贴现象;将重量级 DTO 穿透传递只为获取一个字段,耦合度过高;存在未删除的注释死代码。
    • 性能与资源利用(4/5分):无明显性能瓶颈。但注意到 getGoodsTypeGroupRuleBySpecificGoods 这种纯内存组装 Map 的逻辑使用了 @Transactional 注解,会产生不必要的事务代理开销。
    • 提交信息质量(3/5分):Commit 信息描述为增加 "UGID_" + upgradeGoodsId,但实际代码实现是 "normal_test_" + upgradeGoodsId,提交信息与实际代码行为存在矛盾,会误导后续排查问题的开发人员。

    总分:62分

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