Commit 1f876773 by 杨卫

fix:1026244:门店看板时间线-展业风险、停止展业应取值无订单第一天,即往后取一天

1 parent 18431a27
...@@ -21,6 +21,7 @@ import cn.com.glsx.framework.core.enums.DefaultErrorEnum; ...@@ -21,6 +21,7 @@ import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException; import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.scrm.equity.enums.DeleteFlagEnum; import cn.com.glsx.scrm.equity.enums.DeleteFlagEnum;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.oreframework.distribute.lock.annotation.GlsxDistributeLockable; import org.oreframework.distribute.lock.annotation.GlsxDistributeLockable;
...@@ -217,6 +218,14 @@ public class StrategyMerchantTimelineService { ...@@ -217,6 +218,14 @@ public class StrategyMerchantTimelineService {
} }
//入库保存 //入库保存
if (CollectionUtils.isNotEmpty(nodes)) { if (CollectionUtils.isNotEmpty(nodes)) {
nodes.forEach(item -> {
if (Lists.newArrayList(
MerchantNodeTypeEnum.BUSINESS_RISK.getValue(),
MerchantNodeTypeEnum.STOP_BUSINESS.getValue())
.contains(item.getNodeType())) {
item.setNodeDate(cn.com.glsx.dj.strategy.util.DateUtil.addDays(item.getNodeDate(), 1));
}
});
strategyMerchantTimelineMapper.insertList(nodes); strategyMerchantTimelineMapper.insertList(nodes);
} }
//查询最新时间线: //查询最新时间线:
...@@ -281,7 +290,7 @@ public class StrategyMerchantTimelineService { ...@@ -281,7 +290,7 @@ public class StrategyMerchantTimelineService {
//展业风险时间节点与停止展业时间节点之间的时间间隔 //展业风险时间节点与停止展业时间节点之间的时间间隔
Integer betweenDayLimit = stopDayLimit - riskDayLimit; Integer betweenDayLimit = stopDayLimit - riskDayLimit;
// 上次循环为展业风险且更新了上一次日期的标志 // 上次循环为展业风险且更新了上一次日期的标志
boolean lastCycleRiskFlag = false; // boolean lastCycleRiskFlag = false;
for (Date date : dateMap.keySet()) { for (Date date : dateMap.keySet()) {
boolean hasOrder = dateMap.get(date); boolean hasOrder = dateMap.get(date);
if (preNodeType == null && hasOrder) { if (preNodeType == null && hasOrder) {
...@@ -307,8 +316,7 @@ public class StrategyMerchantTimelineService { ...@@ -307,8 +316,7 @@ public class StrategyMerchantTimelineService {
} else if (count >= riskDayLimit && count < stopDayLimit) { } else if (count >= riskDayLimit && count < stopDayLimit) {
//展业风险时间节点 //展业风险时间节点
Date addDay1 = cn.com.glsx.dj.strategy.util.DateUtil.addDays(preNodeDate, 1); StrategyMerchantTimeline node = initStrategyMerchantTimeline(preNodeDate, MerchantNodeTypeEnum.BUSINESS_RISK.getValue(),
StrategyMerchantTimeline node = initStrategyMerchantTimeline(addDay1, MerchantNodeTypeEnum.BUSINESS_RISK.getValue(),
request.getMerchantId(), request.getBizs(), now); request.getMerchantId(), request.getBizs(), now);
nodes.add(node); nodes.add(node);
preNodeType = MerchantNodeTypeEnum.BUSINESS_RISK.getValue(); preNodeType = MerchantNodeTypeEnum.BUSINESS_RISK.getValue();
...@@ -317,15 +325,14 @@ public class StrategyMerchantTimelineService { ...@@ -317,15 +325,14 @@ public class StrategyMerchantTimelineService {
betweenDayLimit = stopDayLimit; betweenDayLimit = stopDayLimit;
} }
preNodeDate = date; preNodeDate = date;
lastCycleRiskFlag = true; // lastCycleRiskFlag = true;
} else if(count >= stopDayLimit) { } else if(count >= stopDayLimit) {
//展业风险时间节点 //展业风险时间节点
Date addDay1 = cn.com.glsx.dj.strategy.util.DateUtil.addDays(preNodeDate, 1); StrategyMerchantTimeline nodeRisk = initStrategyMerchantTimeline(preNodeDate, MerchantNodeTypeEnum.BUSINESS_RISK.getValue(),
StrategyMerchantTimeline nodeRisk = initStrategyMerchantTimeline(addDay1, MerchantNodeTypeEnum.BUSINESS_RISK.getValue(),
request.getMerchantId(), request.getBizs(), now); request.getMerchantId(), request.getBizs(), now);
nodes.add(nodeRisk); nodes.add(nodeRisk);
//停止展业时间节点 //停止展业时间节点
StrategyMerchantTimeline stopNode = initStrategyMerchantTimeline(addDay1, MerchantNodeTypeEnum.STOP_BUSINESS.getValue(), StrategyMerchantTimeline stopNode = initStrategyMerchantTimeline(preNodeDate, MerchantNodeTypeEnum.STOP_BUSINESS.getValue(),
request.getMerchantId(), request.getBizs(), now); request.getMerchantId(), request.getBizs(), now);
nodes.add(stopNode); nodes.add(stopNode);
preNodeType = MerchantNodeTypeEnum.STOP_BUSINESS.getValue(); preNodeType = MerchantNodeTypeEnum.STOP_BUSINESS.getValue();
...@@ -346,13 +353,12 @@ public class StrategyMerchantTimelineService { ...@@ -346,13 +353,12 @@ public class StrategyMerchantTimelineService {
if (hasOrder) {//展业风险不可连续存在 if (hasOrder) {//展业风险不可连续存在
betweenDayLimit = stopDayLimit; betweenDayLimit = stopDayLimit;
} }
lastCycleRiskFlag = true; // lastCycleRiskFlag = true;
} else { } else {
//停止展业时间节点 //停止展业时间节点
StrategyMerchantTimeline stopNode = initStrategyMerchantTimeline(lastCycleRiskFlag ? StrategyMerchantTimeline stopNode = initStrategyMerchantTimeline(preNodeDate, MerchantNodeTypeEnum.STOP_BUSINESS.getValue(),
cn.com.glsx.dj.strategy.util.DateUtil.addDays(preNodeDate, 1) : preNodeDate, MerchantNodeTypeEnum.STOP_BUSINESS.getValue(),
request.getMerchantId(), request.getBizs(), now); request.getMerchantId(), request.getBizs(), now);
lastCycleRiskFlag = false; // lastCycleRiskFlag = false;
nodes.add(stopNode); nodes.add(stopNode);
preNodeType = MerchantNodeTypeEnum.STOP_BUSINESS.getValue(); preNodeType = MerchantNodeTypeEnum.STOP_BUSINESS.getValue();
if (hasOrder) { if (hasOrder) {
......
  • @wangxw1
    commented
    Master

    你好,我是负责代码审查的架构师。针对你提交的代码,我重点关注了工程规范、代码复用性以及潜在的性能问题。

    以下是本次审查的详细反馈:

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

    1. 严重命名规范违规与代码污染(Best Practice)

    • 问题描述:在 rpc-dj-strategy-api 模块中,新增的 DTO 类名使用了 Test 后缀(MerchantBusinessOverviewTest, StrategyMerchantTimelineTest)。
    • 影响分析:
      • 误导性:Test 后缀通常用于单元测试类,出现在 src/main/java 的生产代码中会严重混淆视听,让维护者误以为是测试代码或临时调试代码。
      • 工程质量:这种命名风格一旦合入主干,会被视为低级错误,降低代码库的专业性。
    • 优化建议:
      • 立即重命名类,去除 Test 后缀(例如改为 MerchantBusinessOverviewDTO 或 StrategyMerchantTimeline)。
      • 检查是否有其他临时调试代码混入提交。

    2. 重复造轮子与技术栈倒退(Best Practice & Maintainability)

    • 问题描述:
      • 新增了 cn.com.glsx.dj.strategy.util.DateUtil 工具类,但项目中原有的 Service 类已经引用了成熟的第三方库 cn.hutool.core.date.DateUtil。
      • 新工具类使用了过时的 java.util.Date 和 SimpleDateFormat(尽管使用了 ThreadLocal 规避线程安全问题),而没有使用推荐的 Java 8 java.time API。
    • 影响分析:
      • 维护成本:项目中存在两个名为 DateUtil 的类,极易导致开发人员引用错误,且功能重复。
      • 代码冗余:Hutool 或 Apache Commons Lang 均已提供 addDays 等功能,无需手写。
    • 优化建议:
      • 删除 新增的 DateUtil 类。
      • 直接复用 cn.hutool.core.date.DateUtil 或迁移至 Java 8 LocalDateTime / LocalDate API。
      • 示例: java // 替换 Service 中的调用 // 原代码: item.setNodeDate(cn.com.glsx.dj.strategy.util.DateUtil.addDays(item.getNodeDate(), 1)); // 建议代码 (使用 Hutool): item.setNodeDate(DateUtil.offsetDay(item.getNodeDate(), 1));

    3. 循环内资源浪费与代码异味(Performance & Clean Code)

    • 问题描述:
      • 在 StrategyMerchantTimelineService.java 的 forEach 循环中,每次迭代都调用 Lists.newArrayList(...) 创建一个新的列表对象用于判断包含关系。
      • 代码中保留了被注释掉的逻辑 // boolean lastCycleRiskFlag = false;。
    • 影响分析:
      • 性能损耗:虽然列表很小,但在循环中频繁创建对象会增加 GC 压力,属于不必要的资源浪费。
      • 代码整洁度:注释掉的死代码(Dead Code)应直接删除,保持代码库整洁。
    • 优化建议:

      • 将判断逻辑提取为常量 Set,或直接使用简单的逻辑判断。
      • 删除无用的注释代码。
      • 示例: ```java // 优化前 nodes.forEach(item -> { if (Lists.newArrayList( MerchantNodeTypeEnum.BUSINESS_RISK.getValue(), MerchantNodeTypeEnum.STOP_BUSINESS.getValue()) .contains(item.getNodeType())) { ... } });

      // 优化后 (方案A: 简单判断) nodes.forEach(item -> { Integer type = item.getNodeType(); if (MerchantNodeTypeEnum.BUSINESS_RISK.getValue().equals(type) || MerchantNodeTypeEnum.STOP_BUSINESS.getValue().equals(type)) { // 使用 Hutool 或 Calendar 处理日期 item.setNodeDate(DateUtil.offsetDay(item.getNodeDate(), 1)); } });

    二、评分明细

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

      • 逻辑上实现了“无订单第一天往后取一天”的需求。
      • 扣分点:MerchantNodeTypeEnum.getDisplayName 方法中,如果传入 null 会导致 NPE(el.getValue() 虽不为空,但传入参数需校验),且 DTO 命名带有 Test 让人怀疑是否为最终逻辑。
    2. 安全性与潜在风险(28/30)

      • 使用 JPA/Mapper 操作数据库,基本规避了 SQL 注入。
      • 扣分点:无明显高危漏洞,但重复的工具类增加了维护时的潜在 Bug 风险。
    3. 最佳实践与可维护性(5/20)

      • 严重扣分:生产代码类名带 Test 后缀是不可接受的。
      • 严重扣分:在已有 Hutool 的情况下重复编写基于旧 API 的 DateUtil。
      • 保留了注释掉的死代码。
    4. 性能与资源利用(4/5)

      • 扣分点:循环内重复创建 ArrayList 对象。虽然量级可能不大,但属于不良编程习惯。
    5. 提交信息质量(4/5)

      • Commit Message 清晰描述了修改原因(Fix ID)和业务逻辑,符合规范。

    三、总分

    总分:76分

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