package com.iamberry.wechat.service.eo;
import com.iamberry.wechat.core.entity.eo.Promotions;
import com.iamberry.wechat.core.entity.eo.SettlementGift;
import com.iamberry.wechat.core.entity.eo.Spike;
import com.iamberry.wechat.face.eo.PromotionsService;
import com.iamberry.wechat.face.eo.SettlementGiftService;
import com.iamberry.wechat.face.eo.SpikeService;
import com.iamberry.wechat.service.mapper.PromotionsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  优惠活动接口
 * @author Administrator
 * @Date 2019-10-21
 */
@Service
public class PromotionsServiceImpl  implements PromotionsService {
    @Autowired
    private PromotionsMapper promotionsMapper;

    @Autowired
    private SettlementGiftService settlementGiftService;
    @Autowired
    private SpikeService spikeService;
    /**
     * 获取集合
     * @param  promotions
     * @return List
     */
    @Override
    public List<Promotions> getPromotionsList(Promotions  promotions){
        return  promotionsMapper.getPromotionsList(promotions);
    }

    @Override
    public Promotions getPromotionsListByTime() {
        Promotions promotions = new Promotions();
        //获取当前时间所有活动
        List<Promotions> promotionsList = promotionsMapper.getPromotionsListByTime();
        int[] str = new int[promotionsList.size()];
        for (int i = 0; i < promotionsList.size(); i++) {
            str[i] = promotionsList.get(i).getPromotionsId();
        }
        if(str == null || str.length == 0){
            return promotions;
        }
        //获取当前活动的所有满赠
        List<SettlementGift> settlementGiftList = settlementGiftService.getSettlementGiftListAll(str);
        promotions.setSettlementGiftList(settlementGiftList);

        //获取当前活动所有秒杀
        List<Spike> spikeList = spikeService.getSpikeListAll(str);
        promotions.setSpikeList(spikeList);

        //获取当前活动所有满减
        return promotions;
    }

    /**
     * 查询单条数据
     * @param  id
     * @return  promotions
     */
    @Override
    public  Promotions  getPromotionsById(Integer  id){
        return  promotionsMapper.getPromotionsById(id);
    }
}
