| | |
| | | package com.ruoyi.quartz.util;
|
| | |
|
| | | import cn.hutool.core.lang.Validator;
|
| | | import cn.hutool.core.util.StrUtil;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | |
|
| | | import java.lang.reflect.InvocationTargetException;
|
| | | import java.lang.reflect.Method;
|
| | | import java.util.LinkedList;
|
| | | import java.util.List;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.quartz.domain.SysJob;
|
| | |
|
| | | /**
|
| | | * 任务执行工具
|
| | |
| | | throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
|
| | | InvocationTargetException
|
| | | {
|
| | | if (StringUtils.isNotNull(methodParams) && methodParams.size() > 0)
|
| | | if (Validator.isNotNull(methodParams) && methodParams.size() > 0)
|
| | | {
|
| | | Method method = bean.getClass().getDeclaredMethod(methodName, getMethodParamsType(methodParams));
|
| | | method.invoke(bean, getMethodParamsValue(methodParams));
|
| | |
| | | */
|
| | | public static boolean isValidClassName(String invokeTarget)
|
| | | {
|
| | | return StringUtils.countMatches(invokeTarget, ".") > 1;
|
| | | return StrUtil.count(invokeTarget, ".") > 1;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | public static String getBeanName(String invokeTarget)
|
| | | {
|
| | | String beanName = StringUtils.substringBefore(invokeTarget, "(");
|
| | | return StringUtils.substringBeforeLast(beanName, ".");
|
| | | String beanName = StrUtil.subBefore(invokeTarget, "(",false);
|
| | | return StrUtil.subBefore(beanName, ".",true);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | public static String getMethodName(String invokeTarget)
|
| | | {
|
| | | String methodName = StringUtils.substringBefore(invokeTarget, "(");
|
| | | return StringUtils.substringAfterLast(methodName, ".");
|
| | | String methodName = StrUtil.subBefore(invokeTarget, "(",false);
|
| | | return StrUtil.subAfter(methodName, ".",true);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | public static List<Object[]> getMethodParams(String invokeTarget)
|
| | | {
|
| | | String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")");
|
| | | if (StringUtils.isEmpty(methodStr))
|
| | | String methodStr = StrUtil.subBetween(invokeTarget, "(", ")");
|
| | | if (StrUtil.isEmpty(methodStr))
|
| | | {
|
| | | return null;
|
| | | }
|
| | |
| | | List<Object[]> classs = new LinkedList<>();
|
| | | for (int i = 0; i < methodParams.length; i++)
|
| | | {
|
| | | String str = StringUtils.trimToEmpty(methodParams[i]);
|
| | | String str = StrUtil.trimToEmpty(methodParams[i]);
|
| | | // String字符串类型,包含'
|
| | | if (StringUtils.contains(str, "'"))
|
| | | if (StrUtil.contains(str, "'"))
|
| | | {
|
| | | classs.add(new Object[] { StringUtils.replace(str, "'", ""), String.class });
|
| | | classs.add(new Object[] { StrUtil.replace(str, "'", ""), String.class });
|
| | | }
|
| | | // boolean布尔类型,等于true或者false
|
| | | else if (StringUtils.equals(str, "true") || StringUtils.equalsIgnoreCase(str, "false"))
|
| | | else if (StrUtil.equals(str, "true") || StrUtil.equalsIgnoreCase(str, "false"))
|
| | | {
|
| | | classs.add(new Object[] { Boolean.valueOf(str), Boolean.class });
|
| | | }
|
| | | // long长整形,包含L
|
| | | else if (StringUtils.containsIgnoreCase(str, "L"))
|
| | | else if (StrUtil.containsIgnoreCase(str, "L"))
|
| | | {
|
| | | classs.add(new Object[] { Long.valueOf(StringUtils.replaceIgnoreCase(str, "L", "")), Long.class });
|
| | | classs.add(new Object[] { Long.valueOf(StrUtil.replaceIgnoreCase(str, "L", "")), Long.class });
|
| | | }
|
| | | // double浮点类型,包含D
|
| | | else if (StringUtils.containsIgnoreCase(str, "D"))
|
| | | else if (StrUtil.containsIgnoreCase(str, "D"))
|
| | | {
|
| | | classs.add(new Object[] { Double.valueOf(StringUtils.replaceIgnoreCase(str, "D", "")), Double.class });
|
| | | classs.add(new Object[] { Double.valueOf(StrUtil.replaceIgnoreCase(str, "D", "")), Double.class });
|
| | | }
|
| | | // 其他类型归类为整形
|
| | | else
|