mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-11 03:46:50 +08:00
查询课程和修改课程学习上报进度,增加视频播放进度的处理
This commit is contained in:
@@ -1,9 +1,14 @@
|
|||||||
package com.xboe.school.study.api;
|
package com.xboe.school.study.api;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
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.alibaba.nacos.shaded.com.google.common.util.concurrent.RateLimiter;
|
||||||
import com.xboe.api.ThirdApi;
|
import com.xboe.api.ThirdApi;
|
||||||
import com.xboe.constants.CacheName;
|
import com.xboe.constants.CacheName;
|
||||||
@@ -253,6 +258,36 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
rs.put("progress", sc.getProgress());
|
rs.put("progress", sc.getProgress());
|
||||||
//查询上次学习的是什么资源。查询用户的学习情况
|
//查询上次学习的是什么资源。查询用户的学习情况
|
||||||
List<StudyCourseItem> items=studyService.findByStudyId(sc.getId());
|
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);//学习的内容
|
rs.put("contentStudys",items);//学习的内容
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,7 +590,7 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
}
|
}
|
||||||
//检查是否已存在
|
//检查是否已存在
|
||||||
try {
|
try {
|
||||||
studyService.updateLastTime(itemId,videoTime, getCurrent().getAccountId(), progressVideo);
|
studyService.updateLastTime(itemId,videoTime, getCurrent().getAccountId());
|
||||||
if (contentId != null && courseId != null && progressVideo != null){
|
if (contentId != null && courseId != null && progressVideo != null){
|
||||||
contentService.updateProcessVideo(contentId, courseId, progressVideo);
|
contentService.updateProcessVideo(contentId, courseId, progressVideo);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xboe.school.study.entity;
|
package com.xboe.school.study.entity;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
@@ -132,7 +133,7 @@ public class StudyCourseItem extends IdEntity {
|
|||||||
/**
|
/**
|
||||||
* 视频播放进度
|
* 视频播放进度
|
||||||
* */
|
* */
|
||||||
@Column(name = "progress_video")
|
// @Column(name = "progress_video")
|
||||||
private Float progressVideo;
|
private BigDecimal progressVideo;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,9 +38,8 @@ public interface IStudyService {
|
|||||||
* @param studyContentId
|
* @param studyContentId
|
||||||
* @param lastStudyTime
|
* @param lastStudyTime
|
||||||
* @param aid
|
* @param aid
|
||||||
* @param progressVideo
|
|
||||||
*/
|
*/
|
||||||
void updateLastTime(String studyContentId, int lastStudyTime, String aid, Float progressVideo);
|
void updateLastTime(String studyContentId, int lastStudyTime, String aid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 资源学习记录
|
* 资源学习记录
|
||||||
|
|||||||
@@ -321,7 +321,7 @@ public class StudyServiceImpl implements IStudyService{
|
|||||||
// 更新 前端传输已学习时长
|
// 更新 前端传输已学习时长
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@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();
|
LocalDateTime now=LocalDateTime.now();
|
||||||
UpdateBuilder update=UpdateBuilder.from(StudyCourseItem.class);
|
UpdateBuilder update=UpdateBuilder.from(StudyCourseItem.class);
|
||||||
@@ -330,9 +330,6 @@ public class StudyServiceImpl implements IStudyService{
|
|||||||
update.addFilter(FieldFilters.lt("lastStudyTime", lastStudyTime));
|
update.addFilter(FieldFilters.lt("lastStudyTime", lastStudyTime));
|
||||||
update.addUpdateField("lastStudyTime", lastStudyTime);
|
update.addUpdateField("lastStudyTime", lastStudyTime);
|
||||||
update.addUpdateField("lastTime", now);
|
update.addUpdateField("lastTime", now);
|
||||||
if(progressVideo!=null) {
|
|
||||||
update.addUpdateField("progressVideo", progressVideo);
|
|
||||||
}
|
|
||||||
scItemDao.update(update.builder());
|
scItemDao.update(update.builder());
|
||||||
//增加用户的学习时长,在api中调用
|
//增加用户的学习时长,在api中调用
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user