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.SsmMemberDao;
import com.ssm.manage.entity.MemberList;
import com.ssm.manage.mapper.MemberListMapper;
import com.ssm.manage.query.MemberRequest;
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 SsmMemberDaoImpl extends BaseDaoImpl<MemberList> implements SsmMemberDao {
    @Autowired
    private MemberListMapper mapper;

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

    @Override
    public PageInfo<MemberList> selectPage(MemberRequest memberRequest) {
        Example example = new Example(MemberList.class);
        Example.Criteria criteria = example.createCriteria();
        if (memberRequest.getState() != null){
            criteria.andEqualTo("state",memberRequest.getState());
        }
        PageHelper.startPage(memberRequest.getPageNum(),memberRequest.getPageSize(),memberRequest.getOrderAndSort());
        List<MemberList> lists = selectByExample(example);
        PageInfo<MemberList> pageInfo = new PageInfo<>(lists);
        return pageInfo;
    }
}
