package cn.com.ctop.job.bytedance.handler;

import cn.com.ctop.toutiao.modules.link.entity.ETLReportBytedanceVideo;
import cn.com.ctop.toutiao.modules.material.service.IEtlBytedanceVideoInfoService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 头条视频报表etl剪辑员信息二次再刷新
 * @author 黄学超
 */
public class BytedanceVideoETLReportReloadJob {
    static ExecutorService executorService = Executors.newFixedThreadPool(5);
    @Autowired
    private IEtlBytedanceVideoInfoService iEtlBytedanceVideoInfoService;

    //TODO 待删除
    @XxlJob("bytedanceETLReportData")
    public void execute() throws Exception {
        //查询素材归属表所有的信息md5,clip_id,clip_name,shot_id,shot_name,plan_id,plan_name
        List<ETLReportBytedanceVideo> etlReportBytedanceVideoList = iEtlBytedanceVideoInfoService.selectAllETLReportBytedanceVideo();
        if (null == etlReportBytedanceVideoList || etlReportBytedanceVideoList.isEmpty()) {
            XxlJobHelper.log("定时获取头条报表数据异常：未获取到素材归属信息");
            XxlJobHelper.handleFail();
            return ;
        }
        //动态sql更新md5,clip_id,clip_name,shot_id,shot_name,plan_id,plan_name不为空的数据
        etlReportBytedanceVideoList.forEach(etlReportBytedanceVideo -> executorService.submit(() -> iEtlBytedanceVideoInfoService.updateETLReportNameIsNull(etlReportBytedanceVideo)));
    }
}
