Commit 6126cb07 by 张富康

fix(staffPerformance): 优化交车数信息日志输出格式

- 引入 JSONUtil 实现交车数日志的 JSON 格式输出
- 替换原 info 日志中交车数信息的打印方式
- 提升日志可读性,方便调试与排查问题情况
1 parent 28d41e87
...@@ -24,6 +24,7 @@ import cn.com.glsx.framework.core.exception.RpcServiceException; ...@@ -24,6 +24,7 @@ import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.util.RpcAssert; import cn.com.glsx.framework.core.util.RpcAssert;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -301,7 +302,7 @@ public class StaffPerformanceCalService { ...@@ -301,7 +302,7 @@ public class StaffPerformanceCalService {
if (storeValidRecommendationCount == 0) { if (storeValidRecommendationCount == 0) {
// 如果storeValidRecommendationCount 为 0 则需要自行查询交车数 // 如果storeValidRecommendationCount 为 0 则需要自行查询交车数
List<MerchantBrandReportDTO> deliveryCounts = effectiveReferralReviewMapper.getDeliveryCount(month, Collections.singletonList(merchantId.toString())); List<MerchantBrandReportDTO> deliveryCounts = effectiveReferralReviewMapper.getDeliveryCount(month, Collections.singletonList(merchantId.toString()));
log.info("deliveryCounts: {}", deliveryCounts); log.info("门店id:{},交车数信息:{}", merchantId, JSONUtil.toJsonStr(deliveryCounts));
if (CollUtil.isNotEmpty(deliveryCounts)) { if (CollUtil.isNotEmpty(deliveryCounts)) {
MerchantBrandReportDTO deliveryCount = CollUtil.getFirst(deliveryCounts); MerchantBrandReportDTO deliveryCount = CollUtil.getFirst(deliveryCounts);
// 判断对应的品牌获取对应的交车数 // 判断对应的品牌获取对应的交车数
......
  • @wangxw1
    commented
    Master

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

    1. 混合使用不同的 JSON 序列化组件(最佳实践与可维护性)

    • 问题描述:当前类中已经引入了 com.alibaba.fastjson.JSONArray 和 JSONObject,说明该类或项目主要使用 Fastjson 处理 JSON 数据。但本次提交引入了 cn.hutool.json.JSONUtil 来进行序列化。
    • 影响分析:在同一个类中混合使用不同的 JSON 处理库(Fastjson 与 Hutool JSON),违背了工程中技术栈统一的最佳实践。这不仅增加了代码的认知负担,还可能因为不同库的序列化底层实现差异(如对时间格式、空值、泛型的处理)导致难以排查的隐蔽 Bug。
    • 优化建议:移除对 Hutool 的 JSONUtil 依赖,直接使用已有的 Fastjson 进行序列化。

    2. 日志打印存在性能隐患(性能与资源利用)

    • 问题描述:在 log.info("...", merchantId, JSONUtil.toJsonStr(deliveryCounts)) 中,JSONUtil.toJsonStr() 方法会在日志方法被调用前无条件执行。
    • 影响分析:如果生产环境动态调整日志级别为 WARN 或 ERROR,该条 INFO 日志虽然最终不会被打印,但 deliveryCounts 转换为 JSON 字符串的 CPU 计算和内存分配开销依然会发生,造成不必要的资源浪费。
    • 优化建议:对于包含对象序列化等高开销操作的日志打印,建议先判断日志级别,或者使用 Supplier 延迟计算(如果日志框架支持)。

    代码优化示例:

    // 移除 cn.hutool.json.JSONUtil 的 import,引入 com.alibaba.fastjson.JSON
    
    // 优化后的日志打印:
    if (log.isInfoEnabled()) {
        log.info("门店id:{},交车数信息:{}", merchantId, JSON.toJSONString(deliveryCounts));
    }
    

    二、评分明细

    • 功能实现的正确性与健壮性(40 / 40分) 理由:本次修改仅涉及日志格式的调整,未改变原有核心业务逻辑。序列化操作对常规的 List 集合不会引发异常,功能实现正确。未触及 MyBatis 子查询或 Dubbo 接口变更等高危项。

    • 安全性与潜在风险(30 / 30分) 理由:仅为内部数据的日志打印,不涉及外部输入直接拼接 SQL,无 SQL 注入、XSS、越权等安全风险。假设 deliveryCounts 不包含极度敏感的用户隐私(如脱敏要求),则无敏感信息泄露风险。

    • 最佳实践与可维护性(15 / 20分) 理由:扣除 5 分。主要原因是引入了冗余的第三方工具类,导致单个类中出现多套 JSON 处理方案,降低了代码的规范性和可维护性。

    • 性能与资源利用(3 / 5分) 理由:扣除 2 分。日志打印中的无条件 JSON 序列化在对象较大或并发较高时,会产生无意义的性能损耗和 GC 压力。

    • 提交信息质量(5 / 5分) 理由:Commit 信息符合业界主流规范(fix(scope): subject 格式),清晰说明了修改内容(引入 JSONUtil)、修改点(替换 info 日志)以及修改目的(提升可读性),具备良好的可追溯性。

    总分:93分

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