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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.common.exception.HttpException;
import com.subsidy.mapper.CourseContentMapper;
import com.subsidy.model.CourseContentDO;
import com.subsidy.service.CourseContentService;
import com.subsidy.util.ConstantUtils;
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 {

    @Override
    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));
    }

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

    @Override
    public String addContent(CourseContentDO courseContentDO){

        Integer orderNoTmp = this.baseMapper.selectMaxOrderNo(courseContentDO.getCourseId());

        int orderNo = 1 ;

        if (null!=orderNoTmp){
            orderNo = orderNoTmp+1;
        }
        courseContentDO.setOrderNo(orderNo);
        this.baseMapper.insert(courseContentDO);
        return ConstantUtils.ADD_SUCCESS;
    }

    @Override
    public String updateContent(CourseContentDO courseContentDO){

        int count  = this.baseMapper.selectCount(new QueryWrapper<CourseContentDO>()
        .lambda()
        .eq(CourseContentDO::getCourseId,courseContentDO.getCourseId())
        .eq(CourseContentDO::getContent,courseContentDO.getContent())
        .ne(CourseContentDO::getId,courseContentDO.getId()));

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

}