Commit 28d41e87 by 张富康

fix(staffPerformance): 修复其他品牌推荐数统计逻辑

- 新增对childBrandId等于-1时其他品牌推荐数的处理
- 分别添加了广联不同行为场景下其他品牌的推荐计数赋值
- 解决了其他品牌推荐数无法正确统计的问题
- 保持与上阶品牌推荐数处理逻辑一致性
1 parent a5b175a2
...@@ -328,6 +328,10 @@ public class StaffPerformanceCalService { ...@@ -328,6 +328,10 @@ public class StaffPerformanceCalService {
if (ObjectUtil.equals(childBrandId, shangjieBrandId)) { if (ObjectUtil.equals(childBrandId, shangjieBrandId)) {
storeValidRecommendationCount = deliveryCount.getQgShangjCount(); storeValidRecommendationCount = deliveryCount.getQgShangjCount();
} }
// 其他品牌
if (ObjectUtil.equals(childBrandId, -1)) {
storeValidRecommendationCount = deliveryCount.getQgOtherCount();
}
} }
// 2-会员权益(广联权益)-qy; // 2-会员权益(广联权益)-qy;
if (ObjectUtil.equals(effectiveReferralReviewSceneType, (byte) 2)) { if (ObjectUtil.equals(effectiveReferralReviewSceneType, (byte) 2)) {
...@@ -351,6 +355,10 @@ public class StaffPerformanceCalService { ...@@ -351,6 +355,10 @@ public class StaffPerformanceCalService {
if (ObjectUtil.equals(childBrandId, shangjieBrandId)) { if (ObjectUtil.equals(childBrandId, shangjieBrandId)) {
storeValidRecommendationCount = deliveryCount.getQyShangjCount(); storeValidRecommendationCount = deliveryCount.getQyShangjCount();
} }
// 其他品牌
if (ObjectUtil.equals(childBrandId, -1)) {
storeValidRecommendationCount = deliveryCount.getQyOtherCount();
}
} }
// 3-单延保-yb; // 3-单延保-yb;
if (ObjectUtil.equals(effectiveReferralReviewSceneType, (byte) 3)) { if (ObjectUtil.equals(effectiveReferralReviewSceneType, (byte) 3)) {
...@@ -374,6 +382,10 @@ public class StaffPerformanceCalService { ...@@ -374,6 +382,10 @@ public class StaffPerformanceCalService {
if (ObjectUtil.equals(childBrandId, shangjieBrandId)) { if (ObjectUtil.equals(childBrandId, shangjieBrandId)) {
storeValidRecommendationCount = deliveryCount.getYbShangjCount(); storeValidRecommendationCount = deliveryCount.getYbShangjCount();
} }
// 其他品牌
if (ObjectUtil.equals(childBrandId, -1)) {
storeValidRecommendationCount = deliveryCount.getYbOtherCount();
}
} }
} }
} }
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议,如果必要,给出代码示例(仅限 Top 3)

    1. 【功能正确性/高风险】ObjectUtil.equals 存在潜在的类型不匹配导致判断失效的风险

    • 问题描述:代码中使用了 ObjectUtil.equals(childBrandId, -1)。在 Java 中,字面量 -1 默认是 Integer 类型。如果 childBrandId 的数据类型是 Long、Short 或 Byte(从上下文中 (byte) 2 的强转来看,项目中对类型要求严格),ObjectUtil.equals 会因为类型不一致而永远返回 false(例如 Long 类型的 -1L 和 Integer 类型的 -1 不相等)。
    • 影响分析:如果 childBrandId 不是 Integer 类型,这段新增的逻辑将永远不会被触发,导致“其他品牌推荐数”依然无法正确统计,修复无效。
    • 优化建议:明确 childBrandId 的数据类型,并使用对应类型的字面量或常量进行比较。如果类型是 Long,应写为 -1L。 java // 假设 childBrandId 是 Long 类型 if (ObjectUtil.equals(childBrandId, -1L)) { storeValidRecommendationCount = deliveryCount.getQgOtherCount(); }

    2. 【最佳实践/可维护性】魔法值(Magic Number)硬编码

    • 问题描述:代码中多次直接使用 -1 来代表“其他品牌”,这是一种典型的魔法值硬编码。
    • 影响分析:降低了代码的可读性和可维护性。后续如果业务调整,“其他品牌”的标识发生变化,需要在多个地方进行全局搜索和替换,容易遗漏出错。
    • 优化建议:在类顶部提取一个具有明确业务含义的常量。

      private static final Long OTHER_BRAND_ID = -1L; // 类型请根据实际情况定义为 Long 或 Integer
      
      // 使用时
      if (ObjectUtil.equals(childBrandId, OTHER_BRAND_ID)) {
          // ...
      }
      

    3. 【最佳实践/逻辑结构】互斥条件未使用 else if

    • 问题描述:在判断 childBrandId 时,childBrandId 等于 shangjieBrandId 和等于 -1 是互斥的业务场景,但代码使用了两个独立的 if 语句。
    • 影响分析:虽然当前逻辑下不会产生严重 Bug,但当第一个 if 命中后,程序依然会去计算和判断第二个 if,这在语义上不够严谨,且如果后续在块内修改了被判断的变量,可能会引发意料之外的逻辑穿透。
    • 优化建议:对于互斥的条件分支,建议使用 else if 进行连接。 java if (ObjectUtil.equals(childBrandId, shangjieBrandId)) { storeValidRecommendationCount = deliveryCount.getQgShangjCount(); } else if (ObjectUtil.equals(childBrandId, OTHER_BRAND_ID)) { storeValidRecommendationCount = deliveryCount.getQgOtherCount(); }

    二、评分明细

    • 功能实现的正确性与健壮性(32/40分):扣除 8 分。主要原因是 ObjectUtil.equals(childBrandId, -1) 存在极高的类型不匹配隐患。如果 ID 是 Long 类型,该“修复”将完全失效。
    • 安全性与潜在风险(30/30分):满分。本次变更属于纯内存数据逻辑计算,不涉及 SQL 拼接、越权或外部参数直接执行,无明显安全风险。未违反“Mybatis子查询”和“Dubbo接口参数变更”的红线规则。
    • 最佳实践与可维护性(15/20分):扣除 5 分。代码中引入了魔法值 -1,且互斥逻辑未使用 else if 组织,代码存在一定的重复(坏味道),但考虑到是局部修复,未做过度扣分。
    • 性能与资源利用(5/5分):满分。简单的条件判断和赋值,无性能瓶颈或资源浪费。
    • 提交信息质量(5/5分):满分。Commit message 采用了符合规范的 fix(scope): subject 格式,且 body 部分清晰地描述了修改内容、原因和结果,可追溯性极强。

    总分:87分

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