You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.5 KiB
Java
53 lines
1.5 KiB
Java
|
7 years ago
|
package com.ruoyi.quartz.util;
|
||
|
|
|
||
|
|
import java.lang.reflect.InvocationTargetException;
|
||
|
|
import java.lang.reflect.Method;
|
||
|
|
import com.ruoyi.common.utils.StringUtils;
|
||
|
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
||
|
|
import com.ruoyi.quartz.domain.SysJob;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 任务执行工具
|
||
|
|
*
|
||
|
|
* @author ruoyi
|
||
|
|
*/
|
||
|
|
public class JobInvokeUtil
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* 执行方法
|
||
|
|
*
|
||
|
|
* @param sysJob 系统任务
|
||
|
|
*/
|
||
|
|
public static void invokeMethod(SysJob sysJob) throws Exception
|
||
|
|
{
|
||
|
|
Object bean = SpringUtils.getBean(sysJob.getJobName());
|
||
|
|
String methodName = sysJob.getMethodName();
|
||
|
|
String methodParams = sysJob.getMethodParams();
|
||
|
|
|
||
|
|
invokeSpringBean(bean, methodName, methodParams);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 调用任务方法
|
||
|
|
*
|
||
|
|
* @param bean 目标对象
|
||
|
|
* @param methodName 方法名称
|
||
|
|
* @param methodParams 方法参数
|
||
|
|
*/
|
||
|
|
private static void invokeSpringBean(Object bean, String methodName, String methodParams)
|
||
|
|
throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
|
||
|
|
InvocationTargetException
|
||
|
|
{
|
||
|
|
if (StringUtils.isNotEmpty(methodParams))
|
||
|
|
{
|
||
|
|
Method method = bean.getClass().getDeclaredMethod(methodName, String.class);
|
||
|
|
method.invoke(bean, methodParams);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
Method method = bean.getClass().getDeclaredMethod(methodName);
|
||
|
|
method.invoke(bean);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|