package com.jwipc.job.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.quartz.JobExecutionContext;
import org.quartz.Trigger;
import org.springframework.stereotype.Component;

/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@Component
@Slf4j
public class TriggerListener implements org.quartz.TriggerListener {


    @Override
    public String getName() {
        return "globalTrigger";
    }

    @Override
    public void triggerFired(Trigger trigger, JobExecutionContext context) {
    }

    @Override
    public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
        return false;
    }

    @Override
    public void triggerMisfired(Trigger trigger) {
        String jobName = trigger.getJobKey().getName();
    }

    @Override
    public void triggerComplete(Trigger trigger, JobExecutionContext context,
                                Trigger.CompletedExecutionInstruction triggerInstructionCode)
    {
        final String jobName = trigger.getJobKey().getName();
        if (StringUtils.equals(jobName, "StoreBatchStatusSyncJob")) {
            // 这种任务不记录日志
            return;
        }
        final String description = context.getJobDetail().getKey().getName();
        log.info("执行了定时任务:{}", description);
    }
}
