package com.hc.gpbusiness.service.impl;

import com.github.pagehelper.PageHelper;
import com.hc.gpbusiness.mapper.WebNewsTagCollectionMapper;
import com.hc.gpbusiness.model.WebNewsTagCollection;
import com.hc.gpbusiness.service.WebNewsTagCollectionService;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageInfo;

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

@Service("newsTagCollectionService")
public class WebNewsTagCollectionServiceImpl implements WebNewsTagCollectionService {

    private final WebNewsTagCollectionMapper newsTagCollectionMapper;

    public WebNewsTagCollectionServiceImpl(WebNewsTagCollectionMapper newsTagCollectionMapper) {
        this.newsTagCollectionMapper = newsTagCollectionMapper;
    }

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

    /**
     * 新增数据
     *
     * @param newsTagCollection 实例对象
     * @return 实例对象
     */
    @Override
    public WebNewsTagCollection insert(WebNewsTagCollection newsTagCollection) {
        this.newsTagCollectionMapper.insert(newsTagCollection);
        return newsTagCollection;
    }

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

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

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