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.SsmRechargeDemotioneingRunDao;
import com.ssm.manage.entity.RechargeDemotioneingRun;
import com.ssm.manage.mapper.RechargeDemotioneingRunMapper;
import com.ssm.manage.query.RechargeDemotioneingRunRequest;
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 SsmRechargeDemotioneingRunDaoImpl extends BaseDaoImpl<RechargeDemotioneingRun> implements SsmRechargeDemotioneingRunDao {
    @Autowired
    private RechargeDemotioneingRunMapper mapper;

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

    @Override
    public PageInfo<RechargeDemotioneingRun> selectByPage(RechargeDemotioneingRunRequest runRequest) {
        Example example = new Example(RechargeDemotioneingRun.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("rechargeTypeId",runRequest.getRechargeTypeId());
        criteria.andEqualTo("storeId",runRequest.getStoreId());
        criteria.andEqualTo("type",runRequest.getType());
        criteria.andEqualTo("status",runRequest.getStatus());
        PageHelper.startPage(runRequest.getPageNum(),runRequest.getPageSize(),runRequest.getOrderAndSort());
        List<RechargeDemotioneingRun> list = mapper.selectByExample(example);
        PageInfo<RechargeDemotioneingRun> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
    @Override
    public List<RechargeDemotioneingRun> selectListChongFu(RechargeDemotioneingRunRequest runRequest) {
        Example example = new Example(RechargeDemotioneingRun.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("rechargeTypeId",runRequest.getRechargeTypeId());
        criteria.andEqualTo("storeId",runRequest.getStoreId());
        criteria.andEqualTo("newRechargeTypeId",runRequest.getNewRechargeTypeId());
        PageHelper.startPage(runRequest.getPageNum(),runRequest.getPageSize(),runRequest.getOrderAndSort());
        List<RechargeDemotioneingRun> list = mapper.selectByExample(example);
        return list;
    }

    @Override
    public PageInfo<RechargeDemotioneingRun> selectByPages(RechargeDemotioneingRunRequest runRequest) {
        Example example = new Example(RechargeDemotioneingRun.class);
        Example.Criteria criteria = example.createCriteria();
//        criteria.andEqualTo("rechargeTypeId",runRequest.getRechargeTypeId());
        criteria.andEqualTo("storeId",runRequest.getStoreId());
//        criteria.andEqualTo("type",runRequest.getType());
        if(null !=runRequest.getRechargeTypeId()){
            criteria.andEqualTo("RechargeTypeId",runRequest.getRechargeTypeId());
        }
        PageHelper.startPage(runRequest.getPageNum(),runRequest.getPageSize(),runRequest.getOrderAndSort());
        List<RechargeDemotioneingRun> list = mapper.selectByExample(example);
        PageInfo<RechargeDemotioneingRun> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

}
