package com.hai.openApi.service.impl;

import com.hai.dao.ApiBlxCouponMapper;
import com.hai.entity.ApiBlxCoupon;
import com.hai.entity.ApiBlxCouponExample;
import com.hai.openApi.service.ApiBlxCouponService;
import org.springframework.stereotype.Service;

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

@Service("apiBlxCouponService")
public class ApiBlxCouponServiceImpl implements ApiBlxCouponService {

    @Resource
    private ApiBlxCouponMapper apiBlxCouponMapper;

    @Override
    public void insertBlxCoupon(ApiBlxCoupon apiBlxCoupon) {
        apiBlxCouponMapper.insert(apiBlxCoupon);
    }

    @Override
    public void editBlxCoupon(ApiBlxCoupon apiBlxCoupon) {
        apiBlxCouponMapper.updateByPrimaryKey(apiBlxCoupon);
    }

    @Override
    public ApiBlxCoupon findBlxCoupon(String couponCode) {
        ApiBlxCouponExample example = new ApiBlxCouponExample();
        ApiBlxCouponExample.Criteria criteria = example.createCriteria();

        criteria.andCouponCodeEqualTo(couponCode);

        List<ApiBlxCoupon> apiBlxCoupons = apiBlxCouponMapper.selectByExample(example);

        if (apiBlxCoupons.size() > 0) {
            return apiBlxCoupons.get(0);
        }

        return null;
    }

    @Override
    public List<ApiBlxCoupon> getBlxCouponList(Map<String, Object> map) {

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

        criteria.andCouponStatusEqualTo(1);

        return apiBlxCouponMapper.selectByExample(example);
    }
}
