| | |
| | | HealthCourse course = requireEnabledCourse(courseId); |
| | | List<HealthCourseVideo> enabledVideos = listEnabledVideos(courseId); |
| | | Map<Long, VideoProgressSnapshot> videoProgressSnapshotMap = buildVideoProgressSnapshotMap(userId, Collections.singletonList(courseId)); |
| | | PurchaseStateSnapshot purchaseStateSnapshot = resolvePurchaseState(courseId); |
| | | |
| | | List<AppMyHealthCourseVideoItemVO> videos = new ArrayList<AppMyHealthCourseVideoItemVO>(enabledVideos.size()); |
| | | Long currentVideoId = null; |
| | | LocalDateTime latestLearnAt = null; |
| | | for (HealthCourseVideo video : enabledVideos) { |
| | | VideoProgressSnapshot snapshot = videoProgressSnapshotMap.get(video.getId()); |
| | | boolean freeAccess = isFreeVideo(video.getSalePrice()); |
| | | boolean purchased = purchaseStateSnapshot.isCourseOwned() |
| | | || purchaseStateSnapshot.getPurchasedVideoIds().contains(video.getId()); |
| | | boolean locked = !freeAccess && !purchased; |
| | | AppMyHealthCourseVideoItemVO itemVO = new AppMyHealthCourseVideoItemVO(); |
| | | itemVO.setVideoId(video.getId()); |
| | | itemVO.setChapterName(trimToEmpty(video.getChapterName())); |
| | | itemVO.setDurationSeconds(defaultNumber(video.getDurationSeconds())); |
| | | itemVO.setDurationText(formatVideoDuration(itemVO.getDurationSeconds())); |
| | | itemVO.setFreeAccess(Boolean.valueOf(freeAccess)); |
| | | itemVO.setPurchased(Boolean.valueOf(purchased)); |
| | | itemVO.setLocked(Boolean.valueOf(locked)); |
| | | itemVO.setVideoUrl(trimToEmpty(video.getVideoUrl())); |
| | | itemVO.setCompleted(Boolean.valueOf(snapshot != null && snapshot.isCompleted())); |
| | | itemVO.setProgressPercent(Integer.valueOf(calculateVideoDisplayProgressPercent( |
| | |
| | | itemVO.setLastPlayPositionSeconds(Integer.valueOf(resolveVideoResumePosition(snapshot))); |
| | | itemVO.setDownloadable(Boolean.valueOf(hasVideoDownloadAccess(userId, courseId, video.getId()))); |
| | | videos.add(itemVO); |
| | | if (snapshot != null && snapshot.getLatestLearnAt() != null |
| | | // 默认播放章节只允许落在当前用户可观看的小节上,未购小节保留展示但不自动选中。 |
| | | if (!locked && snapshot != null && snapshot.getLatestLearnAt() != null |
| | | && (latestLearnAt == null || snapshot.getLatestLearnAt().isAfter(latestLearnAt))) { |
| | | latestLearnAt = snapshot.getLatestLearnAt(); |
| | | currentVideoId = video.getId(); |
| | | } |
| | | } |
| | | if (currentVideoId == null && !enabledVideos.isEmpty()) { |
| | | currentVideoId = enabledVideos.get(0).getId(); |
| | | if (currentVideoId == null) { |
| | | for (AppMyHealthCourseVideoItemVO itemVO : videos) { |
| | | if (!Boolean.TRUE.equals(itemVO.getLocked())) { |
| | | currentVideoId = itemVO.getVideoId(); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | AppMyHealthCourseDetailVO detailVO = new AppMyHealthCourseDetailVO(); |