1.课程添加bug修复

下面完整的添加一个课程,测试效果如下。

image-20211201200114014

数据成功添加了,不过subject_parent_id似乎没有值。这是因为后端接口传的数据CourseInfoForm中没有这个属性。新增如下。

 @ApiModelProperty(value = "一级分类ID")
 private String subjectParentId;

注意属性名与前端使用要保持一致(参考下图)。

image-20211201201357697

重新测试验证bug解决了。

2.课程大纲管理

课程大纲也是一个列表,其实与之前做的课程分类列表功能基本类似。

(1)创建实体类

com.wangzhou.eduservice.entity.chapter.ChapterVo

/**
 * 课程章节
 */
@Data
public class ChapterVo {
    private String id;
    private String title;
    private List<VideoVo> children = new ArrayList<>();
}

com.wangzhou.eduservice.entity.chapter.VideoVo

/**
 * 课程小节
 */
@Data
public class VideoVo {
    private String id;
    private String title;
}

(2)Controller

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author wangzhou
 * @since 2021-11-12
 */
@RestController
@RequestMapping("/eduservice/edu-chapter")
public class EduChapterController {

    @Autowired
    private EduChapterService eduChapterService;

    /**
     * 根据课程id获取课程的章节、小节
     * @return
     */
    @GetMapping("/getChapterVideo/{courseId}")
    public R getChapterVideo(@PathVariable String courseId) {
        List<ChapterVo> list = eduChapterService.getChapterVideo(courseId);
        return R.ok().data("list", list);
    }

}

(3)Service

/**
 * <p>
 * 课程 服务实现类
 * </p>
 *
 * @author wangzhou
 * @since 2021-11-12
 */
@Service
public class EduChapterServiceImpl extends ServiceImpl<EduChapterMapper, EduChapter> implements EduChapterService {
    @Autowired
    private EduVideoService eduVideoService;

    @Override
    public List<ChapterVo> getChapterVideo(String courseId) {
        // 1.根据课程id查取所有章节
        QueryWrapper<EduChapter> chapterWrapper = new QueryWrapper<>();
        chapterWrapper.eq("course_Id", courseId);
        List<EduChapter> chapterList = baseMapper.selectList(chapterWrapper);

        // 2.根据id课程查取所有小节
        QueryWrapper<EduVideo> videoWrapper = new QueryWrapper<>();
        videoWrapper.eq("course_Id", courseId);
        List<EduVideo> videoList = eduVideoService.list(videoWrapper);

        // 3.遍历所有课程章节进行封装
        List<ChapterVo> finalChapterList = new ArrayList<>();
        for (int i = 0; i < chapterList.size(); i++) {
            EduChapter eduChapter = chapterList.get(i);
            ChapterVo chapterVo = new ChapterVo();
            BeanUtils.copyProperties(eduChapter, chapterVo);

            // 4.遍历所有课程小节进行封装
            List<VideoVo> videoVoList = new ArrayList<>();
            for (int j = 0; j < videoList.size(); j++) {
                EduVideo eduVideo = videoList.get(i);
                if(eduVideo.getChapterId().equals(eduChapter.getId())) {
                    VideoVo videoVo = new VideoVo();
                    BeanUtils.copyProperties(eduVideo, videoVo);
                    videoVoList.add(videoVo);
                }

            }
            chapterVo.setChildren(videoVoList);
            finalChapterList.add(chapterVo);
        }
        return finalChapterList;
    }
}