CourseDictServiceImpl.java 2.99 KB
package com.zhongzhi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhongzhi.dao.YearDictDAO;
import com.zhongzhi.dto.course.CoursesDTO;
import com.zhongzhi.dao.VodDictDAO;
import com.zhongzhi.model.CourseDictDO;
import com.zhongzhi.dao.CourseDictDAO;
import com.zhongzhi.model.VodDictDO;
import com.zhongzhi.model.YearDictDO;
import com.zhongzhi.service.CourseDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongzhi.vo.course.CourseVodsVO;
import com.zhongzhi.vo.course.CoursesVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2022-11-14
 */
@Service
public class CourseDictServiceImpl extends ServiceImpl<CourseDictDAO, CourseDictDO> implements CourseDictService {

    @Autowired
    private VodDictDAO vodDictMapper;

    @Autowired
    private YearDictDAO yearDictDAO;

    public void addCourse(CourseDictDO courseDictDO) {
        this.baseMapper.insert(courseDictDO);
    }

    public void updateCourse(CourseDictDO courseDictDO) {
        this.updateById(courseDictDO);
    }

    public IPage<CoursesVO> courses(CoursesDTO coursesDTO) {
        Page page = new Page(coursesDTO.getPageNo(), coursesDTO.getPageSize());
        return this.baseMapper.courses(page, coursesDTO.getCourseName(),coursesDTO.getYearId());
    }

    public void deleteCourse(CourseDictDO courseDictDO) {

        this.baseMapper.deleteById(courseDictDO.getId());

        //删除视频
        vodDictMapper.delete(new QueryWrapper<VodDictDO>()
                .lambda()
                .eq(VodDictDO::getCourseId, courseDictDO.getId()));
    }

    public List<CourseVodsVO> courseVods(CourseDictDO courseDictDO) {

        List<CourseVodsVO> courseVodsVOS = new ArrayList<>();

        YearDictDO yearDictDO = yearDictDAO.selectById(courseDictDO.getYearId());
        if ("1".equals(yearDictDO.getStatus())){
            List<CourseDictDO> courseDictDOS = this.baseMapper.selectList(new QueryWrapper<CourseDictDO>()
                    .lambda()
                    .eq(CourseDictDO::getYearId,courseDictDO.getYearId()));
            for (CourseDictDO cdd : courseDictDOS) {
                CourseVodsVO courseVodsVO = new CourseVodsVO();
                BeanUtils.copyProperties(cdd, courseVodsVO);
                List<VodDictDO> vodDictDOS = vodDictMapper.selectList(new QueryWrapper<VodDictDO>()
                        .lambda()
                        .eq(VodDictDO::getCourseId,cdd.getId())
                        .orderByAsc(VodDictDO::getOrderNo));
                courseVodsVO.setVodDictDOS(vodDictDOS);
                courseVodsVOS.add(courseVodsVO);
            }
        }
        return courseVodsVOS;
    }

}