package org.jeecg.modules.ctop.job;

import cn.com.ctop.common.module.utils.Check;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.ctop.service.ICleanMaterialService;
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;

/**
 * 清洗素材报表
 */
@Slf4j
public class KuaiShouCleanMaterialJob implements Job {
    @Autowired
    private ICleanMaterialService cleanMaterialService;
    static ExecutorService executorService = null;

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


            }
        };
        thread.start();

    }
}
