Commit 08abfccd by zhouhaibao

fix(performance): 修复业绩计算中的产值重复累加问题

- 修改 BasePerformanceDTO 中的 calculateGeneralSecondaryIndicatorsByDelivery 方法,增加类型参数
- 在方法中添加类型判断逻辑,仅在门店类型时累加权益子订单金额到产值
- 更新 StorePerformanceDTO 中对 calculateGeneralSecondaryIndicatorsByDelivery 的调用,传入门店类型参数
- 更新 SupervisorDashboardService 中对 calculateGeneralSecondaryIndicatorsByDelivery 的调用,传入督导类型参数
1 parent 51e918d2
...@@ -255,21 +255,25 @@ public class BasePerformanceDTO implements Serializable { ...@@ -255,21 +255,25 @@ public class BasePerformanceDTO implements Serializable {
/** /**
* 计算通用品牌二级指标(基于交付数计算 - 门店/督导) * 计算通用品牌二级指标(基于交付数计算 - 门店/督导)
* *
* @param deliveryCount 交付数 * @param deliveryCount 交付数
* @param type 1.督导 2.门店
*/ */
public void calculateGeneralSecondaryIndicatorsByDelivery(Integer deliveryCount) { public void calculateGeneralSecondaryIndicatorsByDelivery(Integer deliveryCount, int type) {
int delivery = deliveryCount != null ? deliveryCount : 0; int delivery = deliveryCount != null ? deliveryCount : 0;
int equityMainOrder = getEquityMainOrderCount() != null ? getEquityMainOrderCount() : 0; int equityMainOrder = getEquityMainOrderCount() != null ? getEquityMainOrderCount() : 0;
int warrantyMainOrder = getWarrantyMainOrderCount() != null ? getWarrantyMainOrderCount() : 0; int warrantyMainOrder = getWarrantyMainOrderCount() != null ? getWarrantyMainOrderCount() : 0;
int mainOrderTotal = warrantyMainOrder + equityMainOrder; int mainOrderTotal = warrantyMainOrder + equityMainOrder;
// 产值 = 原有产值 + 权益子订单金额(权益产值) // 门店的时候才累加,督导不重复累加
BigDecimal totalOutput = getTotalOutput() != null ? getTotalOutput() : BigDecimal.ZERO; if (type == 2) {
BigDecimal equitySubOrderAmount = getEquitySubOrderAmount() != null ? getEquitySubOrderAmount() : BigDecimal.ZERO; // 产值 = 原有产值 + 权益子订单金额(权益产值)
setTotalOutput(totalOutput.add(equitySubOrderAmount)); BigDecimal totalOutput = getTotalOutput() != null ? getTotalOutput() : BigDecimal.ZERO;
BigDecimal equitySubOrderAmount =
getEquitySubOrderAmount() != null ? getEquitySubOrderAmount() : BigDecimal.ZERO;
setTotalOutput(totalOutput.add(equitySubOrderAmount));
}
if (delivery > 0) { if (delivery > 0) {
setTouchConversionRate(calculateRate(mainOrderTotal, delivery)); setTouchConversionRate(calculateRate(mainOrderTotal, delivery));
setWarrantyRate(calculateRate(warrantyMainOrder, delivery)); setWarrantyRate(calculateRate(warrantyMainOrder, delivery));
......
...@@ -46,7 +46,7 @@ public class StorePerformanceDTO extends BasePerformanceDTO { ...@@ -46,7 +46,7 @@ public class StorePerformanceDTO extends BasePerformanceDTO {
if (statDimension != null && statDimension == 1) { if (statDimension != null && statDimension == 1) {
calculateHarmonySecondaryIndicatorsByDelivery(getDeliveryCount()); calculateHarmonySecondaryIndicatorsByDelivery(getDeliveryCount());
} else { } else {
calculateGeneralSecondaryIndicatorsByDelivery(getDeliveryCount()); calculateGeneralSecondaryIndicatorsByDelivery(getDeliveryCount(), 2);
} }
} }
} }
...@@ -3537,7 +3537,7 @@ public class SupervisorDashboardService { ...@@ -3537,7 +3537,7 @@ public class SupervisorDashboardService {
if (statDimension != null && statDimension == IndicatorConfig.STAT_DIMENSION_HARMONY) { if (statDimension != null && statDimension == IndicatorConfig.STAT_DIMENSION_HARMONY) {
supervisor.calculateHarmonySecondaryIndicatorsByDelivery(supervisor.getDeliveryCount()); supervisor.calculateHarmonySecondaryIndicatorsByDelivery(supervisor.getDeliveryCount());
} else { } else {
supervisor.calculateGeneralSecondaryIndicatorsByDelivery(supervisor.getDeliveryCount()); supervisor.calculateGeneralSecondaryIndicatorsByDelivery(supervisor.getDeliveryCount(),1);
} }
} }
......
  • @wangxw1
    commented
    Master

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

    1. API 模块方法签名变更导致向下兼容性破坏(重要)

    • 问题描述:在 rpc-dj-supervisor-api 这个对外暴露的 API 模块中,直接修改了 BasePerformanceDTO 的公共方法 calculateGeneralSecondaryIndicatorsByDelivery 的签名(新增了 int type 参数)。
    • 影响分析:根据代码审查重要规则,API/Remote 接口或依赖的公共 DTO 中已有请求参数或方法签名的变更属于高危操作。如果其他消费者(如 Web 端或其他微服务)依赖了旧版本的 API jar 包并调用了该方法,在部署提供者后,消费者侧会抛出 NoSuchMethodError,导致线上故障。
    • 优化建议:使用方法重载(Overload)来代替直接修改原有方法签名,保留旧方法以保证向下兼容。
    // 保留原有方法,默认兼容原有逻辑或抛出明确警告,或者默认走某种安全类型
    @Deprecated
    public void calculateGeneralSecondaryIndicatorsByDelivery(Integer deliveryCount) {
        // 视业务情况决定默认传什么,或者保持原逻辑
        this.calculateGeneralSecondaryIndicatorsByDelivery(deliveryCount, 2); 
    }
    
    // 新增重载方法
    public void calculateGeneralSecondaryIndicatorsByDelivery(Integer deliveryCount, int type) {
        // ... 新逻辑 ...
    }
    

    2. 违反面向对象设计原则(开闭原则)与强耦合

    • 问题描述:在父类 BasePerformanceDTO 中引入了 type == 2(代表门店)的具体业务判断逻辑。
    • 影响分析:父类不应该知道子类(门店、督导)的具体业务细节。这种做法导致父类与具体的业务场景强耦合。如果未来增加“大区”、“代理商”等新类型,又需要修改父类的代码,违反了开闭原则(对扩展开放,对修改封闭),降低了代码的可维护性。
    • 优化建议:不要传递身份标识(type),而是传递行为标识。或者更好的做法是将产值累加逻辑抽象出来,交由子类或 Service 层处理。如果必须在方法中加参数,建议改为布尔值 shouldAccumulateEquity,让调用方决定是否累加。
    // 建议的参数命名,描述行为而非身份
    public void calculateGeneralSecondaryIndicatorsByDelivery(Integer deliveryCount, boolean shouldAccumulateEquity) {
        // ...
        if (shouldAccumulateEquity) {
            BigDecimal totalOutput = getTotalOutput() != null ? getTotalOutput() : BigDecimal.ZERO;
            BigDecimal equitySubOrderAmount = getEquitySubOrderAmount() != null ? getEquitySubOrderAmount() : BigDecimal.ZERO;
            setTotalOutput(totalOutput.add(equitySubOrderAmount));
        }
        // ...
    }
    

    3. 魔法值(Magic Number)的使用

    • 问题描述:代码中直接使用了硬编码的数字 1 和 2 来代表督导和门店,仅通过注释进行说明。
    • 影响分析:魔法值降低了代码的可读性,且在多处调用时容易出错。如果后续人员未仔细阅读注释,极易传错参数。
    • 优化建议:如果在当前上下文中必须使用类型判断,应当定义明确的常量或枚举。
    // 在相关常量类或当前类中定义
    public static final int TYPE_SUPERVISOR = 1;
    public static final int TYPE_STORE = 2;
    
    // 调用时:
    supervisor.calculateGeneralSecondaryIndicatorsByDelivery(supervisor.getDeliveryCount(), TYPE_SUPERVISOR);
    

    二、评分明细

    • 功能实现的正确性与健壮性(32/40分): 修复了产值重复累加的核心 Bug,逻辑判断基本正确。但直接修改 API 模块中公共 DTO 的方法签名带来了向下兼容性风险,健壮性扣除 8 分。

    • 安全性与潜在风险(30/30分): 本次修改属于纯业务逻辑计算,未引入 SQL 注入、越权、XSS 等安全漏洞,满分。

    • 最佳实践与可维护性(10/20分): 父类感知子类业务场景违反了 OCP(开闭原则),且代码中出现了 1、2 等魔法值,未采用常量或行为参数化设计,不利于后续维护,扣除 10 分。

    • 性能与资源利用(5/5分): 仅增加了简单的条件判断,无复杂的循环或耗时操作,无性能瓶颈,满分。

    • 提交信息质量(5/5分): Commit Message 采用了标准格式(fix(performance): ...),清晰地描述了修改的原因、涉及的文件及具体的改动点,具有很好的可追溯性,满分。

    总分:82分

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