package com.hai.service.impl;

import com.hai.dao.HighDiscountPackageDetailsMapper;
import com.hai.entity.HighDiscount;
import com.hai.entity.HighDiscountPackage;
import com.hai.entity.HighDiscountPackageDetails;
import com.hai.entity.HighDiscountPackageDetailsExample;
import com.hai.service.HighDiscountPackageDetailsService;
import com.hai.service.HighDiscountService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;

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

/**
 * @serviceName HighDiscountPackageDetailsServiceImpl.java
 * @author Sum1Dream
 * @version 1.0.0
 * @Description // 优惠券详情服务
 * @createTime 3:38 下午 2021/11/25
 **/
@Service("highDiscountPackageDetailsService")
public class HighDiscountPackageDetailsServiceImpl implements HighDiscountPackageDetailsService {

    @Resource
    private HighDiscountPackageDetailsMapper highDiscountPackageDetailsMapper;

    @Override
    public List<HighDiscountPackageDetails> getDiscountPackageDetailsList(Map<String, Object> map) {

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

        if (MapUtils.getInteger(map, "discountPackageId") != null) {
            criteria.andDiscountPackageIdEqualTo(MapUtils.getInteger(map, "discountPackageId"));
        }
        if (MapUtils.getInteger(map, "discountId") != null) {
            criteria.andDiscountIdEqualTo(MapUtils.getInteger(map, "discountId"));
        }

        criteria.andStatusEqualTo(1);

        return highDiscountPackageDetailsMapper.selectByExample(example);
    }

    @Override
    public HighDiscountPackageDetails findDetailsById(Integer id) {
        return highDiscountPackageDetailsMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<HighDiscountPackageDetails> getDetailByPackage(Integer packageId) {
        HighDiscountPackageDetailsExample example = new HighDiscountPackageDetailsExample();
        example.createCriteria().andStatusNotEqualTo(0).andDiscountPackageIdEqualTo(packageId);
        return highDiscountPackageDetailsMapper.selectByExample(example);
    }

    @Override
    public void insertDiscountPackageDetails(HighDiscountPackageDetails highDiscountPackageDetails) {
        highDiscountPackageDetailsMapper.insert(highDiscountPackageDetails);
    }

    @Override
    public void updateDiscountPackageDetails(HighDiscountPackageDetails highDiscountPackageDetails) {
        highDiscountPackageDetailsMapper.updateByPrimaryKey(highDiscountPackageDetails);
    }

}
