package com.qxgmat.service.inline;

import com.github.pagehelper.Page;
import com.nuliji.tools.AbstractService;
import com.nuliji.tools.exception.ParameterException;
import com.nuliji.tools.exception.SystemException;
import com.nuliji.tools.mybatis.Example;
import com.qxgmat.data.dao.AdMapper;
import com.qxgmat.data.dao.ClassCourseMapper;
import com.qxgmat.data.dao.entity.Ad;
import com.qxgmat.data.dao.entity.ClassCourse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Date;
import java.util.List;

@Service
public class ClassCourseService extends AbstractService {
    private static final Logger logger = LoggerFactory.getLogger(ClassCourseService.class);

    @Resource
    private ClassCourseMapper classCourseMapper;

    public List<ClassCourse> all(){
        Example example = new Example(ClassCourse.class);
        return select(classCourseMapper, example);
    }

    public ClassCourse add(ClassCourse course){
        int result = insert(classCourseMapper, course);
        course = one(classCourseMapper, course.getId());
        if(course == null){
            throw new SystemException("课程添加失败");
        }
        return course;
    }

    public ClassCourse edit(ClassCourse course){
        ClassCourse in = one(classCourseMapper, course.getId());
        if(in == null){
            throw new ParameterException("课程不存在");
        }
        int result = update(classCourseMapper, course);
        return course;
    }

    public boolean delete(Number id){
        ClassCourse in = one(classCourseMapper, id);
        if(in == null){
            throw new ParameterException("课程不存在");
        }
        int result = delete(classCourseMapper, id);
        return result > 0;
    }

    public ClassCourse get(Number id){
        ClassCourse in = one(classCourseMapper, id);

        if(in == null){
            throw new ParameterException("课程不存在");
        }
        return in;
    }

    public Page<ClassCourse> select(int page, int pageSize){
        return select(classCourseMapper, page, pageSize);
    }

    public List<ClassCourse> select(Collection ids){
        return select(classCourseMapper, ids);
    }

}
