package com.hc.gpbusiness.service.impl;

import com.github.pagehelper.PageHelper;
import com.hc.gpbusiness.mapper.WebCourseTagCollectionMapper;
import com.hc.gpbusiness.model.WebCourseTagCollection;
import com.hc.gpbusiness.service.WebCourseTagCollectionService;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageInfo;

/**
 * 新闻标签，新闻对应表(WebCourseTagCollection)表服务实现类
 *
 * @author java
 * @since 2020-07-29 16:23:09
 */

@Service("courseTagCollectionService")
public class WebCourseTagCollectionServiceImpl implements WebCourseTagCollectionService {

    private final WebCourseTagCollectionMapper courseTagCollectionMapper;

    public WebCourseTagCollectionServiceImpl(WebCourseTagCollectionMapper courseTagCollectionMapper) {
        this.courseTagCollectionMapper = courseTagCollectionMapper;
    }

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

    /**
     * 新增数据
     *
     * @param courseTagCollection 实例对象
     * @return 实例对象
     */
    @Override
    public WebCourseTagCollection insert(WebCourseTagCollection courseTagCollection) {
        this.courseTagCollectionMapper.insert(courseTagCollection);
        return courseTagCollection;
    }

    /**
     * 修改数据
     *
     * @param courseTagCollection 实例对象
     * @return 实例对象
     */
    @Override
    public WebCourseTagCollection update(WebCourseTagCollection courseTagCollection) {
        this.courseTagCollectionMapper.updateByPrimaryKeySelective(courseTagCollection);
        return this.queryById(courseTagCollection.getCollectionId());
    }

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

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