package com.hc.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.business.mapper.ZccmQuestionAnswerMapper;
import com.hc.business.model.ZccmQuestionAnswer;
import com.hc.business.service.ZccmQuestionAnswerService;
import org.springframework.stereotype.Service;

/**
 * 问题答案表(ZccmQuestionAnswer)表服务实现类
 *
 * @author java
 * @since 2020-12-07 11:36:22
 */

@Service("questionAnswerService")
public class ZccmQuestionAnswerServiceImpl implements ZccmQuestionAnswerService {

    private final ZccmQuestionAnswerMapper questionAnswerMapper;

    public ZccmQuestionAnswerServiceImpl(ZccmQuestionAnswerMapper questionAnswerMapper) {
        this.questionAnswerMapper = questionAnswerMapper;
    }

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

    /**
     * 新增数据
     *
     * @param questionAnswer 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmQuestionAnswer insert(ZccmQuestionAnswer questionAnswer) {
        this.questionAnswerMapper.insert(questionAnswer);
        return questionAnswer;
    }

    /**
     * 修改数据
     *
     * @param questionAnswer 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmQuestionAnswer update(ZccmQuestionAnswer questionAnswer) {
        this.questionAnswerMapper.updateByPrimaryKeySelective(questionAnswer);
        return this.queryById(questionAnswer.getQuestionAnswerId());
    }

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

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