Commit 782d9c1f by 林永健

refactor(service): 优化门店及员工业务分析数据处理逻辑

- 统一修改日志消息,明确是门店列表指标异常提示
- 优化storeDetailSummary方法的数据处理流程,增加空数据判空和异常日志打印
- 调整指标环比字段类型为String,修正类型不一致问题
- 优化storeEmployeeRank方法中员工指标数据合并逻辑,确保完整更新empMap
- 修改各指标获取方式,统一使用Map批量查询并合并数据,减少重复调用
- 解决品类分析中aggregateType参数使用不一致问题,改为动态判断
- 统一错误日志风格,并在查询失败时返回空结果,提升健壮性
- 添加测试用例中时间范围和参数设置,完善单元测试覆盖
- 调整单车采购产值计算中参数依赖,明确逻辑判断条件
1 parent 005d716f
......@@ -19,13 +19,13 @@ public class EmployeeDetailSummaryResponse implements Serializable {
private BigDecimal totalOutputValue;
@ApiModelProperty(notes = "总产值环比")
private BigDecimal totalOutputValueMom;
private String totalOutputValueMom;
@ApiModelProperty(notes = "客单价")
private BigDecimal avgCustomerPrice;
@ApiModelProperty(notes = "客单价环比")
private BigDecimal avgCustomerPriceMom;
private String avgCustomerPriceMom;
@ApiModelProperty(notes = "日报完成率")
private BigDecimal dailyReportCompletionRate;
......@@ -34,54 +34,54 @@ public class EmployeeDetailSummaryResponse implements Serializable {
private BigDecimal preSalesContactCount;
@ApiModelProperty(notes = "售前触客数环比")
private BigDecimal preSalesContactCountMom;
private String preSalesContactCountMom;
@ApiModelProperty(notes = "售后触客数")
private BigDecimal afterSalesContactCount;
@ApiModelProperty(notes = "售后触客数环比")
private BigDecimal afterSalesContactCountMom;
private String afterSalesContactCountMom;
@ApiModelProperty(notes = "总触客数")
private BigDecimal totalContactCount;
@ApiModelProperty(notes = "总触客数环比")
private BigDecimal totalContactCountMom;
private String totalContactCountMom;
@ApiModelProperty(notes = "售前成交数")
private BigDecimal preSalesDealCount;
@ApiModelProperty(notes = "售前成交数环比")
private BigDecimal preSalesDealCountMom;
private String preSalesDealCountMom;
@ApiModelProperty(notes = "售后成交数")
private BigDecimal afterSalesDealCount;
@ApiModelProperty(notes = "售后成交数环比")
private BigDecimal afterSalesDealCountMom;
private String afterSalesDealCountMom;
@ApiModelProperty(notes = "总成交数")
private BigDecimal totalDealCount;
@ApiModelProperty(notes = "总成交数环比")
private BigDecimal totalDealCountMom;
private String totalDealCountMom;
@ApiModelProperty(notes = "售前转化率")
private BigDecimal preSalesConversionRate;
@ApiModelProperty(notes = "售前转化率环比")
private BigDecimal preSalesConversionRateMom;
private String preSalesConversionRateMom;
@ApiModelProperty(notes = "售后转化率")
private BigDecimal afterSalesConversionRate;
@ApiModelProperty(notes = "售后转化率环比")
private BigDecimal afterSalesConversionRateMom;
private String afterSalesConversionRateMom;
@ApiModelProperty(notes = "转化率")
private BigDecimal conversionRate;
@ApiModelProperty(notes = "转化率环比")
private BigDecimal conversionRateMom;
private String conversionRateMom;
}
......@@ -45,7 +45,7 @@ public class StoreDetailSummaryResponse implements Serializable {
private BigDecimal totalOutputValue;
@ApiModelProperty(notes = "总产值环比")
private BigDecimal totalOutputValueMom;
private String totalOutputValueMom;
@ApiModelProperty(notes = "目标产值(仅月周期展示)")
private BigDecimal targetOutputValue;
......@@ -57,72 +57,72 @@ public class StoreDetailSummaryResponse implements Serializable {
private BigDecimal newCarDeliveryCount;
@ApiModelProperty(notes = "新车交付数环比")
private BigDecimal newCarDeliveryCountMom;
private String newCarDeliveryCountMom;
@ApiModelProperty(notes = "售前触客数")
private BigDecimal preSalesContactCount;
@ApiModelProperty(notes = "售前触客数环比")
private BigDecimal preSalesContactCountMom;
private String preSalesContactCountMom;
@ApiModelProperty(notes = "售后触客数")
private BigDecimal afterSalesContactCount;
@ApiModelProperty(notes = "售后触客数环比")
private BigDecimal afterSalesContactCountMom;
private String afterSalesContactCountMom;
@ApiModelProperty(notes = "总触客数")
private BigDecimal totalContactCount;
@ApiModelProperty(notes = "总触客数环比")
private BigDecimal totalContactCountMom;
private String totalContactCountMom;
@ApiModelProperty(notes = "触客率")
private BigDecimal contactRate;
@ApiModelProperty(notes = "触客率环比")
private BigDecimal contactRateMom;
private String contactRateMom;
@ApiModelProperty(notes = "售前成交数")
private BigDecimal preSalesDealCount;
@ApiModelProperty(notes = "售前成交数环比")
private BigDecimal preSalesDealCountMom;
private String preSalesDealCountMom;
@ApiModelProperty(notes = "售后成交数")
private BigDecimal afterSalesDealCount;
@ApiModelProperty(notes = "售后成交数环比")
private BigDecimal afterSalesDealCountMom;
private String afterSalesDealCountMom;
@ApiModelProperty(notes = "总成交数")
private BigDecimal totalDealCount;
@ApiModelProperty(notes = "总成交数环比")
private BigDecimal totalDealCountMom;
private String totalDealCountMom;
@ApiModelProperty(notes = "售前转化率")
private BigDecimal preSalesConversionRate;
@ApiModelProperty(notes = "售前转化率环比")
private BigDecimal preSalesConversionRateMom;
private String preSalesConversionRateMom;
@ApiModelProperty(notes = "售后转化率")
private BigDecimal afterSalesConversionRate;
@ApiModelProperty(notes = "售后转化率环比")
private BigDecimal afterSalesConversionRateMom;
private String afterSalesConversionRateMom;
@ApiModelProperty(notes = "转化率")
private BigDecimal conversionRate;
@ApiModelProperty(notes = "转化率环比")
private BigDecimal conversionRateMom;
private String conversionRateMom;
@ApiModelProperty(notes = "渗透率")
private BigDecimal penetrationRate;
@ApiModelProperty(notes = "渗透率环比")
private BigDecimal penetrationRateMom;
private String penetrationRateMom;
}
......@@ -110,6 +110,11 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest {
@Test
public void storeDetailSummary() {
SceneBaseReq req = new SceneBaseReq();
req.setBizs(2);
req.setCycleType(2);
req.setStartTime("2025-02-01");
req.setEndTime("2025-11-31");
req.setMerchantIds(Lists.newArrayList());
Object res = service.storeDetailSummary(req);
System.out.println(res);
}
......@@ -117,6 +122,11 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest {
@Test
public void storeEmployeeRank() {
SceneBaseReq req = new SceneBaseReq();
req.setBizs(2);
req.setCycleType(2);
req.setStartTime("2025-02-01");
req.setEndTime("2025-11-31");
req.setMerchantIds(Lists.newArrayList());
Object res = service.storeEmployeeRank(req);
System.out.println(res);
}
......@@ -124,6 +134,11 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest {
@Test
public void storeTrafficRank() {
SceneBaseReq req = new SceneBaseReq();
req.setBizs(2);
req.setCycleType(2);
req.setStartTime("2025-02-01");
req.setEndTime("2025-11-31");
req.setStaffUuids(Lists.newArrayList());
Object res = service.storeTrafficRank(req);
System.out.println(res);
}
......@@ -131,6 +146,12 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest {
@Test
public void storeEmployeeSummary() {
SceneBaseReq req = new SceneBaseReq();
req.setBizs(2);
req.setCycleType(2);
req.setStartTime("2025-02-01");
req.setEndTime("2025-11-31");
req.setMerchantIds(Lists.newArrayList());
req.setStaffUuids(Lists.newArrayList());
Object res = service.storeEmployeeSummary(req);
System.out.println(res);
}
......@@ -138,6 +159,12 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest {
@Test
public void goodsSummary() {
SceneBaseReq req = new SceneBaseReq();
req.setBizs(2);
req.setCycleType(2);
req.setStartTime("2025-02-01");
req.setEndTime("2025-11-31");
req.setMerchantIds(Lists.newArrayList());
req.setStaffUuids(Lists.newArrayList());
Object res = service.goodsSummary(req);
System.out.println(res);
}
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 数据类型变更

    问题描述: 在 EmployeeDetailSummaryResponse.java 和 StoreDetailSummaryResponse.java 中,多个字段的数据类型从 BigDecimal 变更为 String。这种变更可能会影响数据的计算精度和一致性,尤其是在需要进行数学运算的情况下。

    影响:

    • 可能导致数据丢失或精度下降。
    • 在后续的数据处理过程中,需要将字符串转换回 BigDecimal,增加了额外的开销和复杂性。
    • 如果这些字段用于前端展示,可能会导致显示不一致的问题。

    优化建议:

    • 保持数据类型一致性:如果这些字段确实需要以字符串形式展示,可以在传输层进行转换,而不是在数据模型中直接更改类型。
    • 提供转换方法:如果必须使用 String 类型,可以提供从 BigDecimal 到 String 的转换方法,并确保在需要的地方进行正确的转换。

    2. 日志信息优化

    问题描述: 虽然日志信息进行了统一修改,但仍然存在一些不明确的地方,如 log.warn("查询门店列表指标异常. req: {}, itemCodes: {}", JSON.toJSONString(queryParams), itemCodes); 中的 查询门店列表指标异常 可能不够具体。

    影响:

    • 不够具体的日志信息可能导致排查问题时的困难。
    • 对于复杂的系统,需要更详细的日志来帮助快速定位问题。

    优化建议:

    • 详细化日志信息:在日志中添加更多的上下文信息,如方法名、调用者、关键参数等。
    • 统一日志级别:根据问题的严重程度选择合适级别的日志,避免滥用 warn 或 error 级别的日志。

    3. 数据处理逻辑优化

    问题描述: 在 BusinessSceneAnalysisService.java 中,多个地方进行了数据处理逻辑的优化,但仍然存在一些可以改进的地方,如 storeEmployeeRank 方法中的数据合并逻辑。

    影响:

    • 数据处理逻辑不够简洁,增加了理解难度。
    • 重复代码较多,增加了维护成本。

    优化建议:

    • 重构代码:将重复的代码提取到单独的方法中,提高代码的可读性和可维护性。
    • 简化逻辑:对于复杂的逻辑,可以考虑使用设计模式或算法优化,使其更加简洁高效。

    4. 单元测试优化

    问题描述: 在 BusinessSceneAnalysisServiceTest.java 中,添加了测试用例,但测试用例的覆盖范围有限,且没有验证返回结果的正确性。

    影响:

    • 单元测试覆盖率不足,无法全面验证代码的正确性。
    • 测试用例缺乏验证逻辑,可能导致潜在的 bug 没有被发现。

    优化建议:

    • 增加测试用例:覆盖更多的边界条件和异常场景。
    • 验证返回结果:确保测试用例验证返回结果的正确性,而不仅仅是调用成功。

    评分明细

    1. 功能实现的正确性与健壮性(40分):

      • 评分:25分
      • 说明:代码逻辑基本正确,但在数据类型变更和异常处理方面存在改进空间。
    2. 安全性与潜在风险(30分):

      • 评分:28分
      • 说明:代码中未发现明显的安全漏洞,但在数据类型变更和日志信息方面存在潜在风险。
    3. 是否符合最佳实践(20分):

      • 评分:15分
      • 说明:代码结构和命名规范较好,但在日志信息和代码复用方面存在改进空间。
    4. 性能与资源利用效率(5分):

      • 评分:4分
      • 说明:代码性能尚可,但在数据处理逻辑和重复代码方面存在优化机会。
    5. Commits信息的清晰性与准确性(5分):

      • 评分:4分
      • 说明:提交信息较为清晰,但可以进一步细化和详细化。

    总分

    总分:86分


    通过以上审查,建议开发者在后续开发中更加注重数据类型的正确性和一致性,优化日志信息和数据处理逻辑,同时加强单元测试的覆盖范围和验证逻辑。

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