
package com.tmerclub.cloud.user.task;

import cn.hutool.core.collection.CollUtil;
import com.tmerclub.cloud.user.service.CostPerPopupService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 弹窗广告定时任务
 * @author TRACK
 */
@Component
public class PopupTask {

    private static final Logger log = LoggerFactory.getLogger(PopupTask.class);

    @Autowired
    private CostPerPopupService costPerPopupService;

    /**
     * 改变弹窗广告状态
     * 半小时执行一次
     */
    @XxlJob("changePopup")
    public void changePopup() {
        log.info("改变弹窗广告状态");
        // 需要投放的弹窗广告
        List<Long> putOnIds = costPerPopupService.putOnAdvertise();
        // 需要结束的弹窗广告
        List<Long> endIds = costPerPopupService.endAdvertise();
        putOnIds.addAll(endIds);
        if (CollUtil.isNotEmpty(putOnIds)) {
            costPerPopupService.removeCacheBatch(putOnIds);
        }
    }
}
