1、功能需求
一个小节对应一个视频,一个课程有多个视频,删除课程时需要删除多个视频。
2、在VideoAdminController实现删除多个视频的接口service-vod
@ApiOperation(value = "删除多个视频")
@DeleteMapping("deleteMoreVideo")
public R deleteMoreVideo(@RequestParam("videoIdList") List videoIdList){
try {
//1创建初始化对象", "
DefaultAcsClient client = AliyunVodSDKUtils.initVodClient("你自己的阿里云keyid", "你自己的阿里云keysecret");
//2创建删除视频的请求
DeleteVideoRequest request = new DeleteVideoRequest();
//3向请求中设置视频id,支持传入多个视频ID,多个用逗号分隔
//videoIdList修改成11,22,33
String videoIds = StringUtils.join(videoIdList.toArray(),",");
request.setVideoIds(videoIds);
//4调用初始化对象方法
client.getAcsResponse(request);
return R.ok();
} catch (ClientException e) {
return R.error();
}
}
3、在service_edu中的com/atguigu/eduservice/client/ VodClient中新增接口方法
@DeleteMapping("/eduvod/video/deleteMoreVideo")
public R deleteMoreVideo(@RequestParam("videoIdList") List videoIdList);
4、在EduCourseServiceImpl调用接口实现
@Autowired
private VodClient vodClient;
//删除课程(以及相关信息)
@Override
public void deleteCourse(String courseId) {
//1根据课程id删除小节
//删除小节前删除视频
//1.1根据课程id查询该课程所有的视频
QueryWrapper wrapperVideoId = new QueryWrapper();
wrapperVideoId.eq("course_id",courseId);
List list = videoService.list(wrapperVideoId);
//1.2封装需要删除的视频id
List videoIds = new ArrayList();
for (int i = 0; i 0){
vodClient.deleteMoreVideo(videoIds);
}
QueryWrapper wrapperVideo = new QueryWrapper();
wrapperVideo.eq("course_id",courseId);
videoService.remove(wrapperVideo);
//2根据课程id删除章节
QueryWrapper wrapperChapter = new QueryWrapper();
wrapperChapter.eq("course_id",courseId);
chapterService.remove(wrapperChapter);
//3根据课程id删除描述
courseDescriptionService.removeById(courseId);
//4根据课程id删除课程
int delete = baseMapper.deleteById(courseId);
if(delete==0){
throw new GuliException(20001,"删除课程失败");
}
}