package com.hc.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.business.mapper.ZccmQrAccessoryMapper;
import com.hc.business.model.ZccmQrAccessory;
import com.hc.business.service.ZccmQrAccessoryService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 二维码扫码附件表(ZccmQrAccessory)表服务实现类
 *
 * @author makejava
 * @since 2024-11-08 09:46:39
 */

@Service("zccmQrAccessoryService")
public class ZccmQrAccessoryServiceImpl implements ZccmQrAccessoryService {

    private final ZccmQrAccessoryMapper zccmQrAccessoryMapper;

    public ZccmQrAccessoryServiceImpl(ZccmQrAccessoryMapper zccmQrAccessoryMapper) {
        this.zccmQrAccessoryMapper = zccmQrAccessoryMapper;
    }

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

    /**
     * 新增数据
     *
     * @param zccmQrAccessory 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmQrAccessory insert(ZccmQrAccessory zccmQrAccessory) {
        this.zccmQrAccessoryMapper.insert(zccmQrAccessory);
        return zccmQrAccessory;
    }

    /**
     * 修改数据
     *
     * @param zccmQrAccessory 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmQrAccessory update(ZccmQrAccessory zccmQrAccessory) {
        this.zccmQrAccessoryMapper.updateByPrimaryKeySelective(zccmQrAccessory);
        return this.queryById(zccmQrAccessory.getQrId());
    }

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

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

    @Override
    public PageInfo queryByAll(int page, int size,Integer courseId,
                               Integer qrIndex,
                               Integer qrType,
                               Integer chapterId,
                               String fileName) {
        return PageHelper.startPage(page, size).doSelectPageInfo(() -> this.zccmQrAccessoryMapper.queryByAll(courseId,qrIndex,qrType,chapterId,fileName));
    }
}
