wumei-smart-master/springboot/wumei-quartz/src/main/java/com/ruoyi/quartz/util/AbstractQuartzJob.java
@@ -1,6 +1,7 @@
package com.ruoyi.quartz.util;
import java.util.Date;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
@@ -21,8 +22,7 @@
 *
 * @author ruoyi
 */
public abstract class AbstractQuartzJob implements Job
{
public abstract class AbstractQuartzJob implements Job {
    private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class);
    /**
@@ -31,21 +31,16 @@
    private static ThreadLocal<Date> threadLocal = new ThreadLocal<>();
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException
    {
    public void execute(JobExecutionContext context) throws JobExecutionException {
        SysJob sysJob = new SysJob();
        BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES));
        try
        {
        try {
            before(context, sysJob);
            if (sysJob != null)
            {
            if (sysJob != null) {
                doExecute(context, sysJob);
            }
            after(context, sysJob, null);
        }
        catch (Exception e)
        {
        } catch (Exception e) {
            log.error("任务执行异常  - :", e);
            after(context, sysJob, e);
        }
@@ -55,10 +50,9 @@
     * 执行前
     *
     * @param context 工作执行上下文对象
     * @param sysJob 系统计划任务
     * @param sysJob  系统计划任务
     */
    protected void before(JobExecutionContext context, SysJob sysJob)
    {
    protected void before(JobExecutionContext context, SysJob sysJob) {
        threadLocal.set(new Date());
    }
@@ -66,10 +60,9 @@
     * 执行后
     *
     * @param context 工作执行上下文对象
     * @param sysJob 系统计划任务
     * @param sysJob  系统计划任务
     */
    protected void after(JobExecutionContext context, SysJob sysJob, Exception e)
    {
    protected void after(JobExecutionContext context, SysJob sysJob, Exception e) {
        Date startTime = threadLocal.get();
        threadLocal.remove();
@@ -81,14 +74,11 @@
        sysJobLog.setStopTime(new Date());
        long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime();
        sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒");
        if (e != null)
        {
        if (e != null) {
            sysJobLog.setStatus(Constants.FAIL);
            String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000);
            sysJobLog.setExceptionInfo(errorMsg);
        }
        else
        {
        } else {
            sysJobLog.setStatus(Constants.SUCCESS);
        }
@@ -100,7 +90,7 @@
     * 执行方法,由子类重载
     *
     * @param context 工作执行上下文对象
     * @param sysJob 系统计划任务
     * @param sysJob  系统计划任务
     * @throws Exception 执行过程中的异常
     */
    protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception;