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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.IProduceSnExtService;
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 SxWorkOrderAutoCreateSnJob implements Job {

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

    @Autowired
    private IProduceSnExtService produceSnExtService;

    @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();

        produceSnExtService.doWorkOrderCreateSn(true, param);

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

    }
}