package com.hc.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.business.mapper.ZccmCourseChapterTagMapper;
import com.hc.business.model.ZccmCourseChapterTag;
import com.hc.business.service.ZccmCourseChapterTagService;
import org.springframework.stereotype.Service;

/**
 * 图书章节标签表。新建完成的图书章节，可以根据讲师不同，给不同的章节打标签，比如基础阶段，进阶阶段。。。(ZccmCourseChapterTag)表服务实现类
 *
 * @author java
 * @since 2020-11-09 10:04:51
 */

@Service("courseChapterTagService")
public class ZccmCourseChapterTagServiceImpl implements ZccmCourseChapterTagService {

    private final ZccmCourseChapterTagMapper courseChapterTagMapper;

    public ZccmCourseChapterTagServiceImpl(ZccmCourseChapterTagMapper courseChapterTagMapper) {
        this.courseChapterTagMapper = courseChapterTagMapper;
    }

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

    /**
     * 新增数据
     *
     * @param courseChapterTag 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmCourseChapterTag insert(ZccmCourseChapterTag courseChapterTag) {
        this.courseChapterTagMapper.insert(courseChapterTag);
        return courseChapterTag;
    }

    /**
     * 修改数据
     *
     * @param courseChapterTag 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmCourseChapterTag update(ZccmCourseChapterTag courseChapterTag) {
        this.courseChapterTagMapper.updateByPrimaryKeySelective(courseChapterTag);
        return this.queryById(courseChapterTag.getTagId());
    }

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

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