package com.hai.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.hai.common.utils.DateUtil;
import com.hai.dao.BsIntegralRebateMapper;
import com.hai.entity.BsIntegralRebate;
import com.hai.entity.BsIntegralRebateExample;
import com.hai.entity.HighOrder;
import com.hai.entity.OutRechargeOrder;
import com.hai.service.*;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("bsIntegralRebateService")
public class BsIntegralRebateServiceImpl implements BsIntegralRebateService {

    @Resource
    private BsIntegralRebateMapper bsIntegralRebateMapper;

    @Resource
    private HighUserService highUserService;

    @Resource
    private HighOrderService highOrderService;

    @Resource
    private OutRechargeOrderService outRechargeOrderService;

    @Resource
    private BsDistributionUserRelService bsDistributionUserRelService;

    @Override
    public BsIntegralRebate findIntegralRebateByMap(Map<String, Object> map) {

        BsIntegralRebateExample example = new BsIntegralRebateExample();
        BsIntegralRebateExample.Criteria criteria = example.createCriteria();

        if (MapUtils.getInteger(map , "type") != null) {
            criteria.andTypeEqualTo(MapUtils.getInteger(map , "type"));
        }
        if (MapUtils.getLong(map , "companyId") != null) {
            criteria.andCompanyIdEqualTo(MapUtils.getLong(map , "companyId"));
        }
        if (MapUtils.getInteger(map , "status") != null) {
            criteria.andStatusEqualTo(MapUtils.getInteger(map , "status"));
        }

        List<BsIntegralRebate> list = bsIntegralRebateMapper.selectByExample(example);

        if (list.size() > 0) {
           return bsIntegralRebateMapper.selectByExample(example).get(0);
        }

        return null;
    }

    @Override
    public BsIntegralRebate findIntegralRebateById(Long id) {
        return bsIntegralRebateMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<BsIntegralRebate> getIntegralRebateByList(Map<String, Object> map) {
        BsIntegralRebateExample example = new BsIntegralRebateExample();
        BsIntegralRebateExample.Criteria criteria = example.createCriteria();

        if (MapUtils.getInteger(map , "type") != null) {
            criteria.andTypeEqualTo(MapUtils.getInteger(map , "type"));
        }
        if (MapUtils.getLong(map , "companyId") != null) {
            criteria.andCompanyIdEqualTo(MapUtils.getLong(map , "companyId"));
        }
        if (MapUtils.getLong(map , "productId") != null) {
            criteria.andProductIdEqualTo(MapUtils.getLong(map , "productId"));
        }
        return bsIntegralRebateMapper.selectByExample(example);
    }

    @Override
    public void insertIntegralRebate(BsIntegralRebate bsIntegralRebate) {
        bsIntegralRebateMapper.insert(bsIntegralRebate);
    }

    @Override
    public void updateIntegralRebate(BsIntegralRebate bsIntegralRebate) {
        bsIntegralRebateMapper.updateByPrimaryKeySelective(bsIntegralRebate);
    }

    @Override
    public void deleteIntegralRebate(Long id) {
        bsIntegralRebateMapper.deleteByPrimaryKey(id);
    }


}
