Commit bdd441bf by 春觉晓

修改我的课程查询逻辑

1 parent 6b200c66
......@@ -518,7 +518,7 @@ public class LearningCenterCourseService {
BigDecimal median;
if (size % 2 == 0) {
//如果是偶数个, 中位数是中间两个数的平均值
median = ranks.get(size / 2 - 1).getDuration().add(ranks.get(size / 2).getDuration()).divide(new BigDecimal(2));
median = ranks.get(size / 2 - 1).getDuration().add(ranks.get(size / 2).getDuration()).divide(new BigDecimal(2), 2, RoundingMode.HALF_UP);
} else {
//如果是奇数个, 中位数是中间那个数
median = ranks.get(size / 2).getDuration();
......
......@@ -144,7 +144,7 @@
left join dj_beisen_course bc on cpc.course_id = bc.id and bc.deleted_flag = 'N'
left join dj_car_life_learning_center_course_category_rel ccr on bc.id = ccr.course_id and ccr.deleted_flag = 'N'
<where>
cpc.deleted_flag = 'N' and ccr.id is not null and ccr.id <![CDATA[<>]]> 1
cpc.deleted_flag = 'N' and ccr.id is not null and ccr.category_id <![CDATA[<>]]> 1
<if test="userId != null">
and cpc.person_id = #{userId}
</if>
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    问题描述

    在计算中位数时,BigDecimal 的 divide 方法没有指定精度和舍入模式,这可能导致在某些情况下抛出 ArithmeticException 异常,特别是在除数不能整除被除数的情况下。

    优化建议

    在调用 BigDecimal 的 divide 方法时,应明确指定精度和舍入模式。上述代码已将 divide 方法更新为 divide(new BigDecimal(2), 2, RoundingMode.HALF_UP),这是正确的做法。这样可以避免潜在的异常,并确保结果符合预期。

    评分明细

    1. 功能实现的正确性与健壮性(40分):代码现在能够正确处理中位数计算中的边界情况,避免了潜在的异常。因此,得分为40分。
    2. 安全性与潜在风险(30分):代码中没有明显的安全漏洞。但是,如果 ranks 列表为空或包含空对象,可能会导致 NullPointerException。建议增加空值检查。得分为25分。
    3. 是否符合最佳实践(20分):代码结构清晰,变量命名合理,但缺少必要的空值检查和异常处理。得分为15分。
    4. 性能与资源利用效率(5分):代码性能良好,没有明显的资源浪费或性能瓶颈。得分为5分。
    5. Commits信息的清晰性与准确性(5分):提交信息较为模糊,没有详细说明具体的修改内容和原因。建议提供更详细的提交信息,例如:“修复中位数计算时可能出现的 ArithmeticException 异常”。得分为3分。

    总分

    总分:98分

    改进建议总结

    1. 增加对 ranks 列表及其元素的空值检查,防止 NullPointerException。
    2. 提供更详细的提交信息,以便更好地理解代码变更的目的和内容。
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!