package com.hfkj.service.discount.impl;

import com.hfkj.dao.CouponDiscountUserRelMapper;
import com.hfkj.entity.CouponDiscountExample;
import com.hfkj.entity.CouponDiscountUserRel;
import com.hfkj.entity.CouponDiscountUserRelExample;
import com.hfkj.service.discount.CouponDiscountUserRelService;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

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

@Service("couponDiscountUserRelService")
public class CouponDiscountUserRelServiceImpl implements CouponDiscountUserRelService {

    @Resource
    private CouponDiscountUserRelMapper couponDiscountUserRelMapper;

    @Override
    public void create(CouponDiscountUserRel couponDiscountUserRel) {
        couponDiscountUserRelMapper.insert(couponDiscountUserRel);
    }

    @Override
    public void update(CouponDiscountUserRel couponDiscountUserRel) {
        couponDiscountUserRelMapper.updateByPrimaryKey(couponDiscountUserRel);
    }

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

        if (MapUtils.getInteger(map, "userId") != null) {
            criteria.andUserIdEqualTo(MapUtils.getLong(map, "userId"));
        }

        if (MapUtils.getInteger(map, "status") != null) {
            criteria.andStatusEqualTo(MapUtils.getInteger(map, "status"));
        }
        if (MapUtils.getLong(map, "discountId") != null) {
            criteria.andDiscountIdEqualTo(MapUtils.getLong(map, "discountId"));
        }
        if (MapUtils.getInteger(map, "platformCode") != null) {
            criteria.andPlatformCodeEqualTo(MapUtils.getString(map, "platformCode"));
        }

        return couponDiscountUserRelMapper.selectByExample(example);
    }

    @Override
    public CouponDiscountUserRel getRel(Long id) {
        return couponDiscountUserRelMapper.selectByPrimaryKey(id);
    }

    @Override
    public CouponDiscountUserRel getRel(Map<String, Object> map) {
        CouponDiscountUserRelExample example = new CouponDiscountUserRelExample();
        CouponDiscountUserRelExample.Criteria criteria = example.createCriteria();


        if (MapUtils.getInteger(map, "userId") != null) {
            criteria.andUserIdEqualTo(MapUtils.getLong(map, "userId"));
        }
        if (MapUtils.getInteger(map, "discountId") != null) {
            criteria.andDiscountIdEqualTo(MapUtils.getLong(map, "discountId"));
        }

        if (MapUtils.getInteger(map, "status") != null) {
            criteria.andStatusEqualTo(MapUtils.getInteger(map, "status"));
        }
        return null;
    }


}
