Explorar o código

优化定时任务字符包含多个括号导致数据错误

RuoYi hai 1 ano
pai
achega
4aa261e8f7

+ 26 - 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java

@@ -284,6 +284,32 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
284 284
     }
285 285
 
286 286
     /**
287
+     * 在字符串中查找第一个出现的 `open` 和最后一个出现的 `close` 之间的子字符串
288
+     * 
289
+     * @param str 要截取的字符串
290
+     * @param open 起始字符串
291
+     * @param close 结束字符串
292
+     * @return 截取结果
293
+     */
294
+    public static String substringBetweenLast(final String str, final String open, final String close)
295
+    {
296
+        if (isEmpty(str) || isEmpty(open) || isEmpty(close))
297
+        {
298
+            return NULLSTR;
299
+        }
300
+        final int start = str.indexOf(open);
301
+        if (start != INDEX_NOT_FOUND)
302
+        {
303
+            final int end = str.lastIndexOf(close);
304
+            if (end != INDEX_NOT_FOUND)
305
+            {
306
+                return str.substring(start + open.length(), end);
307
+            }
308
+        }
309
+        return NULLSTR;
310
+    }
311
+
312
+    /**
287 313
      * 判断是否为空,并且不是空白字符
288 314
      * 
289 315
      * @param str 要判断的value

+ 1 - 1
ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/util/JobInvokeUtil.java

@@ -105,7 +105,7 @@ public class JobInvokeUtil
105 105
      */
106 106
     public static List<Object[]> getMethodParams(String invokeTarget)
107 107
     {
108
-        String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")");
108
+        String methodStr = StringUtils.substringBetweenLast(invokeTarget, "(", ")");
109 109
         if (StringUtils.isEmpty(methodStr))
110 110
         {
111 111
             return null;