从学习中心章节视频的学习资格,通过远程调用内容服务判断课程收费情况,免费远程调用媒资服务,查询视频URL,返回前端;收费视频判断是否到期等

接口信息

路径地址 http://localhost:63020/learning/open/learn/getvideo/{courseId}/{teachplanId}/{mediaId}
请求方式 POST
请求参数
返回结果 R

查询Service

public interface LearningService {

/**
* 获取视频的学习资格
*
* @param userId 用户ID
* @param courseId 课程ID
* @param teachplanId 课程计划ID
* @param mediaId 媒资ID
*/
R getvideo(String userId, Long courseId, Long teachplanId, String mediaId);
}

实现该方法

@Service
public class LearningServiceImpl implements LearningService {
private final MyCourseTablesService myCourseTablesService;
private final ContentServerClient contentServerClient;
private final MediaServerClient mediaServerClient;

public LearningServiceImpl(MyCourseTablesService myCourseTablesService, ContentServerClient contentServerClient, MediaServerClient mediaServerClient) {
this.myCourseTablesService = myCourseTablesService;
this.contentServerClient = contentServerClient;
this.mediaServerClient = mediaServerClient;
}

/**
* 获取视频的学习资格
*
* @param userId 用户ID
* @param courseId 课程ID
* @param teachplanId 课程计划ID
* @param mediaId 媒资ID
*/
@Override
public R getvideo(String userId, Long courseId, Long teachplanId, String mediaId) {
// 远程调用查询已发布课程
CoursePublish coursePublish = contentServerClient.getCoursePublish(courseId);
if (coursePublish == null) {
return R.fail(-1, "课程不存在,无法预览");
}

// TODO 判断该视频视频所在课程小节是否支持试学


if (StringUtils.isEmpty(userId)) {
// 用户未登录
if (coursePublish.getCharge().equals("201000")) {
String url = mediaServerClient.getPlayUrlByMediaId(mediaId);
return R.success(url);
}
return R.fail(-1, "请登陆后选课学习");
}
// 查询学习资格
XcCourseTablesVO learningStatus = myCourseTablesService.getLearningStatus(userId, courseId);
String learnStatus = learningStatus.getLearnStatus();
if (learnStatus.equals("702002")) {
return R.fail(-1, "无法学习,未选课或选课后没有支付");
} else if (learnStatus.equals("702003")) {
return R.fail(-1, "已过期需要申请续费或重新支付");
}

// 有资格, 远程调用媒资获取视频地址
String url = mediaServerClient.getPlayUrlByMediaId(mediaId);
return R.success(url);
}
}

查询Controller

MyLearningController
@Api(value = "学习过程管理接口", tags = "学习过程管理接口")
@RestController
public class MyLearningController {
private final LearningService learningService;

public MyLearningController(LearningService learningService) {
this.learningService = learningService;
}

@ApiOperation("获取视频")
@GetMapping("/open/learn/getvideo/{courseId}/{teachplanId}/{mediaId}")
public R getVideo(@PathVariable("courseId") Long courseId, @PathVariable("teachplanId") Long teachplanId, @PathVariable("mediaId") String mediaId) {
String userId = null;
try {
SecurityUtil.XcUser user = SecurityUtil.getUser();
userId = user.getId();
} catch (Exception e) {
e.printStackTrace();
}
return learningService.getvideo(userId, courseId, teachplanId, mediaId);
}
}