package com.ssm.manage.dao.impl;

import com.github.pagehelper.PageInfo;
import com.ssm.core.impl.BaseDaoImpl;
import com.ssm.manage.dao.SsmStoreMemberFileDao;
import com.ssm.manage.entity.StoreMemberFile;
import com.ssm.manage.mapper.StoreMemberFileMapper;
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 SsmStoreMemberFileDaoImpl extends BaseDaoImpl<StoreMemberFile> implements SsmStoreMemberFileDao {
    @Autowired
    private StoreMemberFileMapper mapper;

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

    @Override
    public PageInfo<StoreMemberFile> selectPage(StoreMemberPhoneRequest memberFileRequest) {
        Example example = new Example(StoreMemberFile.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("storeId",memberFileRequest.getStoreId());
        if (StringUtils.isNotBlank(memberFileRequest.getMemberName())){
            criteria.andLike("memberName","%" + memberFileRequest.getMemberName() + "%");
        }
        if (StringUtils.isNotBlank(memberFileRequest.getOldPhone())){
            criteria.andEqualTo("oldPhone", memberFileRequest.getOldPhone());
        }
        List<StoreMemberFile> list = selectByExample(example);
        PageInfo<StoreMemberFile> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
