package com.tmerclub.cloud.product.feign;

import com.tmerclub.cloud.api.product.feign.GiveawayFeignClient;
import com.tmerclub.cloud.common.constant.StatusEnum;
import com.tmerclub.cloud.common.product.vo.GiveawayVO;
import com.tmerclub.cloud.product.service.GiveawayService;
import com.tmerclub.cloud.product.service.GiveawaySpuService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Objects;
/**
 * @author lanhai
 */
@DubboService
public class GiveawayFeignController implements GiveawayFeignClient {
    @Autowired
    private GiveawayService giveawayService;
    @Autowired
    private GiveawaySpuService giveawaySpuService;

    @Override
    public void changeGiveawayStatus(Long spuId) {
        GiveawayVO giveawayVO = giveawayService.getBySpuId(spuId);
        if (Objects.nonNull(giveawayVO)) {
            giveawayService.changeStatus(giveawayVO.getGiveawayId(), StatusEnum.DISABLE.value());
        }
    }

    @Override
    public void changeGiveawaySpuStatus(Long spuId) {
        //赠送商品则清除缓存
        List<Long> spuIds = giveawayService.listMainSpuIdByGiveawaySpuId(spuId);
        giveawaySpuService.removeGiveawayCacheBatch(spuIds);

    }
}
