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.SsmModifyRechargeRecordDao;
import com.ssm.manage.entity.ModifyRechargeRecord;
import com.ssm.manage.mapper.ModifyRechargeRecordMapper;
import com.ssm.manage.query.ModifyRechargeRecordRequest;
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 SsmModifyRechargeRecordDaoImpl extends BaseDaoImpl<ModifyRechargeRecord> implements SsmModifyRechargeRecordDao {
    @Autowired
    private ModifyRechargeRecordMapper mapper;

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

    @Override
    public PageInfo<ModifyRechargeRecord> selectPage(ModifyRechargeRecordRequest modifyRechargeRecordRequest) {
        Example example = new Example(ModifyRechargeRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("storeId", modifyRechargeRecordRequest.getStoreId());
        if (null != modifyRechargeRecordRequest.getMemberId()){
            criteria.andEqualTo("memberId", modifyRechargeRecordRequest.getMemberId());
        }
        if (StringUtils.isNotBlank(modifyRechargeRecordRequest.getRechargeTypeName())){
            criteria.andLike("rechargeTypeName", "%" + modifyRechargeRecordRequest.getRechargeTypeName() + "%");
        }
        PageHelper.startPage(modifyRechargeRecordRequest.getPageNum(), modifyRechargeRecordRequest.getPageSize(), modifyRechargeRecordRequest.getOrderAndSort());
        List<ModifyRechargeRecord> list = selectByExample(example);
        PageInfo<ModifyRechargeRecord> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
