|
@@ -1,26 +1,28 @@
|
|
|
package cn.iocoder.byzs.module.bjdx.service.course;
|
|
package cn.iocoder.byzs.module.bjdx.service.course;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
|
|
+import cn.iocoder.byzs.framework.common.pojo.PageResult;
|
|
|
|
|
+import cn.iocoder.byzs.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.byzs.module.bjdx.controller.admin.course.vo.CoursePageReqVO;
|
|
import cn.iocoder.byzs.module.bjdx.controller.admin.course.vo.CoursePageReqVO;
|
|
|
|
|
+import cn.iocoder.byzs.module.bjdx.controller.admin.course.vo.CourseRespVO;
|
|
|
import cn.iocoder.byzs.module.bjdx.controller.admin.course.vo.CourseSaveReqVO;
|
|
import cn.iocoder.byzs.module.bjdx.controller.admin.course.vo.CourseSaveReqVO;
|
|
|
-import cn.iocoder.byzs.module.bjdx.controller.admin.courseconfig.vo.CourseConfigPageReqVO;
|
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
+import cn.iocoder.byzs.module.bjdx.dal.dataobject.course.CourseDO;
|
|
|
|
|
+import cn.iocoder.byzs.module.bjdx.dal.mysql.course.CourseMapper;
|
|
|
|
|
+import cn.iocoder.byzs.module.infra.framework.file.core.client.FileClient;
|
|
|
|
|
+import cn.iocoder.byzs.module.infra.service.file.FileConfigService;
|
|
|
|
|
+import cn.iocoder.byzs.module.infra.service.file.FileServiceImpl;
|
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
-import java.util.*;
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
-import cn.iocoder.byzs.module.bjdx.controller.admin.course.vo.*;
|
|
|
|
|
-import cn.iocoder.byzs.module.bjdx.dal.dataobject.course.CourseDO;
|
|
|
|
|
-import cn.iocoder.byzs.framework.common.pojo.PageResult;
|
|
|
|
|
-import cn.iocoder.byzs.framework.common.util.object.BeanUtils;
|
|
|
|
|
-
|
|
|
|
|
-import cn.iocoder.byzs.module.bjdx.dal.mysql.course.CourseMapper;
|
|
|
|
|
-
|
|
|
|
|
import static cn.iocoder.byzs.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.byzs.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
-import static cn.iocoder.byzs.framework.common.util.collection.CollectionUtils.convertList;
|
|
|
|
|
-import static cn.iocoder.byzs.module.bjdx.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
|
+import static cn.iocoder.byzs.module.bjdx.enums.ErrorCodeConstants.COURSE_NOT_EXISTS;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 课程 Service 实现类
|
|
* 课程 Service 实现类
|
|
@@ -33,12 +35,20 @@ public class CourseServiceImpl implements CourseService {
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private CourseMapper courseMapper;
|
|
private CourseMapper courseMapper;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private FileServiceImpl fileService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private FileConfigService fileConfigService;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Long createCourse(CourseSaveReqVO createReqVO) {
|
|
public Long createCourse(CourseSaveReqVO createReqVO) {
|
|
|
// 插入
|
|
// 插入
|
|
|
CourseDO course = BeanUtils.toBean(createReqVO, CourseDO.class);
|
|
CourseDO course = BeanUtils.toBean(createReqVO, CourseDO.class);
|
|
|
courseMapper.insert(course);
|
|
courseMapper.insert(course);
|
|
|
|
|
+
|
|
|
|
|
+ if (course.getCourseContentType().equals("video")) {
|
|
|
|
|
+ getSelf().asymcVideoFfmpeg(course);
|
|
|
|
|
+ }
|
|
|
// 返回
|
|
// 返回
|
|
|
return course.getId();
|
|
return course.getId();
|
|
|
}
|
|
}
|
|
@@ -50,6 +60,33 @@ public class CourseServiceImpl implements CourseService {
|
|
|
// 更新
|
|
// 更新
|
|
|
CourseDO updateObj = BeanUtils.toBean(updateReqVO, CourseDO.class);
|
|
CourseDO updateObj = BeanUtils.toBean(updateReqVO, CourseDO.class);
|
|
|
courseMapper.updateById(updateObj);
|
|
courseMapper.updateById(updateObj);
|
|
|
|
|
+
|
|
|
|
|
+ if (updateObj.getCourseContentType().equals("video")) {
|
|
|
|
|
+ getSelf().asymcVideoFfmpeg(updateObj);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Async
|
|
|
|
|
+ public void asymcVideoFfmpeg(CourseDO course) {
|
|
|
|
|
+ //只对mp4文件进行处理
|
|
|
|
|
+ String courseVideoPath = course.getCourseVideoPath();
|
|
|
|
|
+ String ext = courseVideoPath.substring(courseVideoPath.lastIndexOf("."));
|
|
|
|
|
+ if (StrUtil.isBlank(ext) || ext.equals(".m3u8")) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获取相对文件路径
|
|
|
|
|
+ String filePath= fileService.getFilePathByUrl(course.getCourseVideoPath());
|
|
|
|
|
+ if (StrUtil.isBlank(filePath)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //切片
|
|
|
|
|
+ FileClient client = fileConfigService.getMasterFileClient();
|
|
|
|
|
+ String m3u8Path = client.ffmpegHts(filePath);
|
|
|
|
|
+ if(StrUtil.isNotEmpty(m3u8Path)){
|
|
|
|
|
+ courseMapper.updateById(new CourseDO().setId(course.getId()).setCourseVideoPath(m3u8Path));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -105,4 +142,14 @@ public class CourseServiceImpl implements CourseService {
|
|
|
return courseMapper.selectCoursePage(pageReqVO);
|
|
return courseMapper.selectCoursePage(pageReqVO);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获得自身的代理对象,解决 AOP 生效问题
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return 自己
|
|
|
|
|
+ */
|
|
|
|
|
+ private CourseServiceImpl getSelf() {
|
|
|
|
|
+ return SpringUtil.getBean(getClass());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|