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

import cn.estsh.i3plus.ext.mes.pcn.api.job.IProjectTourConfirmOrderService;
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;

/**
 * @author wangjie
 * @version 1.0
 * @date 2021/2/2 16:44
 **/
@Slf4j
@DisallowConcurrentExecution
@ApiOperation("工程巡回确认单据定时任务")
public class ProjectTourConfirmOrderJob implements Job {

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

    @Autowired
    private IProjectTourConfirmOrderService projectTourConfirmOrderService;

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

        projectTourConfirmOrderService.doProjectTourConfirmOrder(param.toString());

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

    }
}
