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.core.mapper.BaseMapper;
import com.ssm.manage.dao.SsmSysRoleUserDao;
import com.ssm.manage.dao.SsmTopUpPromotionDao;
import com.ssm.manage.entity.SysRoleUser;
import com.ssm.manage.entity.SysUser;
import com.ssm.manage.entity.TopUpPromotion;
import com.ssm.manage.mapper.SysUserMapper;
import com.ssm.manage.mapper.TopUpPromotionMapper;
import com.ssm.manage.query.TopUpPromotionRequest;
import com.ssm.manage.query.UserRequest;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Component
public class SsmTopUpPromotionDaoImpl  extends BaseDaoImpl<TopUpPromotion> implements SsmTopUpPromotionDao {

    @Autowired
    public TopUpPromotionMapper mapper;

    @Override
    protected BaseMapper<TopUpPromotion> getMapper() {
        return mapper;
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public PageInfo<TopUpPromotion> selectByPage(TopUpPromotionRequest topUpPromotionRequest) {
        Example example = new Example(SysUser.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(topUpPromotionRequest.getPromotionNum())){
            criteria.andLike("promotionNum","%" + topUpPromotionRequest.getPromotionNum() + "%");
        }
        if (StringUtils.isNotBlank(topUpPromotionRequest.getPromotionName())){
            criteria.andLike("promotionName","%" + topUpPromotionRequest.getPromotionName() + "%");
        }
//        if (StringUtils.isNotBlank(userRequest.getUserNum())){
//            criteria.andLike("userNum","%" + userRequest.getUserNum() + "%");
//        }
        criteria.andEqualTo("state",topUpPromotionRequest.getState());
//        if (StringUtils.isNotBlank(userRequest.getQq())){
//            criteria.orLike("qq","%" + userRequest.getQq() + "%");
//        }
//        if (StringUtils.isNotBlank(userRequest.getWechat())){
//            criteria.orLike("weChat","%"+ userRequest.getWechat() + "%");
//        }
//        if (StringUtils.isNotBlank(userRequest.getMailbox())){
//            criteria.orLike("mailBox","%" + userRequest.getMailbox() + "%");
//        }
        PageHelper.startPage(topUpPromotionRequest.getPageNum(),topUpPromotionRequest.getPageSize(),topUpPromotionRequest.getOrderAndSort());
        List<TopUpPromotion> list = mapper.selectByExample(example);
        PageInfo<TopUpPromotion> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
