[+]日报的生态预警门店日期处理以及流失门店的模糊查询过滤
Showing
4 changed files
with
131 additions
and
4 deletions
-
你好,我是负责本次代码审查的资深软件开发工程师。
这段代码涉及 RPC 接口的入参校验、DTO 定义以及核心业务逻辑中关于日期周期的处理。代码中存在阻断性的逻辑错误以及数据准确性隐患,需要立即修正。
以下是具体的审查报告:
一、关键问题与优化建议(Top 3)
1. 严重逻辑错误:入参校验断言反向使用(Blocker)
-
问题描述:在
BusinessAnalysisRemoteImpl.java中,对于cycleType和loginRole字段的校验使用了RpcAssert.assertIsNull。 -
影响分析:
assertIsNull的语义是“断言该值必须为 Null,否则抛出异常”。结合错误提示信息"must not ne null"(应为 be),开发者的本意显然是校验字段不能为空。当前的写法会导致所有传入了有效参数的合法请求全部被拦截报错,接口完全不可用。 -
优化建议:
- 将
assertIsNull修改为assertNotNull。 - 修正错误提示信息中的拼写错误(
ne->be)。
- 将
// 修改前 RpcAssert.assertIsNull(req.getCycleType(), DefaultErrorEnum.DATA_NULL, "cycleType must not ne null"); RpcAssert.assertIsNull(req.getLoginRole(), DefaultErrorEnum.DATA_NULL, "loginRole must not ne null"); // 修改后 RpcAssert.assertNotNull(req.getCycleType(), DefaultErrorEnum.DATA_NULL, "cycleType must not be null"); RpcAssert.assertNotNull(req.getLoginRole(), DefaultErrorEnum.DATA_NULL, "loginRole must not be null");2. 数据准确性隐患:日期格式化导致时间精度丢失(Critical)
-
问题描述:在
BusinessAnalysisService.java中,计算本周结束时间时,先构建了包含时间的LocalDateTime(sunday.atTime(23, 59, 59)),但在设置到sceneBaseReq时,使用了yyyy-MM-dd格式的formatter进行格式化。 -
影响分析:
startDateTime.format(formatter)和endDateTime.format(formatter)会丢弃时间部分。- 结束时间
2025-01-05 23:59:59格式化后变为字符串"2025-01-05"。 - 如果底层 SQL 使用字符串比较(如
BETWEEN或<=),数据库通常将"2025-01-05"解析为"2025-01-05 00:00:00"。 - 后果:这将导致周日全天的数据被遗漏,统计结果不准确。
- 结束时间
-
优化建议:
- 如果底层支持
yyyy-MM-dd HH:mm:ss格式,请定义包含时间的 Formatter。 - 或者在 Service 层直接传递
Date或LocalDateTime对象,由 DAO 层处理格式。
- 如果底层支持
// 建议修改 DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); sceneBaseReq.setStartTime(startDateTime.format(timeFormatter)); sceneBaseReq.setEndTime(endDateTime.format(timeFormatter));3. API 字段命名拼写错误与规范性(Major)
-
问题描述:
-
LostStoreDetailResponse.java中字段名为loatOrderTime,明显是lastOrderTime的拼写错误。 -
BusinessAnalysisRemoteImpl.java中错误提示must not ne null。 -
BusinessAnalysisService.java中变量tagetOutput拼写错误(应为target)。
-
-
影响分析:
- 对外暴露的 API 字段(DTO)一旦发布,客户端接入后将难以修改,永久保留这个拼写错误,极度影响接口的专业性和可维护性。
- 拼写错误会误导后续维护人员,增加理解成本。
-
优化建议:
- 使用 IDE 的拼写检查插件。
- 立即重构 DTO 字段名。
// LostStoreDetailResponse.java @ApiModelProperty(notes = "最后开单日期", example = "2025-01-02") private String lastOrderTime; // 修正 loat -> last
二、评分明细
维度 评分 理由 功能正确性 15/40 存在阻断性 Bug(校验逻辑反向),导致接口完全不可用;日期处理逻辑存在丢失数据的风险。 安全性 28/30 使用了 RpcAssert 进行防御性编程,未见明显的注入或越权风险。 最佳实践 12/20 存在多处拼写错误(API 字段、日志、错误提示);修改入参对象( request.setStartTime)产生副作用;serialVersionUID设为 -1 不符合常规。性能与资源 4/5 日期计算逻辑基本合理,无明显性能瓶颈。 提交信息 5/5 提交信息清晰,涵盖了主要变更点。 总分:64分
-
问题描述:在
-
Please register or sign in to post a comment