package cn.estsh.i3plus.ext.mes.pcn.apiservice.schedulejob;

import cn.estsh.i3plus.ext.mes.pcn.api.job.ISxDeleteTravelDataService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jboss.logging.Logger;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic-bu
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2022-11-11 11:11
 */
@Slf4j
@DisallowConcurrentExecution
@ApiOperation("删除数据定时任务")
public class SxDeleteTravelDataJob implements Job {

    @Autowired
    private ISxDeleteTravelDataService deleteTravelDataService;

    private static final Logger LOGGER = Logger.getLogger(SxDeleteTravelDataJob.class);

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        LOGGER.info(this.getClass().getSimpleName() + " :Pcn处理删除数据JOB开始执行...");

        Object param =  jobExecutionContext.getJobDetail().getJobDataMap().get(MesPcnExtConstWords.PARAM);

        if(StringUtils.isEmpty(param)){
            LOGGER.error("Pcn处理删除数据JOB开始执行,未配置工厂代码参数");
            return;
        }

        long startTime = System.currentTimeMillis();

        String[] organizeCodeArray = param.toString().split(MesPcnExtConstWords.COMMA);

        for (String organizeCode : organizeCodeArray) {
            deleteTravelDataService.doDeleteTravelData(organizeCode);
        }

        long endTime = System.currentTimeMillis();
        LOGGER.info(this.getClass().getSimpleName() + " :ALL:耗时: " + (endTime - startTime) + "ms");
    }
}
