package org.jeecg.modules.ctop.job;

import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.toutiao.modules.report.service.IBytedanceCreativeDailyReportService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;

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

/**
 * DONE
 * 清洗素材报表
 */
@Slf4j
public class ByteDanceCleanMaterialJob implements Job {
    @Autowired
    private IBytedanceCreativeDailyReportService bytedanceCreativeDailyReportService;
    static ExecutorService executorService = null;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        Thread thread = new Thread() {
            @Override
            public void run() {
                List<String> signatureList = bytedanceCreativeDailyReportService.getSignatureList();
                if (Check.isNull(signatureList)) {
                    log.error("头条素材数据获取为空");
                    return;
                }
                executorService = Executors.newFixedThreadPool(3);
                for (int i = 0; i < signatureList.size(); i++) {
                    String signature = signatureList.get(i);
                    executorService.submit(new Runnable() {
                        @Override
                        public void run() {
                            bytedanceCreativeDailyReportService.calculationMaterialReport(signature);
                        }
                    });
                }
            }
        };
        thread.start();

    }
}
