查询课程和修改课程学习上报进度,增加视频播放进度的处理

This commit is contained in:
sunhonglai
2025-03-31 13:14:14 +08:00
parent 87e5dd81f8
commit 5705bb8529
4 changed files with 42 additions and 10 deletions

View File

@@ -1,9 +1,14 @@
package com.xboe.school.study.api;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.nacos.shaded.com.google.common.util.concurrent.RateLimiter;
import com.xboe.api.ThirdApi;
import com.xboe.constants.CacheName;
@@ -253,6 +258,36 @@ public class StudyCourseApi extends ApiBaseController{
rs.put("progress", sc.getProgress());
//查询上次学习的是什么资源。查询用户的学习情况
List<StudyCourseItem> items=studyService.findByStudyId(sc.getId());
// 和内容匹配,根据内容的视频时长,计算学习进度
if(CollectionUtil.isNotEmpty(items) && CollectionUtil.isNotEmpty(cclist)){
// 根据ID转换map
Map<String, CourseContent> contentMap = cclist.stream().collect(Collectors.toMap(CourseContent::getId, Function.identity()));
for (StudyCourseItem item : items) {
CourseContent content = contentMap.get(item.getContentId());
if(item.getContentId().equals(content.getId())){
// 计算学习进度item.getLastStudyTime() /content.getDuration()
if(null==item.getLastStudyTime()
|| item.getLastStudyTime()<=0
|| null==content.getDuration()
|| content.getDuration()<=0){
continue;
}
BigDecimal lastStudyTime = new BigDecimal(item.getLastStudyTime());
BigDecimal duration = new BigDecimal(content.getDuration());
BigDecimal progress = lastStudyTime.divide(duration, 10, RoundingMode.HALF_UP);
// 如果progress<0则为0如果progress>1则为1
if(progress.compareTo(BigDecimal.ZERO) < 0){
progress = BigDecimal.ZERO;
}else if(progress.compareTo(BigDecimal.ONE) > 0){
progress = BigDecimal.ONE;
}
item.setProgressVideo(progress);
}
}
}
rs.put("contentStudys",items);//学习的内容
}
@@ -555,7 +590,7 @@ public class StudyCourseApi extends ApiBaseController{
}
//检查是否已存在
try {
studyService.updateLastTime(itemId,videoTime, getCurrent().getAccountId(), progressVideo);
studyService.updateLastTime(itemId,videoTime, getCurrent().getAccountId());
if (contentId != null && courseId != null && progressVideo != null){
contentService.updateProcessVideo(contentId, courseId, progressVideo);
}

View File

@@ -1,5 +1,6 @@
package com.xboe.school.study.entity;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import javax.persistence.Column;
@@ -132,7 +133,7 @@ public class StudyCourseItem extends IdEntity {
/**
* 视频播放进度
* */
@Column(name = "progress_video")
private Float progressVideo;
// @Column(name = "progress_video")
private BigDecimal progressVideo;
}

View File

@@ -38,9 +38,8 @@ public interface IStudyService {
* @param studyContentId
* @param lastStudyTime
* @param aid
* @param progressVideo
*/
void updateLastTime(String studyContentId, int lastStudyTime, String aid, Float progressVideo);
void updateLastTime(String studyContentId, int lastStudyTime, String aid);
/**
* 资源学习记录

View File

@@ -321,7 +321,7 @@ public class StudyServiceImpl implements IStudyService{
// 更新 前端传输已学习时长
@Override
@Transactional
public void updateLastTime(String studyContentId, int lastStudyTime, String aid, Float progressVideo) {
public void updateLastTime(String studyContentId, int lastStudyTime, String aid) {
// 更新最后的学习时间点
LocalDateTime now=LocalDateTime.now();
UpdateBuilder update=UpdateBuilder.from(StudyCourseItem.class);
@@ -330,9 +330,6 @@ public class StudyServiceImpl implements IStudyService{
update.addFilter(FieldFilters.lt("lastStudyTime", lastStudyTime));
update.addUpdateField("lastStudyTime", lastStudyTime);
update.addUpdateField("lastTime", now);
if(progressVideo!=null) {
update.addUpdateField("progressVideo", progressVideo);
}
scItemDao.update(update.builder());
//增加用户的学习时长,在api中调用
}