feat: 🎸 查询视频学习进度接口
This commit is contained in:
parent
35fb15e2e3
commit
a9ae28e3e1
@ -406,6 +406,21 @@ public class AiolCourseController extends JeecgController<AiolCourse, IAiolCours
|
||||
return Result.OK(result);
|
||||
}
|
||||
|
||||
@GetMapping("/{courseId}/get_video_progress")
|
||||
@Operation(summary = "查询视频学习进度", description = "查询用户在指定视频章节的学习进度,包括已学习时长和视频总时长")
|
||||
public Result<Map<String, Object>> queryVideoProgress(
|
||||
@PathVariable(value = "courseId") String courseId,
|
||||
@RequestParam(value = "sectionId") String sectionId,
|
||||
HttpServletRequest request) {
|
||||
|
||||
String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN);
|
||||
String username = JwtUtil.getUsername(token);
|
||||
LoginUser sysUser = sysBaseApi.getUserByName(username);
|
||||
|
||||
Map<String, Object> result = aiolCourseService.queryVideoProgress(courseId, sectionId, sysUser.getId());
|
||||
return Result.OK(result);
|
||||
}
|
||||
|
||||
@GetMapping("/count")
|
||||
@Operation(summary = "查询课程总数", description = "返回系统中所有课程的总数量")
|
||||
@IgnoreAuth
|
||||
|
@ -104,5 +104,14 @@ public interface IAiolCourseService extends IService<AiolCourse> {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> recordVideoProgress(String courseId, String sectionId, Integer duration, String id);
|
||||
Map<String, Object> recordVideoProgress(String courseId, String sectionId, Integer duration, String userId);
|
||||
|
||||
/**
|
||||
* 查询视频学习进度
|
||||
* @param courseId
|
||||
* @param sectionId
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> queryVideoProgress(String courseId, String sectionId, String userId);
|
||||
}
|
||||
|
@ -805,4 +805,60 @@ public class AiolCourseServiceImpl extends ServiceImpl<AiolCourseMapper, AiolCou
|
||||
return resourceMapper.selectById(resourceId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryVideoProgress(String courseId, String sectionId, String userId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
// 1. 查询用户在该章节的学习进度
|
||||
QueryWrapper<AiolLearnProgress> progressQuery = new QueryWrapper<>();
|
||||
progressQuery.eq("user_id", userId)
|
||||
.eq("course_id", courseId)
|
||||
.eq("section_id", sectionId);
|
||||
|
||||
AiolLearnProgress learnProgress = learnProgressMapper.selectOne(progressQuery);
|
||||
|
||||
// 2. 获取已学习时长
|
||||
Integer learnedDuration = 0;
|
||||
|
||||
if (learnProgress != null) {
|
||||
learnedDuration = learnProgress.getDuration() != null ? learnProgress.getDuration() : 0;
|
||||
}
|
||||
|
||||
// 3. 从Redis缓存获取视频资源信息,如果没有则从数据库查询并缓存
|
||||
String sourceType = EntityLinkConst.SourceType.COURSE_SECTION;
|
||||
String targetType = EntityLinkConst.TargetType.RESOURCE;
|
||||
|
||||
List<String> resourceIds = entityLinkBizService.listTargetIds(sourceType, sectionId, targetType);
|
||||
if (resourceIds.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "未找到章节对应的视频资源");
|
||||
return result;
|
||||
}
|
||||
|
||||
String resourceId = resourceIds.get(0);
|
||||
AiolResource resource = getVideoResourceFromCache(resourceId);
|
||||
|
||||
if (resource == null || resource.getDuration() == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "视频资源信息不完整");
|
||||
return result;
|
||||
}
|
||||
|
||||
Integer totalDuration = resource.getDuration();
|
||||
|
||||
// 6. 构建返回结果
|
||||
result.put("success", true);
|
||||
result.put("learnedDuration", learnedDuration); // 已学习时长(秒)
|
||||
result.put("totalDuration", totalDuration); // 视频总时长(秒)
|
||||
} catch (Exception e) {
|
||||
log.error("查询视频学习进度失败: courseId={}, sectionId={}, userId={}, error={}",
|
||||
courseId, sectionId, userId, e.getMessage(), e);
|
||||
result.put("success", false);
|
||||
result.put("message", "查询学习进度失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user