Commit 84ef268e by 杨卫

fix:预警和产值计算T-1,但策略搜索要按原时间区间进行搜索

1 parent 44e3aae6
......@@ -32,12 +32,18 @@ public class WarningRecordQueryRequest implements Serializable {
@ApiModelProperty(notes = "时间维度: W/M/LDW/LDM")
private String timeDimension;
@ApiModelProperty(notes = "开始日期 yyyy-MM-dd")
@ApiModelProperty(notes = "用于预警和产值查询,开始日期 yyyy-MM-dd")
private String startDate;
@ApiModelProperty(notes = "结束日期 yyyy-MM-dd")
@ApiModelProperty(notes = "用于预警和产值查询,结束日期 yyyy-MM-dd")
private String endDate;
@ApiModelProperty(notes = "用于普通查询开始日期 yyyy-MM-dd")
private String queryStartDate;
@ApiModelProperty(notes = "用于普通查询结束日期 yyyy-MM-dd")
private String queryEndDate;
@ApiModelProperty(notes = "项目组筛选")
private Integer groupId;
......
......@@ -535,8 +535,8 @@ public class WarningEngineRemoteImpl implements WarningEngineRemote {
filterDto.setFlyingSupervisorId(request.getFlightSupervisionId());
filterDto.setStoreName(request.getStoreName());
filterDto.setGroupId(request.getGroupId());
filterDto.setStartDate(request.getStartDate());
filterDto.setEndDate(request.getEndDate());
filterDto.setStartDate(request.getQueryStartDate());
filterDto.setEndDate(request.getQueryEndDate());
// getIntersectionMerchantIds 可能返回不可变列表(Collections.emptyList()/Arrays.asList()),
// 后续 retainAll / removeAll 需要可变集合,所以包装为 ArrayList。
......
......@@ -3,6 +3,7 @@ package cn.com.glsx.dj.strategy.service;
import cn.com.glsx.dj.strategy.BaseServiceTest;
import cn.com.glsx.dj.strategy.dto.StrategyDetailReqDTO;
import cn.com.glsx.dj.strategy.dto.StrategyDetailRespDTO;
import cn.com.glsx.dj.strategy.remote.WarningEngineRemoteImpl;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
......@@ -20,6 +21,9 @@ public class StrategyDetailServiceTest extends BaseServiceTest {
@Autowired
private StrategyDetailService strategyDetailService;
@Autowired
private WarningEngineRemoteImpl warningEngineRemote;
@Test
public void findStrategyDetailTest() {
......@@ -29,4 +33,8 @@ public class StrategyDetailServiceTest extends BaseServiceTest {
log.info("策略详情:{}", JSONUtil.toJsonStr(strategyDetail));
}
@Test
public void findWarningSummaryTest() {
log.info("warningEngineRemote.findWarningSummary: {}", JSONUtil.toJsonStr(warningEngineRemote.findWarningSummary(null)));
}
}
  • @wangxw1
    commented
    Master

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

    1. Dubbo 接口向下兼容性被破坏(严重风险,触犯重要规则)

    • 问题描述:在 WarningRecordQueryRequest 中新增了 queryStartDate 和 queryEndDate 字段,且在 WarningEngineRemoteImpl 中直接将过滤条件从原有的 startDate 切换为读取新增的 queryStartDate。这触犯了“dubbo服务提供者Remote接口中的已有请求参数变更视为危险实现”的重要规则。
    • 影响分析:如果调用该 Dubbo 接口的消费端(Consumer)没有同步升级 API 包并修改传参逻辑,它们依然只会传递 startDate 和 endDate。此时服务端接收到的 queryStartDate 将为 null,导致正常的策略搜索功能直接失效,引发生产环境的线上故障。
    • 优化建议:必须保证接口的向下兼容性。在服务端获取时间参数时,应当做兼容性处理(如果新字段为空,则降级使用老字段)。更好的设计是:不要新增多余的时间字段,而是新增一个业务标识字段(如 queryScene 或 isTMinusOne),服务端根据该标识对标准的 startDate 进行不同的内部逻辑推算。 兼容性修复示例: java // 保持兼容性的取值方式 String actualStartDate = StringUtils.isNotBlank(request.getQueryStartDate()) ? request.getQueryStartDate() : request.getStartDate(); filterDto.setStartDate(actualStartDate);

    2. DTO 设计不合理,存在字段语义重叠(最佳实践)

    • 问题描述:在同一个 Request DTO 中同时存在 startDate(用于预警和产值)和 queryStartDate(用于普通查询),这种设计非常容易引起调用者的困惑。
    • 影响分析:破坏了 API 契约的清晰性。调用方在对接接口时,无法直观判断当前场景到底应该传哪个时间字段,极易传错,增加了沟通成本和后续的维护成本。
    • 优化建议:废弃 queryStartDate 等新增字段。统一使用 startDate 和 endDate。如果“预警产值”和“普通查询”对时间的处理逻辑不同,应在 Request 中增加枚举或标识字段(如 QueryTypeEnum queryType),由 Provider 内部根据 queryType 决定如何截取或偏移时间。

    3. 单元测试用例健壮性不足(健壮性)

    • 问题描述:在 StrategyDetailServiceTest 的 findWarningSummaryTest 方法中,直接向 warningEngineRemote.findWarningSummary(null) 传入了 null 作为请求参数。
    • 影响分析:如果 Remote 实现类的第一行代码是类似 request.getGroupId() 的取值操作,该测试用例会直接抛出 NullPointerException。这暴露出接口可能缺乏对入参为空的基础校验(如 @Valid 或手动防空)。
    • 优化建议:在单元测试中应当构造真实的 Request 对象进行测试。同时,建议在 Provider 接口实现的最前端,增加对 request 对象本身的 null 值拦截与校验。

    二、评分明细

    • 1. 功能实现的正确性与健壮性(25/40分) 理由:核心逻辑的修改直接导致了 Dubbo 接口在旧版本客户端调用时功能失效(取到 null 值),健壮性存在明显缺陷。单元测试传入 null 值也未能有效验证功能的正确性。

    • 2. 安全性与潜在风险(20/30分) 理由:代码本身未引入 SQL 注入等传统安全漏洞,但 RPC 接口不兼容更新属于高危的系统可用性风险,极易引发线上生产事故。

    • 3. 最佳实践与可维护性(12/20分) 理由:在 DTO 中通过增加功能重叠的字段来区分业务场景(而不是通过增加业务类型标识),属于不良的 API 设计模式,降低了代码的可读性和可维护性。

    • 4. 性能与资源利用(5/5分) 理由:本次变更仅涉及 DTO 字段扩展和简单的 Get/Set 替换,不存在性能瓶颈或资源浪费现象。

    • 5. 提交信息质量(4/5分) 理由:Commit 信息(fix:预警和产值计算T-1,但策略搜索要按原时间区间进行搜索)清晰地说明了本次修改的业务背景和目的,具有较好的可追溯性。

    总分:66分

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