package com.hc.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.business.mapper.ZccmQuestionTypeMapper;
import com.hc.business.model.ZccmQuestionType;
import com.hc.business.service.ZccmQuestionTypeService;
import org.springframework.stereotype.Service;

/**
 * 问题类型表(ZccmQuestionType)表服务实现类
 *
 * @author java
 * @since 2020-12-07 11:37:03
 */

@Service("questionTypeService")
public class ZccmQuestionTypeServiceImpl implements ZccmQuestionTypeService {

    private final ZccmQuestionTypeMapper questionTypeMapper;

    public ZccmQuestionTypeServiceImpl(ZccmQuestionTypeMapper questionTypeMapper) {
        this.questionTypeMapper = questionTypeMapper;
    }

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

    /**
     * 新增数据
     *
     * @param questionType 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmQuestionType insert(ZccmQuestionType questionType) {
        this.questionTypeMapper.insert(questionType);
        return questionType;
    }

    /**
     * 修改数据
     *
     * @param questionType 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmQuestionType update(ZccmQuestionType questionType) {
        this.questionTypeMapper.updateByPrimaryKeySelective(questionType);
        return this.queryById(questionType.getTypeId());
    }

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

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