package com.hc.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.business.mapper.CourseChapterAnnexMapper;
import com.hc.business.model.CourseChapterAnnex;
import com.hc.business.service.CourseChapterAnnexService;
import org.springframework.stereotype.Service;

/**
 * 章节附件表(CourseChapterAnnex)表服务实现类
 *
 * @author java
 * @since 2020-11-09 10:04:49
 */

@Service("courseChapterAnnexService")
public class CourseChapterAnnexServiceImpl implements CourseChapterAnnexService {

    private final CourseChapterAnnexMapper courseChapterAnnexMapper;

    public CourseChapterAnnexServiceImpl(CourseChapterAnnexMapper courseChapterAnnexMapper) {
        this.courseChapterAnnexMapper = courseChapterAnnexMapper;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param courseChapterAnnexId 主键
     * @return 实例对象
     */
    @Override
    public CourseChapterAnnex queryById(Integer courseChapterAnnexId) {
        return this.courseChapterAnnexMapper.selectByPrimaryKey(courseChapterAnnexId);
    }

    /**
     * 新增数据
     *
     * @param courseChapterAnnex 实例对象
     * @return 实例对象
     */
    @Override
    public CourseChapterAnnex insert(CourseChapterAnnex courseChapterAnnex) {
        this.courseChapterAnnexMapper.insert(courseChapterAnnex);
        return courseChapterAnnex;
    }

    /**
     * 修改数据
     *
     * @param courseChapterAnnex 实例对象
     * @return 实例对象
     */
    @Override
    public CourseChapterAnnex update(CourseChapterAnnex courseChapterAnnex) {
        this.courseChapterAnnexMapper.updateByPrimaryKeySelective(courseChapterAnnex);
        return this.queryById(courseChapterAnnex.getCourseChapterAnnexId());
    }

    /**
     * 通过主键删除数据
     *
     * @param courseChapterAnnexId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer courseChapterAnnexId) {
        return this.courseChapterAnnexMapper.deleteByPrimaryKey(courseChapterAnnexId) > 0;
    }

    /**
     * 分页查询多条数据
     *
     * @param page 页码
     * @param size 查询条数
     * @return 对象列表
     */
    @Override
    public PageInfo queryAllByLimit(int page, int size) {
        return PageHelper.startPage(page, size).doSelectPageInfo(this.courseChapterAnnexMapper::selectAll);
    }
}