Commit e8a420c5 by 春觉晓

优化员工学习时长统计接口

1 parent 2d04c415
......@@ -16,7 +16,7 @@ public interface LearningCenterPersonCourseMapper extends OreMapper<LearningCent
* @param personId
* @return
*/
Integer countUnReadCourse(@Param("personId") Integer personId);
Integer countUnReadCourse(@Param("personId") Integer personId, @Param("planId") Integer planId);
/**
* 未学习课程
......
......@@ -74,6 +74,9 @@ public class LearningCenterCourseService {
@Autowired
private BeiSenOrganizationService beiSenOrganizationService;
@Autowired
private PadLearningCenterService padLearningCenterService;
@Autowired
......@@ -252,10 +255,14 @@ public class LearningCenterCourseService {
}
public CourseStatisticsDTO getCourseStatistics(CourseSearchDTO request) {
CourseStatisticsDTO res = new CourseStatisticsDTO();
//根据手机号查询员工信息
BeiSenEmployeeListResonseDTO employeeInfo = getEmployeeInfoByStaffPhone(request.getStaffPhone());
if (employeeInfo == null) {
return res;
}
Integer userId = employeeInfo.getUserID();
CourseStatisticsDTO res = new CourseStatisticsDTO();
//计算累计学习时长
BigDecimal studyDuration = beiSenLearnStaffProgressDailyMapper.sumStudyDuration(userId, null, null);
//将学习时长:单位秒 转 小时,四舍五入保留1位小数
......@@ -282,7 +289,7 @@ public class LearningCenterCourseService {
BigDecimal weekHour = weekDuration.divide(new BigDecimal(60 * 60), 1, RoundingMode.HALF_UP);
res.setWeekHour(weekHour);
//查询我的课程未读条数
Integer unReadCount = learningCenterPersonCourseMapper.countUnReadCourse(userId);
Integer unReadCount = searchUnReadCount(userId);
res.setUnReadCount(unReadCount);
//计算本月学习时长占比
if (lastMonthDuration.compareTo(BigDecimal.ZERO) > 0) {
......@@ -295,6 +302,17 @@ public class LearningCenterCourseService {
return res;
}
public Integer searchUnReadCount(Integer userId) {
BeiSenEmployeeListResonseDTO employeeInfo = new BeiSenEmployeeListResonseDTO();
employeeInfo.setUserID(userId);
LearningCenterLevelExamPersonDTO userTrainingPlanStage = padLearningCenterService.getUserTrainingPlanStage(employeeInfo);
if (userTrainingPlanStage == null) {
return null;
}
Integer planId = userTrainingPlanStage.getPlanId();
return learningCenterPersonCourseMapper.countUnReadCourse(userId, planId);
}
/**
* 查询推荐课程
* @param pagination
......
......@@ -32,6 +32,18 @@
select ifnull(count(*),0)
from learning_center_person_course
where deleted_flag = 'N'and person_id = #{personId} and look_status = '0' and course_push_source = '0'
SELECT
ifnull(count(*),0)
FROM learning_center_person_course t1
JOIN dj_beisen_course t3 ON t1.course_id = t3.id
WHERE t1.course_push_source = '0'
AND t1.person_id = #{personId}
AND t1.plan_id = #{planId}
AND t3.course_status = '40'
AND t1.deleted_flag = 'N'
AND t3.deleted_flag = 'N'
AND t1.look_status = '0'
</select>
<select id="unLearnedCourses"
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. LearningCenterPersonCourseMapper.java

      • 问题: 方法 countUnReadCourse 的参数列表发生变化,增加了 planId 参数,但没有提供相应的 SQL 映射修改,可能导致运行时错误。
      • 影响: 如果没有更新对应的 XML 文件中的 SQL 语句,该方法调用会抛出 SQL 错误。
      • 优化建议: 确保在 LearningCenterPersonCourseMapper.xml 中相应的方法定义也进行了更新,添加 planId 参数。
    2. LearningCenterCourseService.java

      • 问题: 在 getCourseStatistics 方法中,CourseStatisticsDTO res 对象被实例化了两次,第一次是在方法开头,第二次是在 userId 获取之后。这会导致第一次创建的对象没有被使用。
      • 影响: 没有实际影响,但会导致不必要的对象创建,降低代码可读性。
      • 优化建议: 移除第一次的 CourseStatisticsDTO res = new CourseStatisticsDTO(); 实例化,只在 userId 获取之后实例化一次。
    3. LearningCenterCourseService.java

      • 问题: 在 searchUnReadCount 方法中,创建了一个新的 BeiSenEmployeeListResonseDTO 对象并设置了 userID,但这个对象实际上已经在 getCourseStatistics 方法中获取过了。这导致了重复的工作。
      • 影响: 无明显功能影响,但增加了不必要的对象创建和方法调用,降低性能。
      • 优化建议: 将 employeeInfo 作为参数传递给 searchUnReadCount 方法,避免重复创建对象和方法调用。
    4. Commits 信息

      • 问题: 提交信息 "优化员工学习时长统计接口" 描述不够具体,无法清楚地传达具体的更改内容。
      • 影响: 后续维护者难以快速理解此次提交的目的和内容。
      • 优化建议: 提供更详细的提交信息,例如 "添加 planId 参数到 countUnReadCourse 方法,并更新相关逻辑"。

    评分明细

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

      • 代码逻辑基本正确,但存在潜在的 SQL 错误风险,需要更新 SQL 映射文件。
      • 分数: 30/40
    2. 安全性与潜在风险(30分)

      • 未发现明显的安全漏洞,但需要确认 SQL 映射文件的更新不会引入 SQL 注入等安全问题。
      • 分数: 28/30
    3. 是否符合最佳实践(20分)

      • 代码结构合理,但存在不必要的对象创建和方法调用,可以进一步优化。
      • 分数: 15/20
    4. 性能与资源利用效率(5分)

      • 存在重复的对象创建和方法调用,可能影响性能。
      • 分数: 3/5
    5. Commits 信息的清晰性与准确性(5分)

      • 提交信息不够详细,需要改进。
      • 分数: 3/5

    总分: 79分


    总结: 代码整体逻辑清晰,但在细节上存在一些可以优化的地方,特别是 SQL 映射文件的更新、不必要的对象创建以及提交信息的清晰度。通过这些改进,可以提高代码的质量和可维护性。

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