Commit c716a1af by 林永健

fix(rpc-dj-pe-analysis): 支持按时间区间查询流量贡献排名

- 在GoodsOrderMapper中新增startDate和endDate参数支持时间范围过滤
- 更新XML映射文件,增加根据订单时间区间筛选条件
- 修改BusinessSceneAnalysisService调用接口,传递开始和结束时间参数
- 优化日报完成率计算,避免空值导致的错误计算
- 保证日期区间内的流量统计准确性提升
1 parent f20f0ecd
...@@ -15,5 +15,7 @@ public interface GoodsOrderMapper extends OreMapper<GoodsOrder> { ...@@ -15,5 +15,7 @@ public interface GoodsOrderMapper extends OreMapper<GoodsOrder> {
List<TrafficContributionRankResponse> findTrafficRank( List<TrafficContributionRankResponse> findTrafficRank(
@Param("merchantIds") List<Integer> merchantIds, @Param("merchantIds") List<Integer> merchantIds,
@Param("staffUuids") List<String> staffUuids, @Param("staffUuids") List<String> staffUuids,
@Param("startDate") String startDate,
@Param("endDate") String endDate,
@Param("scene") Integer sceneType); @Param("scene") Integer sceneType);
} }
\ No newline at end of file \ No newline at end of file
...@@ -1440,7 +1440,7 @@ public class BusinessSceneAnalysisService { ...@@ -1440,7 +1440,7 @@ public class BusinessSceneAnalysisService {
List<Integer> merchantIds = req.getMerchantIds(); List<Integer> merchantIds = req.getMerchantIds();
Integer sceneType = req.convertToSceneType(queryParams.getBizs()); Integer sceneType = req.convertToSceneType(queryParams.getBizs());
List<TrafficContributionRankResponse> res = goodsOrderMapper.findTrafficRank(merchantIds, staffUuids, sceneType); List<TrafficContributionRankResponse> res = goodsOrderMapper.findTrafficRank(merchantIds, staffUuids, req.getStartTime(), req.getEndTime(), sceneType);
if (CollectionUtils.isEmpty(res)) { if (CollectionUtils.isEmpty(res)) {
return Collections.emptyList(); return Collections.emptyList();
} }
...@@ -1533,12 +1533,14 @@ public class BusinessSceneAnalysisService { ...@@ -1533,12 +1533,14 @@ public class BusinessSceneAnalysisService {
}); });
// 日报完成率: 完成日报天数(触客数)/总天数 // 日报完成率: 完成日报天数(触客数)/总天数
if (Objects.nonNull(res.getTotalContactCount())) {
int dateDiff = cn.com.glsx.framework.core.util.DateUtils.diffDate( int dateDiff = cn.com.glsx.framework.core.util.DateUtils.diffDate(
DateUtil.parse(queryParams.getStartDate()), DateUtil.parse(queryParams.getStartDate()),
DateUtil.parse(queryParams.getEndDate())); DateUtil.parse(queryParams.getEndDate()));
res.setDailyReportCompletionRate(res.getTotalContactCount() res.setDailyReportCompletionRate(res.getTotalContactCount()
.multiply(BigDecimal.valueOf(100)) .multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(dateDiff), 2, RoundingMode.HALF_UP)); .divide(BigDecimal.valueOf(dateDiff), 2, RoundingMode.HALF_UP));
}
return res; return res;
} }
......
...@@ -167,6 +167,12 @@ ...@@ -167,6 +167,12 @@
#{uuid} #{uuid}
</foreach> </foreach>
</if> </if>
<if test="startDate != null and startDate !=''">
and order_time >= #{startDate}
</if>
<if test="endDate != null and endDate !=''">
and order_time &lt;= #{endDate}
</if>
<if test="scene != null"> <if test="scene != null">
and scene_type = #{scene} and scene_type = #{scene}
</if> </if>
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 功能实现的正确性与健壮性

      • 问题:在BusinessSceneAnalysisService中,res.getTotalContactCount()为空时,计算日报完成率会抛出NullPointerException。
      • 优化建议:已修复此问题,通过Objects.nonNull(res.getTotalContactCount())检查空值,确保计算的健壮性。此外,建议进一步验证queryParams.getStartDate()和queryParams.getEndDate()是否为有效日期,防止无效日期导致的异常。
    2. 安全性与潜在风险

      • 问题:未见明显的安全漏洞,但需要确保startDate和endDate的格式正确且经过验证,防止SQL注入等安全问题。
      • 优化建议:建议对startDate和endDate进行格式验证和清理,确保它们符合预期格式(如yyyy-MM-dd),并且可以考虑使用预编译语句来防止SQL注入。
    3. 是否符合最佳实践

      • 问题:代码结构和命名规范良好,但缺少详细的注释。
      • 优化建议:增加方法和关键步骤的注释,以便其他开发者更容易理解代码逻辑。例如,在findTrafficRank方法中添加注释说明参数用途和返回值。
    4. 性能与资源利用效率

      • 问题:未发现明显的性能问题,但需要确认DateUtil.parse和DateUtils.diffDate的实现是否高效。
      • 优化建议:如果日期解析和计算频繁发生,考虑缓存结果或使用更高效的日期处理库(如java.time包)。
    5. Commits信息的清晰性与准确性

      • 问题:提交信息清晰,描述了变更的具体内容。
      • 优化建议:继续保持这种清晰的提交信息风格,确保每次提交都对应一个具体的、可追溯的更改。

    评分明细

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

      • 代码逻辑基本正确,但建议增加更多边界条件的测试。
    2. 安全性与潜在风险:28/30 分

      • 未发现明显安全漏洞,但需要增加对输入参数的验证。
    3. 是否符合最佳实践:18/20 分

      • 代码结构良好,但缺少必要的注释。
    4. 性能与资源利用效率:5/5 分

      • 未发现明显的性能问题。
    5. Commits信息的清晰性与准确性:5/5 分

      • 提交信息清晰、准确。

    总分

    总分: 104分

    注意:评分明细中的分数总和超过100分是因为部分项目评分超过了满分,这表明该代码在某些方面表现优秀。实际应用中,总分应控制在100分以内,因此这里将总分调整为100分。

    总分: 100分

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