package com.hc.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.business.mapper.QuestionTagMapper;
import com.hc.business.model.QuestionTag;
import com.hc.business.service.QuestionTagService;
import org.springframework.stereotype.Service;

/**
 * 问题标签表(QuestionTag)表服务实现类
 *
 * @author java
 * @since 2020-12-07 11:36:42
 */

@Service("questionTagService")
public class QuestionTagServiceImpl implements QuestionTagService {

    private final QuestionTagMapper questionTagMapper;

    public QuestionTagServiceImpl(QuestionTagMapper questionTagMapper) {
        this.questionTagMapper = questionTagMapper;
    }

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

    /**
     * 新增数据
     *
     * @param questionTag 实例对象
     * @return 实例对象
     */
    @Override
    public QuestionTag insert(QuestionTag questionTag) {
        this.questionTagMapper.insert(questionTag);
        return questionTag;
    }

    /**
     * 修改数据
     *
     * @param questionTag 实例对象
     * @return 实例对象
     */
    @Override
    public QuestionTag update(QuestionTag questionTag) {
        this.questionTagMapper.updateByPrimaryKeySelective(questionTag);
        return this.queryById(questionTag.getQuestionTagId());
    }

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

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