package com.platform.modules.live.task;

import com.platform.common.utils.DateUtils;
import com.platform.common.utils.RedisUtils;
import com.platform.modules.live.constants.SceneConstants;
import com.platform.modules.live.entity.LiveSceneEntity;
import com.platform.modules.live.service.LiveSceneService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @author Matt
 * 2021/4/19 11:30
 */
@Component("autoLiveTask")
public class AutoLiveTask {

    @Autowired
    private LiveSceneService liveSceneService;

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private RedisUtils redisUtils;

    public void AutoLiveTask(){

        logger.info("现场自动开关播定时刷新任务，刷新时间为：" + DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN));

        List<LiveSceneEntity> dataList = liveSceneService.freshLiveStateByAutoLive();

        if (dataList != null && dataList.size() > 0) {
            dataList.forEach(e -> {
                liveSceneService.createSceneIndex(e, null, null, null, null, null);
                redisUtils.delete(SceneConstants.SCENE_REDIS_PREFIX + e.getId());
            });
        }
    }
}
