package com.hc.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.business.mapper.ZccmCourseChapterTestMapper;
import com.hc.business.model.ZccmCourseChapterTest;
import com.hc.business.service.ZccmCourseChapterTestService;
import org.springframework.stereotype.Service;

/**
 * 章节测试表/随堂练习表(ZccmCourseChapterTest)表服务实现类
 *
 * @author java
 * @since 2020-11-09 10:04:53
 */

@Service("courseChapterTestService")
public class ZccmCourseChapterTestServiceImpl implements ZccmCourseChapterTestService {

    private final ZccmCourseChapterTestMapper courseChapterTestMapper;

    public ZccmCourseChapterTestServiceImpl(ZccmCourseChapterTestMapper courseChapterTestMapper) {
        this.courseChapterTestMapper = courseChapterTestMapper;
    }

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

    /**
     * 新增数据
     *
     * @param courseChapterTest 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmCourseChapterTest insert(ZccmCourseChapterTest courseChapterTest) {
        this.courseChapterTestMapper.insert(courseChapterTest);
        return courseChapterTest;
    }

    /**
     * 修改数据
     *
     * @param courseChapterTest 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmCourseChapterTest update(ZccmCourseChapterTest courseChapterTest) {
        this.courseChapterTestMapper.updateByPrimaryKeySelective(courseChapterTest);
        return this.queryById(courseChapterTest.getTestId());
    }

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

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