Commit 2206ee83 by zhouhaibao

refactor(service): 替换商家合同服务提供商引用为商家服务引用

- 将 merchantContractServiceProviderService.shopInEffectRef 方法调用替换为
  serviceMerchantRefService.getShopMerchantServiceRef
- 修改方法参数,将 record.getSceneType() 替换为 record.getBaseSceneCode()
- 更新错误提示信息中的场景类型获取方式,使用 SceneTypeEnum.getDisplayName() 获取显示名称
1 parent e2b14d2d
...@@ -558,8 +558,8 @@ public class MerchantReconciliationRuleService { ...@@ -558,8 +558,8 @@ public class MerchantReconciliationRuleService {
final SceneTypeEnum sceneTypeEnum = SceneTypeEnum.getByValue(record.getSceneType()); final SceneTypeEnum sceneTypeEnum = SceneTypeEnum.getByValue(record.getSceneType());
for (MerchantExpenseCategoryRuleLevelDTO item : expenseCategoryRules) { for (MerchantExpenseCategoryRuleLevelDTO item : expenseCategoryRules) {
if (item.getTargetMerchantId() != null) { if (item.getTargetMerchantId() != null) {
Boolean shopInEffectRef = merchantContractServiceProviderService.shopInEffectRef(merchantId, Boolean shopInEffectRef = serviceMerchantRefService.getShopMerchantServiceRef(merchantId,
item.getTargetMerchantId(), record.getSceneType()); item.getTargetMerchantId(), record.getBaseSceneCode());
if (!shopInEffectRef) { if (!shopInEffectRef) {
throw new RpcServiceException(RpcErrorEnum.DATA_INVALID_WITH_SPECIFIC_MSG, throw new RpcServiceException(RpcErrorEnum.DATA_INVALID_WITH_SPECIFIC_MSG,
String.format("在场景:%s,4s店:%d未关联服务商:%d", sceneTypeEnum.getDisplayName(), merchantId, item.getTargetMerchantId())); String.format("在场景:%s,4s店:%d未关联服务商:%d", sceneTypeEnum.getDisplayName(), merchantId, item.getTargetMerchantId()));
...@@ -568,8 +568,8 @@ public class MerchantReconciliationRuleService { ...@@ -568,8 +568,8 @@ public class MerchantReconciliationRuleService {
if (CollectionUtils.isNotEmpty(item.getChildren())) { if (CollectionUtils.isNotEmpty(item.getChildren())) {
for (MerchantExpenseCategoryRule child : item.getChildren()) { for (MerchantExpenseCategoryRule child : item.getChildren()) {
if (child.getTargetMerchantId() != null) { if (child.getTargetMerchantId() != null) {
Boolean shopInEffectRef = merchantContractServiceProviderService.shopInEffectRef(merchantId, Boolean shopInEffectRef = serviceMerchantRefService.getShopMerchantServiceRef(merchantId,
child.getTargetMerchantId(), record.getSceneType()); child.getTargetMerchantId(), record.getBaseSceneCode());
if (!shopInEffectRef) { if (!shopInEffectRef) {
throw new RpcServiceException(RpcErrorEnum.DATA_INVALID_WITH_SPECIFIC_MSG, throw new RpcServiceException(RpcErrorEnum.DATA_INVALID_WITH_SPECIFIC_MSG,
String.format("在场景:%s,4s店:%d未关联服务商:%d", sceneTypeEnum.getDisplayName(), merchantId, child.getTargetMerchantId())); String.format("在场景:%s,4s店:%d未关联服务商:%d", sceneTypeEnum.getDisplayName(), merchantId, child.getTargetMerchantId()));
......
  • @wangxw1
    commented
    Master

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

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

    • 问题描述:在抛出 RpcServiceException 异常时,使用了 sceneTypeEnum.getDisplayName()。如果 SceneTypeEnum.getByValue(record.getSceneType()) 无法匹配到对应的枚举值从而返回 null,此时调用 getDisplayName() 会触发 NullPointerException。
    • 影响分析:NPE 会掩盖原本应该抛出的业务异常(RpcServiceException),导致上层捕获不到预期的错误码和错误信息,增加排查难度并可能导致接口直接响应 500 内部错误。
    • 优化建议:在拼接异常信息时对 sceneTypeEnum 进行非空判断,或者提供默认值处理。 java String sceneName = sceneTypeEnum != null ? sceneTypeEnum.getDisplayName() : "未知场景(" + record.getSceneType() + ")"; throw new RpcServiceException(RpcErrorEnum.DATA_INVALID_WITH_SPECIFIC_MSG, String.format("在场景:%s,4s店:%d未关联服务商:%d", sceneName, merchantId, item.getTargetMerchantId()));

    2. 循环内高频调用外部服务存在性能瓶颈(性能与资源利用)

    • 问题描述:在 expenseCategoryRules 及其子集 children 的两层 for 循环中,频繁调用了 serviceMerchantRefService.getShopMerchantServiceRef 方法。
    • 影响分析:如果该方法涉及数据库查询或 RPC 远程调用,且循环次数较多,会导致经典的 N+1 性能问题,极大增加网络开销和数据库压力,造成接口响应缓慢。
    • 优化建议:建议采用“批量处理”的思想。在循环前,先遍历收集所有需要的 targetMerchantId,通过批量查询接口一次性获取所有的关联状态,最后在循环的内存中进行状态判断。

    3. 校验参数与异常提示信息的语义可能不一致(功能正确性)

    • 问题描述:本次变更将校验方法的参数由 record.getSceneType() 修改为了 record.getBaseSceneCode()。但在校验失败抛出异常时,提示信息中仍然使用的是基于 record.getSceneType() 解析出的 sceneTypeEnum.getDisplayName()。
    • 影响分析:如果 sceneType 与 baseSceneCode 在业务上的含义或具体值存在差异,会导致校验依据与最终给出的错误提示信息不匹配,对后续的客诉排查和用户理解造成误导。
    • 优化建议:请确认 baseSceneCode 与 sceneType 的业务关联。如果校验是基于 baseSceneCode 进行的,建议异常提示中也体现出 baseSceneCode 的信息,以保证逻辑和提示的强一致性。

    二、评分明细

    • 功能实现的正确性与健壮性(32 / 40分) 理由:核心业务替换逻辑清晰,未触发 SQL 子查询或 Dubbo 接口参数变更等危险操作。但存在明显的 NPE 隐患,且校验参数与提示信息存在潜在的语义不一致风险,扣除 8 分。

    • 安全性与潜在风险(30 / 30分) 理由:本次变更为内部服务调用替换,未引入 SQL 注入、XSS、越权或敏感信息泄露等安全风险。满分。

    • 最佳实践与可维护性(16 / 20分) 理由:代码整体可读性较好,但循环内执行外部依赖查询违背了工程最佳实践。扣除 4 分。

    • 性能与资源利用(2 / 5分) 理由:嵌套循环中调用服务方法存在较严重的性能隐患(N+1 问题),在数据量增长时极易成为性能瓶颈。扣除 3 分。

    • 提交信息质量(5 / 5分) 理由:Commit 信息清晰、结构规范,准确描述了替换的类、方法、参数变更以及异常提示的修改,具备良好的可追溯性。满分。

    总分:85分

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