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

import cn.estsh.i3plus.ext.mes.pcn.api.job.ISxGenPrintRecordService;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

/**
 * @Description : Pcn处理打印记录JOB
 * @Reference :
 * @Author : wangjie
 * @CreateDate : 2020-10-23 17:30
 **/
@Slf4j
@ApiOperation("Pcn处理打印记录JOB")
@DisallowConcurrentExecution
public class SxGenPrintRecordJob implements Job {

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

    @Autowired
    private ISxGenPrintRecordService genPrintRecordService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        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();

        genPrintRecordService.doGenPrintRecord(param.toString());

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

    }
}