CourseContentServiceImpl.java 2.45 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.scheduling.annotation.Async;
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));
    }

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

    @Async
    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;
    }

    @Async
    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;
    }

}