Commit 4f8c97d1 by 叶立庆

Merge remote-tracking branch 'origin/v5.5.0' into v5.5.0

2 parents ce21faa4 aeafbc04
...@@ -267,18 +267,22 @@ public class LearningCenterCourseService { ...@@ -267,18 +267,22 @@ public class LearningCenterCourseService {
//计算累计学习时长 //计算累计学习时长
BigDecimal studyDuration = beiSenLearnStaffProgressDailyMapper.sumStudyDuration(userId, null, null); BigDecimal studyDuration = beiSenLearnStaffProgressDailyMapper.sumStudyDuration(userId, null, null);
if (studyDuration != null) {
//将学习时长:单位秒 转 小时,四舍五入保留1位小数 //将学习时长:单位秒 转 小时,四舍五入保留1位小数
BigDecimal totalHour = studyDuration.divide(new BigDecimal(60 * 60), 1, RoundingMode.HALF_UP); BigDecimal totalHour = studyDuration.divide(new BigDecimal(60 * 60), 1, RoundingMode.HALF_UP);
res.setTotalHour(totalHour); res.setTotalHour(totalHour);
}
//获取当前时间 //获取当前时间
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
//计算当前时间本月的时间范围, 格式:yyyy-MM-dd HH:mm:ss //计算当前时间本月的时间范围, 格式:yyyy-MM-dd HH:mm:ss
Date startOfMonthDate = DateUtil.getMonthFirstDay(now); Date startOfMonthDate = DateUtil.getMonthFirstDay(now);
Date endOfMonthDate = DateUtil.getMonthEndDay(now); Date endOfMonthDate = DateUtil.getMonthEndDay(now);
BigDecimal monthDuration = beiSenLearnStaffProgressDailyMapper.sumStudyDuration(userId, startOfMonthDate, endOfMonthDate); BigDecimal monthDuration = beiSenLearnStaffProgressDailyMapper.sumStudyDuration(userId, startOfMonthDate, endOfMonthDate);
if (monthDuration != null) {
//将学习时长:单位秒 转 小时,四舍五入保留1位小数 //将学习时长:单位秒 转 小时,四舍五入保留1位小数
BigDecimal monHour = monthDuration.divide(new BigDecimal(60 * 60), 1, RoundingMode.HALF_UP); BigDecimal monHour = monthDuration.divide(new BigDecimal(60 * 60), 1, RoundingMode.HALF_UP);
res.setMonHour(monHour); res.setMonHour(monHour);
}
// 计算当前时间 上月时间范围 // 计算当前时间 上月时间范围
Date startOfLastMonthDate = DateUtil.getPreMonthFirstDay(now); Date startOfLastMonthDate = DateUtil.getPreMonthFirstDay(now);
Date endOfLastMonthDate = DateUtil.getPreMonthEndDay(now); Date endOfLastMonthDate = DateUtil.getPreMonthEndDay(now);
...@@ -287,20 +291,26 @@ public class LearningCenterCourseService { ...@@ -287,20 +291,26 @@ public class LearningCenterCourseService {
Date startOfWeekDate = DateUtil.getWeekFirstDay(now); Date startOfWeekDate = DateUtil.getWeekFirstDay(now);
Date endOfWeekDate = DateUtil.getWeekEndDay(now); Date endOfWeekDate = DateUtil.getWeekEndDay(now);
BigDecimal weekDuration = beiSenLearnStaffProgressDailyMapper.sumStudyDuration(userId, startOfWeekDate, endOfWeekDate); BigDecimal weekDuration = beiSenLearnStaffProgressDailyMapper.sumStudyDuration(userId, startOfWeekDate, endOfWeekDate);
if (weekDuration != null) {
//将学习时长:单位秒 转 小时,四舍五入保留1位小数 //将学习时长:单位秒 转 小时,四舍五入保留1位小数
BigDecimal weekHour = weekDuration.divide(new BigDecimal(60 * 60), 1, RoundingMode.HALF_UP); BigDecimal weekHour = weekDuration.divide(new BigDecimal(60 * 60), 1, RoundingMode.HALF_UP);
res.setWeekHour(weekHour); res.setWeekHour(weekHour);
}
//查询我的课程未读条数 //查询我的课程未读条数
Integer unReadCount = searchUnReadCount(userId); Integer unReadCount = searchUnReadCount(userId);
res.setUnReadCount(unReadCount); res.setUnReadCount(unReadCount);
//计算本月学习时长占比 //计算本月学习时长占比
if (lastMonthDuration != null) {
if (lastMonthDuration.compareTo(BigDecimal.ZERO) > 0) { if (lastMonthDuration.compareTo(BigDecimal.ZERO) > 0) {
monthDuration = monthDuration == null ? BigDecimal.ZERO : monthDuration;
//计算本月学习时长占比 = 本月学习时长 / 上月学习时长 -1 * 100%, 四舍五入保留2位小数 //计算本月学习时长占比 = 本月学习时长 / 上月学习时长 -1 * 100%, 四舍五入保留2位小数
BigDecimal monHourRatio = monthDuration.divide(lastMonthDuration, 3, RoundingMode.HALF_UP).subtract(BigDecimal.ONE).multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP); BigDecimal monHourRatio = monthDuration.divide(lastMonthDuration, 3, RoundingMode.HALF_UP).subtract(BigDecimal.ONE).multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
res.setMonHourRatio(monHourRatio); res.setMonHourRatio(monHourRatio);
} else { } else {
res.setMonHourRatio(null); res.setMonHourRatio(null);
} }
}
return res; return res;
} }
......
...@@ -228,11 +228,10 @@ public class PadLearningCenterService { ...@@ -228,11 +228,10 @@ public class PadLearningCenterService {
break; break;
} }
// 未推送培训计划,即等级考试未考 // 未推送培训计划,继续往下找
LearningCenterTrainingPlanPerson learningCenterTrainingPlanPerson = pushedPlanIdMapPerson.get(element.getPlanId()); LearningCenterTrainingPlanPerson learningCenterTrainingPlanPerson = pushedPlanIdMapPerson.get(element.getPlanId());
if (ObjectUtil.isNull(learningCenterTrainingPlanPerson)) { if (ObjectUtil.isNull(learningCenterTrainingPlanPerson)) {
result = element; continue;
break;
} }
element.setTrainingPlanPerson(learningCenterTrainingPlanPerson); element.setTrainingPlanPerson(learningCenterTrainingPlanPerson);
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<select id="sumStudyDuration" resultType="java.math.BigDecimal"> <select id="sumStudyDuration" resultType="java.math.BigDecimal">
select ifnull(sum(duration),0) select sum(duration)
from dj_beisen_learn_staff_progress_daily from dj_beisen_learn_staff_progress_daily
where deleted_flag = 'N' and staff = #{userId} where deleted_flag = 'N' and staff = #{userId}
<if test="beginDate != null"> <if test="beginDate != null">
......
package cn.com.glsx.dj.riskmanage.remote.learningcenter;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.LearningCenterLevelExamDTO;
import cn.com.glsx.dj.riskmanage.remote.BaseRemoteTest;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.hutool.json.JSONUtil;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @author yangwei
* @version 1.0
* @since 2025/12/09 15:34
*/
public class PadLearningCenterServiceTest extends BaseRemoteTest {
@Autowired
private PadLearningCenterRemoteImpl padLearningCenterService;
@Test
public void learningCenterPermissionOrder() {
LearningCenterLevelExamDTO learningCenterLevelExamDTO = new LearningCenterLevelExamDTO();
learningCenterLevelExamDTO.setStaffPhone("19144475436");
RpcResponse<Boolean> booleanRpcResponse = padLearningCenterService.learningCenterPermissionOrder(learningCenterLevelExamDTO);
System.out.println("请求结果为:" + JSONUtil.toJsonStr(booleanRpcResponse));
}
}
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 空指针检查:

      • 问题描述: 在levelExamLevel为空时,examPersonUpdate.setLevelId 和 examPersonUpdate.setLevelName 方法会抛出空指针异常。
      • 优化建议: 已通过增加if (levelExamLevel != null)来避免空指针异常,但levelExamMapper.completionIncreaseCount(levelExam.getId())在levelExamLevel为空时仍然会执行。如果这是预期行为,则无需更改;否则应考虑将其移动到if (levelExamLevel != null)内部。
    2. 日志记录:

      • 问题描述: 使用log.error记录错误信息,但没有记录完整的上下文信息。例如,在log.error("完成等级考试更新失败 id:{}", id);中,应该记录更多的上下文信息以便于调试。
      • 优化建议: 增加更多的日志信息,例如调用栈或相关的变量值,以便更好地理解错误发生的原因。
    3. 重复检查:

      • 问题描述: 在levelExamMapper.completionIncreaseCount(levelExam.getId());之后,再次检查examPersonUpdate.getLevelId()是否为null。这种检查可能会导致不必要的代码复杂性,因为levelExamMapper.completionIncreaseCount与examPersonUpdate.getLevelId()之间没有直接关系。
      • 优化建议: 如果levelExamMapper.completionIncreaseCount需要依赖于levelExamLevel的信息,那么这个检查是有意义的;否则应移除此检查,简化代码逻辑。
    4. 代码结构:

      • 问题描述: 当前代码结构在某些情况下可能不够清晰,尤其是在levelExamLevel为空的情况下,可能会有多个return语句。
      • 优化建议: 可以考虑重构代码,使其更加简洁和易于理解。例如,可以将逻辑拆分为多个方法,或者使用else语句来明确逻辑分支。

    评分明细

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

      • 得分: 30分
      • 评语: 基本实现了预期的功能,但在某些情况下可能存在空指针异常和不必要的重复检查。
    2. 安全性与潜在风险(30分):

      • 得分: 25分
      • 评语: 代码中没有明显的安全漏洞,但日志记录不够详细,可能会增加调试难度。
    3. 是否符合最佳实践(20分):

      • 得分: 15分
      • 评语: 代码结构和命名尚可,但存在一些可以改进的地方,如减少重复代码和提高日志信息的详细程度。
    4. 性能与资源利用效率(5分):

      • 得分: 5分
      • 评语: 当前代码没有明显的性能问题。
    5. Commits信息的清晰性与准确性(5分):

      • 得分: 3分
      • 评语: 提交信息不够清晰,没有详细描述具体的修改内容和原因。

    总分

    总分: 78分


    以上是针对代码的详细审查报告,希望对代码改进有所帮助。如果有任何疑问或需要进一步讨论的地方,请随时联系。

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