package com.ssm.manage.dao.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.core.impl.BaseDaoImpl;
import com.ssm.manage.dao.SsmImgMaintainDao;
import com.ssm.manage.entity.ImgMaintain;
import com.ssm.manage.mapper.ImgMaintainMapper;
import com.ssm.manage.query.ImgMaintainRequest;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Component
public class SsmImgMaintainDaoImpl extends BaseDaoImpl<ImgMaintain> implements SsmImgMaintainDao {
    @Autowired
    private ImgMaintainMapper mapper;

    @Override
    public ImgMaintainMapper getMapper() {
        return mapper;
    }

    @Override
    public PageInfo<ImgMaintain> page(ImgMaintainRequest imgMaintainRequest) {
        Example example = new Example(ImgMaintain.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(imgMaintainRequest.getFileName())) {
            criteria.andLike("fileName", '%' + imgMaintainRequest.getFileName() + "%");
        }
        if (imgMaintainRequest.getType() != 0) {
            criteria.andEqualTo("type", imgMaintainRequest.getType());
        }
        PageHelper.startPage(imgMaintainRequest.getPageNum(), imgMaintainRequest.getPageSize(), imgMaintainRequest.getOrderAndSort());
        List<ImgMaintain> list = mapper.selectByExample(example);
        PageInfo<ImgMaintain> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
