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.SsmCollectionTypeDao;
import com.ssm.manage.entity.BaseCollectionType;
import com.ssm.manage.mapper.BaseCollectionTypeMapper;
import com.ssm.manage.query.CollectionTypeRequest;
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 SsmCollectionTypeDaoImpl extends BaseDaoImpl<BaseCollectionType> implements SsmCollectionTypeDao {
    @Autowired
    private BaseCollectionTypeMapper mapper;

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

    @Override
    public PageInfo<BaseCollectionType> selectPage(CollectionTypeRequest collectionTypeRequest) {
        Example example = new Example(BaseCollectionType.class);
        Example.Criteria criteria =  example.createCriteria();
        if (StringUtils.isNotBlank(collectionTypeRequest.getCollectionType())){
            criteria.andLike("collectionType","%" + collectionTypeRequest.getCollectionType() + "%");
        }
        if (StringUtils.isNotBlank(collectionTypeRequest.getCollectionTypeName())){
            criteria.andLike("collectionTypeName","%" + collectionTypeRequest.getCollectionTypeName() + "%");
        }
        criteria.andEqualTo("state",collectionTypeRequest.getState());
        PageHelper.startPage(collectionTypeRequest.getPageNum(),collectionTypeRequest.getPageSize(),collectionTypeRequest.getOrderAndSort());
        List<BaseCollectionType> list = mapper.selectByExample(example);
        PageInfo<BaseCollectionType> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
