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

import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.toutiao.modules.report.service.IBytedanceCreativeDailyReportService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

/**
 * 清洗素材报表
 *
 * @author 宋英豪
 */
@Component
public class ByteDanceCleanMaterialJob {
    @Autowired
    private IBytedanceCreativeDailyReportService creativeDailyReportService;
    static ExecutorService executorService = Executors.newFixedThreadPool(3);

    @XxlJob("byteDanceCleanMaterial")
    public void execute() throws Exception {
        List<String> signatureList = creativeDailyReportService.getSignatureList();
        if (Check.isNull(signatureList)) {
            XxlJobHelper.log("头条素材数据获取为空");
            XxlJobHelper.handleFail();
            return ;
        }
        signatureList.forEach(signature -> executorService.submit(() -> creativeDailyReportService.calculationMaterialReport(signature)));
    }
}
