package com.hai.service.impl;

import com.hai.dao.HighCouponCodeOtherMapper;
import com.hai.entity.HighCouponCodeOther;
import com.hai.entity.HighCouponCodeOtherExample;
import com.hai.service.HighCouponCodeOtherService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;

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

@Service("highCouponCodeOtherService")
public class HighCouponCodeOtherServiceImpl implements HighCouponCodeOtherService {

    @Resource
    private HighCouponCodeOtherMapper highCouponCodeOtherMapper;

    @Override
    public List<HighCouponCodeOther> getList(Map<String, Object> map) {
        HighCouponCodeOtherExample example = new HighCouponCodeOtherExample();
        HighCouponCodeOtherExample.Criteria criteria = example.createCriteria();

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

        if (MapUtils.getLong(map,"orderId") != null) {
            criteria.andOrderIdEqualTo(MapUtils.getLong(map,"orderId"));
        }

        if (MapUtils.getInteger(map,"childOrderId") != null) {
            criteria.andChildOrderIdEqualTo(MapUtils.getLong(map,"childOrderId"));
        }
        return highCouponCodeOtherMapper.selectByExample(example);
    }

    @Override
    public HighCouponCodeOther getDetailByCouponAgentCodeId(Long couponAgentCodeId) {
        HighCouponCodeOtherExample example = new HighCouponCodeOtherExample();
        example.createCriteria().andCouponAgentCodeIdEqualTo(couponAgentCodeId);
        List<HighCouponCodeOther> list = highCouponCodeOtherMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
