package com.hfkj.service.recharge.impl;

import com.hfkj.dao.RechargePriceMapper;
import com.hfkj.entity.BsOrderGoods;
import com.hfkj.entity.RechargePrice;
import com.hfkj.entity.RechargePriceExample;
import com.hfkj.service.recharge.PriceService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service("priceService")
public class PriceServiceImpl implements PriceService {

    @Resource
    private RechargePriceMapper rechargePriceMapper;

    @Override
    public void create(RechargePrice rechargePrice) {
        rechargePriceMapper.insert(rechargePrice);
    }

    @Override
    public void update(RechargePrice rechargePrice) {
        rechargePriceMapper.updateByPrimaryKeySelective(rechargePrice);
    }

    @Override
    public void delete(Long id, Boolean fullDelete) {
        if (fullDelete) {
            rechargePriceMapper.deleteByPrimaryKey(id);
        } else {
            RechargePrice rechargePrice = queryDetail(id);
            rechargePrice.setStatus(0);
            rechargePrice.setUpdateTime(new Date());
            update(rechargePrice);
        }
    }

    @Override
    public RechargePrice queryDetail(Long id) {
        return rechargePriceMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<RechargePrice> getList(Map<String, Object> map) {

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

        if (MapUtils.getInteger(map, "type") != null) {
            criteria.andTypeEqualTo(MapUtils.getInteger(map, "type"));
        }



        return rechargePriceMapper.selectByExample(example);
    }
}
