package com.dgtis.dorm.manager.db.service;

import com.github.pagehelper.PageHelper;
import com.dgtis.dorm.manager.db.dao.BannerMapper;
import com.dgtis.dorm.manager.db.domain.Banner;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BannerService {

    @Resource
    private BannerMapper bannerMapper;


    /**
     * 分页获取 banner 列表
     */
    public List<Banner> querySelective(Banner banner, int page, int limit, String sort) {

        List<Banner> lstBanner = null;
        PageHelper.startPage(page, limit);
        lstBanner = bannerMapper.selectByExample(banner);

        return lstBanner;
    }

    /**
     * 获取banner列表数量
     */
    public Integer countSelective(Banner banner) {

        int total = (int)bannerMapper.countByExample(banner);
        return total;
    }

    /**
     * 获取指定id的banner详情
     */
    public Banner findById(Integer id) {

        Banner banner = bannerMapper.selectByPrimaryKey(id);
        return banner;
    }

    /**
     * 录入banner信息
     */
    public void add(Banner banner) {
        bannerMapper.insertSelective(banner);
    }

    /**
     * 更新banner信息
     */
    public void update(Banner banner) {
        bannerMapper.updateByPrimaryKeySelective(banner);
    }

    /**
     * 删除banner信息
     */
    public void delete(int id) {
        bannerMapper.deleteByPrimaryKey(id);
    }
}
