package com.hc.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.business.mapper.ZccmPaperQuestionMapper;
import com.hc.business.model.ZccmPaperQuestion;
import com.hc.business.service.ZccmPaperQuestionService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 随机试卷问题表(ZccmPaperQuestion)表服务实现类
 *
 * @author java
 * @since 2020-12-07 11:35:14
 */

@Service("paperQuestionService")
public class ZccmPaperQuestionServiceImpl implements ZccmPaperQuestionService {

    private final ZccmPaperQuestionMapper paperQuestionMapper;

    public ZccmPaperQuestionServiceImpl(ZccmPaperQuestionMapper paperQuestionMapper) {
        this.paperQuestionMapper = paperQuestionMapper;
    }

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

    /**
     * 新增数据
     *
     * @param paperQuestion 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmPaperQuestion insert(ZccmPaperQuestion paperQuestion) {
        this.paperQuestionMapper.insert(paperQuestion);
        return paperQuestion;
    }

    /**
     * 修改数据
     *
     * @param paperQuestion 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmPaperQuestion update(ZccmPaperQuestion paperQuestion) {
        this.paperQuestionMapper.updateByPrimaryKeySelective(paperQuestion);
        return this.queryById(paperQuestion.getPaperRuleId());
    }

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

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

    @Override
    public List<ZccmPaperQuestion> queryByPaperId(Integer paperId) {
        return this.paperQuestionMapper.queryByPaperId(paperId);
    }
}