package com.hc.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.business.mapper.ZccmBannerMapper;
import com.hc.business.model.ZccmBanner;
import com.hc.business.service.ZccmBannerService;
import org.springframework.stereotype.Service;

/**
 * 广告表
 * (ZccmBanner)表服务实现类
 *
 * @author java
 * @since 2020-11-26 09:29:52
 */

@Service("bannerService")
public class ZccmBannerServiceImpl implements ZccmBannerService {

    private final ZccmBannerMapper bannerMapper;

    public ZccmBannerServiceImpl(ZccmBannerMapper bannerMapper) {
        this.bannerMapper = bannerMapper;
    }

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

    /**
     * 新增数据
     *
     * @param banner 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmBanner insert(ZccmBanner banner) {
        this.bannerMapper.insert(banner);
        return banner;
    }

    /**
     * 修改数据
     *
     * @param banner 实例对象
     * @return 实例对象
     */
    @Override
    public ZccmBanner update(ZccmBanner banner) {
        this.bannerMapper.updateByPrimaryKeySelective(banner);
        return this.queryById(banner.getBannerId());
    }

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

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