CourseContentServiceImpl.java 2.64 KB
package com.subsidy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.common.exception.HttpException;
import com.subsidy.controller.CourseContentController;
import com.subsidy.mapper.VodDictMapper;
import com.subsidy.model.CourseContentDO;
import com.subsidy.mapper.CourseContentMapper;
import com.subsidy.model.CourseDictDO;
import com.subsidy.model.VodDictDO;
import com.subsidy.service.CourseContentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.vo.vod.GetContendVodsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 课程目录表 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2021-10-11
 */
@Service
public class CourseContentServiceImpl extends ServiceImpl<CourseContentMapper, CourseContentDO> implements CourseContentService {

    public List<CourseContentDO> getContents(CourseContentDO courseContentDO) {
        return this.baseMapper.selectList(new QueryWrapper<CourseContentDO>()
                .lambda()
                .eq(CourseContentDO::getCourseId, courseContentDO.getCourseId())
                .orderByAsc(CourseContentDO::getOrderNo)
                .orderByAsc(CourseContentDO::getCreateDate));
    }

    public String deleteContent(CourseContentDO courseContentDO){
        this.baseMapper.deleteById(courseContentDO.getId());
        return ConstantUtils.DELETE_SUCCESS;
    }

    public String addContent(CourseContentDO courseContentDO){

        List<CourseContentDO> courseContentDOS = this.baseMapper.selectList(new QueryWrapper<CourseContentDO>()
        .lambda()
        .eq(CourseContentDO::getCourseId,courseContentDO.getCourseId())
        .orderByDesc(CourseContentDO::getOrderNo));

        int orderNo = 1 ;

        if (courseContentDOS.size()>0){
            orderNo = courseContentDOS.get(0).getOrderNo()+1;
        }
        courseContentDO.setOrderNo(orderNo);
        this.baseMapper.insert(courseContentDO);
        return ConstantUtils.ADD_SUCCESS;
    }

    public String updateContent(CourseContentDO courseContentDO){

        List<CourseContentDO> courseContentDOS = this.baseMapper.selectList(new QueryWrapper<CourseContentDO>()
        .lambda()
        .eq(CourseContentDO::getCourseId,courseContentDO.getCourseId())
        .eq(CourseContentDO::getContent,courseContentDO.getContent()));

        if (courseContentDOS.size()>0){
            throw new HttpException(40001);
        }
        this.baseMapper.updateById(courseContentDO);
        return ConstantUtils.SET_SUCCESS;
    }

}