package com.foreverwin.mesnac.quartz.job;

import com.foreverwin.mesnac.common.service.ProdReadyTaskService;
import com.foreverwin.mesnac.common.util.StringUtil;
import com.foreverwin.modular.core.exception.BaseException;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description TODO
 * @Author Philip
 * @Since 2021-08-06
 */
@DisallowConcurrentExecution
public class ProdUnReadySendMsgJob implements Job {
    private static final String SITE_UPPERCASE = "SITE";
    private static final String SITE_LOWERCASE = "site";

    private Logger logger = LoggerFactory.getLogger(ProdUnReadySendMsgJob.class);
    @Autowired
    private ProdReadyTaskService prodReadyTaskService;

    @Override
    public void execute(JobExecutionContext context) {
        logger.info("生产准备发送信息定时任务开始执行");
        //获取站点，若站点为空则抛出异常
        String site = getSite(context);
        if (StringUtil.isBlank(site)) {
            logger.error("生产准备发送信息定时任务未配置站点参数！");
            return;
        }
        prodReadyTaskService.sendMsgJob(site);
    }

    private String getSite(JobExecutionContext context) {
        String site = context.getJobDetail().getJobDataMap().getString(SITE_LOWERCASE);
        if (StringUtil.isBlank(site)) {
            site = context.getJobDetail().getJobDataMap().getString(SITE_UPPERCASE);
        }
        return site;
    }
}
