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

import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.toutiao.modules.report.service.IByteDanceCleanMaterialReportService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
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 IByteDanceCleanMaterialReportService cleanMaterialService;
    static ExecutorService executorService = Executors.newFixedThreadPool(3);

    @XxlJob("byteDanceCleanMaterial")
    public ReturnT<String> execute(String param) throws Exception {
        List<String> signatureList = cleanMaterialService.getSignature();
        if (Check.isNull(signatureList)) {
            XxlJobLogger.log("头条素材数据获取为空");
            return ReturnT.FAIL;
        }
        signatureList.forEach(signature -> executorService.submit(() -> cleanMaterialService.calculationMaterialReport(signature)));
        return ReturnT.SUCCESS;
    }
}
