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

import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.kuaishou.modules.report.service.IKuaiShouCleanMaterialReportService;
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;

@Component
public class KuaiShouCleanMaterialJob {
    @Autowired
    private IKuaiShouCleanMaterialReportService kuaiShouCleanMaterialReportService;
    static ExecutorService executorService = Executors.newFixedThreadPool(5);

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