292 lines
10 KiB
Java
292 lines
10 KiB
Java
package com.peanut.modules.sociology.controller;
|
||
|
||
import com.aliyun.vod20170321.models.*;
|
||
import com.aliyuncs.sts.model.v20150401.AssumeRoleResponse;
|
||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||
import com.peanut.common.utils.PlayToken;
|
||
import com.peanut.common.utils.R;
|
||
import com.peanut.common.utils.ShiroUtils;
|
||
import com.peanut.common.utils.SpdbUtil;
|
||
import com.peanut.modules.common.dao.UserCourseStudyingDao;
|
||
import com.peanut.modules.common.entity.*;
|
||
import com.peanut.modules.common.to.ParamTo;
|
||
import com.peanut.modules.master.service.CourseCatalogueChapterVideoService;
|
||
import com.peanut.modules.master.service.SysCourseDirectService;
|
||
import com.peanut.modules.sociology.service.CourseCatalogueChapterService;
|
||
import com.peanut.modules.sociology.service.CourseService;
|
||
import com.peanut.modules.sociology.service.CourseSociologyService;
|
||
import lombok.SneakyThrows;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.web.bind.annotation.RequestBody;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RestController;
|
||
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.Objects;
|
||
|
||
|
||
@Slf4j
|
||
@RestController("sociologyCourse")
|
||
@RequestMapping("sociology/course")
|
||
public class CourseController {
|
||
@Autowired
|
||
private CourseService courseService;
|
||
@Autowired
|
||
private CourseCatalogueChapterService courseCatalogueChapterService;
|
||
@Autowired
|
||
private CourseCatalogueChapterVideoService courseCatalogueChapterVideoService;
|
||
@Autowired
|
||
private SysCourseDirectService sysCourseDirectService;
|
||
@Autowired
|
||
private CourseSociologyService courseSociologyService;
|
||
|
||
@Autowired
|
||
private UserCourseStudyingDao userCourseStudyingDao;
|
||
@Autowired
|
||
private PlayToken playToken;
|
||
|
||
/**
|
||
* 获取用户最近学习课程列表
|
||
* @return
|
||
*/
|
||
@RequestMapping("/getUserLateCourseList")
|
||
public R getUserLateCourseList(){
|
||
ParamTo param = new ParamTo();
|
||
Integer userId = ShiroUtils.getUId();
|
||
param.setId(userId);
|
||
List<CourseEntity> userLateCourseList = courseService.getUserLateCourseList(param);
|
||
return R.ok().put("page",userLateCourseList);
|
||
}
|
||
|
||
/**
|
||
* 获取国学营销标签下的课程列表
|
||
* @param param
|
||
* @return
|
||
*/
|
||
@RequestMapping("/getMarketCourseList")
|
||
public R getMarketCourseList(@RequestBody ParamTo param){
|
||
Page<CourseEntity> marketCourseList = courseService.getMarketCourseList(param);
|
||
return R.ok().put("courseList",marketCourseList);
|
||
}
|
||
|
||
/**
|
||
* 获取课程说明
|
||
* @return
|
||
*/
|
||
@RequestMapping("/getSociologyCourseRecord")
|
||
public R getSociologyCourseRecord(){
|
||
SysCourseDirectEntity byId = sysCourseDirectService.getById(2);
|
||
return R.ok().put("result",byId);
|
||
}
|
||
|
||
/**
|
||
* 获取国学课程价格
|
||
* @return
|
||
*/
|
||
@RequestMapping("/getCoursePrice")
|
||
public R getCoursePrice(){
|
||
List coursePrice = courseService.getCoursePrice();
|
||
return R.ok().put("list",coursePrice);
|
||
}
|
||
|
||
/**
|
||
* 获取国学标签下的课程列表
|
||
* @param param
|
||
* @return
|
||
*/
|
||
@RequestMapping("/getSociologyCourseList")
|
||
public R getSociologyCourseList(@RequestBody ParamTo param){
|
||
Page sociologyCourseList = courseService.getSociologyCourseList(param);
|
||
return R.ok().put("courses",sociologyCourseList);
|
||
}
|
||
|
||
/**
|
||
* 加入收藏(加入正在学习)
|
||
* @param map
|
||
* @return
|
||
*/
|
||
@RequestMapping("/addUserCourseStudying")
|
||
public R addUserCourseStudying(@RequestBody Map<String,Integer> map){
|
||
int isExist = userCourseStudyingDao.selectCount(new LambdaQueryWrapper<UserCourseStudying>()
|
||
.eq(UserCourseStudying::getUserId,ShiroUtils.getUId())
|
||
.eq(UserCourseStudying::getCourseId,map.get("courseId")));
|
||
if (isExist>0){
|
||
return R.error("已存在");
|
||
}else {
|
||
UserCourseStudying userCourseStudying = new UserCourseStudying();
|
||
userCourseStudying.setUserId(ShiroUtils.getUId());
|
||
userCourseStudying.setCourseId(map.get("courseId"));
|
||
userCourseStudyingDao.insert(userCourseStudying);
|
||
return R.ok().put("result",userCourseStudying);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 移出收藏(移出正在学习)
|
||
* @param map
|
||
* @return
|
||
*/
|
||
@RequestMapping("/removeUserCourseStudying")
|
||
public R removeUserCourseStudying(@RequestBody Map<String,Integer> map){
|
||
userCourseStudyingDao.delete(new LambdaQueryWrapper<UserCourseStudying>()
|
||
.eq(UserCourseStudying::getUserId,ShiroUtils.getUId()).eq(UserCourseStudying::getCourseId,map.get("courseId")));
|
||
return R.ok();
|
||
}
|
||
|
||
/**
|
||
* 获取课程目录章节详情
|
||
* @param param
|
||
* @return
|
||
*/
|
||
@RequestMapping("/getCourseCatalogueChapterDetail")
|
||
public R getCourseCatalogueChapterDetail(@RequestBody ParamTo param){
|
||
Map<String, Object> chapterDetail = courseCatalogueChapterService.getChapterDetail(param.getId());
|
||
return R.ok().put("data",chapterDetail);
|
||
}
|
||
|
||
/**
|
||
* 开通免费课程
|
||
* @param map
|
||
* @return
|
||
*/
|
||
@RequestMapping("/startStudyForMF")
|
||
public R startStudyForMF(@RequestBody Map<String,Integer> map){
|
||
return courseService.startStudyForMF(map.get("catalogueId"));
|
||
}
|
||
|
||
/**
|
||
* 获取课程详情
|
||
* @param param
|
||
* @return
|
||
*/
|
||
@RequestMapping("/getCourseDetail")
|
||
public R getCourseDetail(@RequestBody ParamTo param){
|
||
Map<String, Object> courseDetail = courseService.getCourseDetail(param.getId());
|
||
return R.ok().put("data",courseDetail);
|
||
}
|
||
|
||
/**
|
||
* 获取课程目录章节条目列表
|
||
* @param param
|
||
* @return
|
||
*/
|
||
@RequestMapping("/getCourseCatalogueChapterList")
|
||
public R getCourseCatalogueChapterList(@RequestBody ParamTo param){
|
||
List<CourseCatalogueChapterEntity> courseCatalogueChapterList = courseCatalogueChapterService.getCourseCatalogueChapterList(param.getId());
|
||
return R.ok().put("chapterList",courseCatalogueChapterList);
|
||
}
|
||
|
||
@RequestMapping("/getPlayAuth")
|
||
public R getPlayAuth(@RequestBody Map<String,String> map) throws Exception {
|
||
GetVideoPlayAuthResponse vid = SpdbUtil.getPlayAuth(map.get("vid"));
|
||
String playAuth = vid.getBody().getPlayAuth();
|
||
return R.ok().put("playAuth",playAuth);
|
||
}
|
||
|
||
@RequestMapping("/saveCoursePosition")
|
||
public R saveCoursePosition(@RequestBody Map<String,Object> map){
|
||
Integer uId = ShiroUtils.getUId();
|
||
|
||
Integer videoId = Integer.valueOf(map.get("videoId").toString());
|
||
String po = map.get("position").toString();
|
||
if(Objects.equals(po, "none")||po==""){
|
||
return R.ok();
|
||
}
|
||
int position = Integer.valueOf(po);
|
||
courseCatalogueChapterVideoService.saveCoursePosition(uId,videoId,position);
|
||
return R.ok();
|
||
}
|
||
/**
|
||
* 验证video权限,并解决足迹,加密视频签名问题
|
||
* @param video
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
@RequestMapping("/checkVideo")
|
||
public R checkVideo(@RequestBody CourseCatalogueChapterVideoEntity video) throws Exception {
|
||
return courseCatalogueChapterVideoService.checkVideo(video);
|
||
}
|
||
|
||
@RequestMapping("/mytt")
|
||
public R mytt() throws Exception {
|
||
String s = playToken.generateToken();
|
||
System.out.println(s);
|
||
boolean b = playToken.validateToken(s);
|
||
System.out.println(b);
|
||
|
||
// GenerateKMSDataKeyResponseBody kms = SpdbUtil.KMS();
|
||
//
|
||
// return R.ok().put("result",kms);
|
||
return R.ok();
|
||
}
|
||
|
||
|
||
@RequestMapping("/mytt1")
|
||
public R mytt1(@RequestBody Map<String,String> map){
|
||
DecryptKMSDataKeyResponseBody decryptKMSDataKeyResponseBody = SpdbUtil.enKMS(map.get("kms"));
|
||
return R.ok().put("result",decryptKMSDataKeyResponseBody);
|
||
}
|
||
|
||
@RequestMapping("/mytt2")
|
||
public R mytt2(@RequestBody Map<String,String> map){
|
||
GetPlayInfoResponseBody urlbody = SpdbUtil.getUrl(map.get("vid"));
|
||
// String url = urlbody==null?null:urlbody.getPlayInfoList().getPlayInfo().get(0).getPlayURL();
|
||
return R.ok().put("result",urlbody);
|
||
}
|
||
|
||
|
||
@RequestMapping("/ttt")
|
||
@SneakyThrows
|
||
public R ttt(){
|
||
AssumeRoleResponse assumeRoleResponse = SpdbUtil.assumeRole();
|
||
return R.ok().put("result",assumeRoleResponse);
|
||
}
|
||
|
||
@RequestMapping("/getMyCourse")
|
||
public R getMyCourse(@RequestBody Map<String,Integer> map){
|
||
List courses = courseService.getMyCourse(map.get("type"));
|
||
return R.ok().put("courses",courses);
|
||
}
|
||
|
||
// //添加正在学习(收藏)
|
||
// @RequestMapping("/addUserCourseStudying")
|
||
// public R addUserCourseStudying(@RequestBody UserCourseStudying userCourseStudying){
|
||
// return R.ok().put("success",courseService.addUserCourseStudying(userCourseStudying));
|
||
// }
|
||
|
||
//移除正在学习(收藏)
|
||
@RequestMapping("/delUserCourseStudying")
|
||
public R delUserCourseStudying(@RequestBody Map<String,Object> param){
|
||
return R.ok().put("success",courseService.delUserCourseStudying(param));
|
||
}
|
||
|
||
//我的课程-正在学习(收藏)
|
||
@RequestMapping("/getUserCourseStudying")
|
||
public R getUserCourseStudying(){
|
||
List courseList = courseService.getUserCourseStudying();
|
||
return R.ok().put("courseList",courseList);
|
||
}
|
||
|
||
//我的课程-全部
|
||
@RequestMapping("/getUserCourseBuy")
|
||
public R getUserCourseBuy(){
|
||
List<CourseSociologyEntity> courseSociologyList = courseSociologyService.getCourseSociologyTree();
|
||
Map<String,Object> param = new HashMap<>();
|
||
param.put("courseSociologyList",courseSociologyList);
|
||
List courseList = courseService.getUserCourseBuy(param);
|
||
return R.ok().put("courseList",courseList);
|
||
}
|
||
|
||
//我的课程-过期课程
|
||
@RequestMapping("/getCourseExpire")
|
||
public R getCourseExpire(@RequestBody Map<String,Object> param){
|
||
List courseList = courseService.getCourseExpire(param);
|
||
return R.ok().put("courseList",courseList);
|
||
}
|
||
|
||
}
|