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.SsmStoreMemberPhoneDao;
import com.ssm.manage.entity.StoreMemberPhone;
import com.ssm.manage.mapper.StoreMemberPhoneMapper;
import com.ssm.manage.query.StoreMemberPhoneRequest;
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 SsmStoreMemberPhoneDaoImpl extends BaseDaoImpl<StoreMemberPhone> implements SsmStoreMemberPhoneDao {
    @Autowired
    private StoreMemberPhoneMapper mapper;

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

    @Override
    public PageInfo<StoreMemberPhone> selectPage(StoreMemberPhoneRequest memberPhoneRequest) {
        Example example = new Example(StoreMemberPhone.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("storeId",memberPhoneRequest.getStoreId());
        if (StringUtils.isNotBlank(memberPhoneRequest.getMemberName())){
            criteria.andLike("memberName","%" + memberPhoneRequest.getMemberName() + "%");
        }
        if (StringUtils.isNotBlank(memberPhoneRequest.getOldPhone())){
            criteria.andEqualTo("oldPhone", memberPhoneRequest.getOldPhone());
        }
        if (StringUtils.isNotBlank(memberPhoneRequest.getSource())){
            criteria.andEqualTo("source", memberPhoneRequest.getSource());
        }
        PageHelper.startPage(memberPhoneRequest.getPageNum(),memberPhoneRequest.getPageSize(),memberPhoneRequest.getOrderAndSort());
        List<StoreMemberPhone> list = selectByExample(example);
        PageInfo<StoreMemberPhone> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
