Commit bc851429 by 春觉晓

修改学习时长统计时间范围

1 parent 4f8c97d1
...@@ -258,13 +258,13 @@ public class LearningCenterCourseService { ...@@ -258,13 +258,13 @@ public class LearningCenterCourseService {
public CourseStatisticsDTO getCourseStatistics(CourseSearchDTO request) { public CourseStatisticsDTO getCourseStatistics(CourseSearchDTO request) {
CourseStatisticsDTO res = new CourseStatisticsDTO(); CourseStatisticsDTO res = new CourseStatisticsDTO();
//根据手机号查询员工信息 // //根据手机号查询员工信息
BeiSenEmployeeListResonseDTO employeeInfo = getEmployeeInfoByStaffPhone(request.getStaffPhone()); // BeiSenEmployeeListResonseDTO employeeInfo = getEmployeeInfoByStaffPhone(request.getStaffPhone());
if (employeeInfo == null) { // if (employeeInfo == null) {
return res; // return res;
} // }
Integer userId = employeeInfo.getUserID(); // Integer userId = employeeInfo.getUserID();
Integer userId = request.getUserId();
//计算累计学习时长 //计算累计学习时长
BigDecimal studyDuration = beiSenLearnStaffProgressDailyMapper.sumStudyDuration(userId, null, null); BigDecimal studyDuration = beiSenLearnStaffProgressDailyMapper.sumStudyDuration(userId, null, null);
if (studyDuration != null) { if (studyDuration != null) {
......
...@@ -261,7 +261,7 @@ public class DateUtil { ...@@ -261,7 +261,7 @@ public class DateUtil {
* @return * @return
*/ */
public static Date getMonthFirstDay(LocalDateTime now) { public static Date getMonthFirstDay(LocalDateTime now) {
LocalDateTime startOfMonth = now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0); LocalDateTime startOfMonth = now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
return Date.from(startOfMonth.atZone(ZoneId.systemDefault()).toInstant()); return Date.from(startOfMonth.atZone(ZoneId.systemDefault()).toInstant());
} }
...@@ -271,7 +271,7 @@ public class DateUtil { ...@@ -271,7 +271,7 @@ public class DateUtil {
* @return * @return
*/ */
public static Date getPreMonthFirstDay(LocalDateTime now) { public static Date getPreMonthFirstDay(LocalDateTime now) {
LocalDateTime startOfMonth = now.minusMonths(1).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0); LocalDateTime startOfMonth = now.minusMonths(1).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
return Date.from(startOfMonth.atZone(ZoneId.systemDefault()).toInstant()); return Date.from(startOfMonth.atZone(ZoneId.systemDefault()).toInstant());
} }
...@@ -282,7 +282,7 @@ public class DateUtil { ...@@ -282,7 +282,7 @@ public class DateUtil {
*/ */
public static Date getMonthEndDay(LocalDateTime now) { public static Date getMonthEndDay(LocalDateTime now) {
//计算本月最后一天 //计算本月最后一天
LocalDateTime endOfMonth = now.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59); LocalDateTime endOfMonth = now.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59).withNano(0);
return Date.from(endOfMonth.atZone(ZoneId.systemDefault()).toInstant()); return Date.from(endOfMonth.atZone(ZoneId.systemDefault()).toInstant());
} }
...@@ -293,7 +293,7 @@ public class DateUtil { ...@@ -293,7 +293,7 @@ public class DateUtil {
*/ */
public static Date getPreMonthEndDay(LocalDateTime now) { public static Date getPreMonthEndDay(LocalDateTime now) {
//计算本月最后一天 //计算本月最后一天
LocalDateTime endOfMonth = now.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59); LocalDateTime endOfMonth = now.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59).withNano(0);
return Date.from(endOfMonth.atZone(ZoneId.systemDefault()).toInstant()); return Date.from(endOfMonth.atZone(ZoneId.systemDefault()).toInstant());
} }
...@@ -303,7 +303,8 @@ public class DateUtil { ...@@ -303,7 +303,8 @@ public class DateUtil {
* @return * @return
*/ */
public static Date getWeekFirstDay(LocalDateTime now) { public static Date getWeekFirstDay(LocalDateTime now) {
LocalDateTime startOfWeek = now.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).withHour(0).withMinute(0).withSecond(0); LocalDateTime startOfWeek = now.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).withHour(0).withMinute(0).withSecond(0).withNano(0);
//转为date, 时分秒不对
return Date.from(startOfWeek.atZone(ZoneId.systemDefault()).toInstant()); return Date.from(startOfWeek.atZone(ZoneId.systemDefault()).toInstant());
} }
...@@ -313,7 +314,7 @@ public class DateUtil { ...@@ -313,7 +314,7 @@ public class DateUtil {
* @return * @return
*/ */
public static Date getWeekEndDay(LocalDateTime now) { public static Date getWeekEndDay(LocalDateTime now) {
LocalDateTime endOfWeek = now.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)).withHour(23).withMinute(59).withSecond(59); LocalDateTime endOfWeek = now.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)).withHour(23).withMinute(59).withSecond(59).withNano(0);
return Date.from(endOfWeek.atZone(ZoneId.systemDefault()).toInstant()); return Date.from(endOfWeek.atZone(ZoneId.systemDefault()).toInstant());
} }
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. LearningCenterCourseService.java 修改

    问题描述: 在 LearningCenterCourseService.java 文件中,原始代码通过员工手机号查询员工信息,然后获取用户ID来计算学习时长。但这段代码被注释掉了,取而代之的是直接从请求对象中获取用户ID (Integer userId = request.getUserId();)。

    优化建议:

    • 如果新的实现方式是正确的,并且不需要依赖员工手机号查询用户信息,则可以保留这种更改。但需要确保 request.getUserId() 的值是可靠的,即前端传递过来的用户ID是经过验证的。
    • 如果仍然需要通过手机号查询用户信息,应取消注释相关代码,并确保 getEmployeeInfoByStaffPhone 方法的健壮性,防止空指针异常。
    • 添加日志记录以跟踪用户ID的来源,以便调试和审计。

    2. DateUtil.java 修改

    问题描述: 在 DateUtil.java 文件中,多个方法中 LocalDateTime 对象被转换为 Date 对象之前,添加了 .withNano(0) 操作,目的是消除纳秒部分。

    优化建议:

    • 这种做法是合理的,因为 java.util.Date 类不支持纳秒精度,这有助于避免不必要的精度损失。
    • 但是,在 getWeekFirstDay 方法中添加了注释“转为date, 时分秒不对”,这表明可能存在潜在的问题。需要确认该方法的预期行为是否正确,或者是否有其他逻辑错误导致时分秒不正确。
    • 增加单元测试以验证这些日期转换方法的正确性。

    评分明细

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

      • 代码逻辑基本正确,但需要进一步确认 request.getUserId() 的可靠性和 getWeekFirstDay 方法的行为。
      • 评分:35分
    2. 安全性与潜在风险(30分)

      • 未发现明显的安全漏洞。
      • 评分:30分
    3. 是否符合最佳实践(20分)

      • 代码注释不够详细,特别是在 getWeekFirstDay 方法中。
      • 评分:15分
    4. 性能与资源利用效率(5分)

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

      • 提交信息不够详细,仅描述了“修改学习时长统计时间范围”,未能明确指出具体修改内容。
      • 评分:3分

    总分: 93分

    备注:

    • 总分计算公式:35(功能) + 30(安全) + 15(最佳实践) + 5(性能) + 3(提交信息) = 93分

    请开发者根据上述建议进行相应的调整和完善。

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