vip
This commit is contained in:
@@ -1,18 +1,24 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.text.StrFormatter;
|
||||
|
||||
/**
|
||||
* 字符串工具类
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
@@ -28,7 +34,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 获取参数不为空值
|
||||
*
|
||||
*
|
||||
* @param value defaultValue 要判断的value
|
||||
* @return value 返回值
|
||||
*/
|
||||
@@ -39,7 +45,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* * 判断一个Collection是否为空, 包含List,Set,Queue
|
||||
*
|
||||
*
|
||||
* @param coll 要判断的Collection
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
@@ -50,7 +56,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* * 判断一个Collection是否非空,包含List,Set,Queue
|
||||
*
|
||||
*
|
||||
* @param coll 要判断的Collection
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
@@ -61,7 +67,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* * 判断一个对象数组是否为空
|
||||
*
|
||||
*
|
||||
* @param objects 要判断的对象数组
|
||||
** @return true:为空 false:非空
|
||||
*/
|
||||
@@ -72,7 +78,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* * 判断一个对象数组是否非空
|
||||
*
|
||||
*
|
||||
* @param objects 要判断的对象数组
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
@@ -83,7 +89,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* * 判断一个Map是否为空
|
||||
*
|
||||
*
|
||||
* @param map 要判断的Map
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
@@ -94,7 +100,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* * 判断一个Map是否为空
|
||||
*
|
||||
*
|
||||
* @param map 要判断的Map
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
@@ -105,7 +111,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* * 判断一个字符串是否为空串
|
||||
*
|
||||
*
|
||||
* @param str String
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
@@ -116,7 +122,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* * 判断一个字符串是否为非空串
|
||||
*
|
||||
*
|
||||
* @param str String
|
||||
* @return true:非空串 false:空串
|
||||
*/
|
||||
@@ -127,7 +133,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* * 判断一个对象是否为空
|
||||
*
|
||||
*
|
||||
* @param object Object
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
@@ -138,7 +144,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* * 判断一个对象是否非空
|
||||
*
|
||||
*
|
||||
* @param object Object
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
@@ -149,7 +155,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* * 判断一个对象是否是数组类型(Java基本型别的数组)
|
||||
*
|
||||
*
|
||||
* @param object 对象
|
||||
* @return true:是数组 false:不是数组
|
||||
*/
|
||||
@@ -211,7 +217,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 截取字符串
|
||||
*
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param start 开始
|
||||
* @return 结果
|
||||
@@ -242,7 +248,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 截取字符串
|
||||
*
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param start 开始
|
||||
* @param end 结束
|
||||
@@ -288,7 +294,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 在字符串中查找第一个出现的 `open` 和最后一个出现的 `close` 之间的子字符串
|
||||
*
|
||||
*
|
||||
* @param str 要截取的字符串
|
||||
* @param open 起始字符串
|
||||
* @param close 结束字符串
|
||||
@@ -314,7 +320,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 判断是否为空,并且不是空白字符
|
||||
*
|
||||
*
|
||||
* @param str 要判断的value
|
||||
* @return 结果
|
||||
*/
|
||||
@@ -344,7 +350,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
* 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br>
|
||||
* 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br>
|
||||
* 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
|
||||
*
|
||||
*
|
||||
* @param template 文本模板,被替换的部分用 {} 表示
|
||||
* @param params 参数值
|
||||
* @return 格式化后的文本
|
||||
@@ -360,7 +366,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 是否为http(s)://开头
|
||||
*
|
||||
*
|
||||
* @param link 链接
|
||||
* @return 结果
|
||||
*/
|
||||
@@ -371,7 +377,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 字符串转set
|
||||
*
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param sep 分隔符
|
||||
* @return set集合
|
||||
@@ -383,7 +389,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 字符串转list
|
||||
*
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param sep 分隔符
|
||||
* @return list集合
|
||||
@@ -395,7 +401,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 字符串转list
|
||||
*
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param sep 分隔符
|
||||
* @param filterBlank 过滤纯空白
|
||||
@@ -532,7 +538,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 是否包含字符串
|
||||
*
|
||||
*
|
||||
* @param str 验证字符串
|
||||
* @param strs 字符串组
|
||||
* @return 包含返回true
|
||||
@@ -554,7 +560,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld
|
||||
*
|
||||
*
|
||||
* @param name 转换前的下划线大写方式命名的字符串
|
||||
* @return 转换后的驼峰式命名的字符串
|
||||
*/
|
||||
@@ -628,7 +634,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
|
||||
*
|
||||
*
|
||||
* @param str 指定字符串
|
||||
* @param strs 需要检查的字符串数组
|
||||
* @return 是否匹配
|
||||
@@ -650,11 +656,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断url是否与规则配置:
|
||||
* ? 表示单个字符;
|
||||
* * 表示一层路径内的任意字符串,不可跨层级;
|
||||
* 判断url是否与规则配置:
|
||||
* ? 表示单个字符;
|
||||
* * 表示一层路径内的任意字符串,不可跨层级;
|
||||
* ** 表示任意层路径;
|
||||
*
|
||||
*
|
||||
* @param pattern 匹配规则
|
||||
* @param url 需要匹配的url
|
||||
* @return
|
||||
@@ -673,7 +679,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 数字左边补齐0,使之达到指定长度。注意,如果数字转换为字符串后,长度大于size,则只保留 最后size个字符。
|
||||
*
|
||||
*
|
||||
* @param num 数字对象
|
||||
* @param size 字符串指定长度
|
||||
* @return 返回数字的字符串格式,该字符串为指定长度。
|
||||
@@ -685,7 +691,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
|
||||
/**
|
||||
* 字符串左补齐。如果原始字符串s长度大于size,则只保留最后size个字符。
|
||||
*
|
||||
*
|
||||
* @param s 原始字符串
|
||||
* @param size 字符串指定长度
|
||||
* @param c 用于补齐的字符
|
||||
@@ -719,4 +725,42 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static String convertToBeijingTime(String gmtTime) {
|
||||
try {
|
||||
// 移除时区标识
|
||||
String timeStr = gmtTime.replace(" Etc/GMT", "");
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
// 解析为本地时间
|
||||
LocalDateTime localDateTime = LocalDateTime.parse(timeStr, formatter);
|
||||
|
||||
// GMT时间加8小时就是北京时间
|
||||
LocalDateTime beijingTime = localDateTime.plusHours(8);
|
||||
|
||||
return beijingTime.format(formatter);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("时间转换失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将GMT时间字符串转换为时间戳(毫秒)
|
||||
*/
|
||||
public static long convertToTimestampMillis(String gmtTime) {
|
||||
try {
|
||||
String timeStr = gmtTime.replace(" Etc/GMT", "");
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
LocalDateTime localDateTime = LocalDateTime.parse(timeStr, formatter);
|
||||
ZonedDateTime gmtDateTime = localDateTime.atZone(ZoneId.of("GMT"));
|
||||
|
||||
return gmtDateTime.toInstant().toEpochMilli();
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("时间戳转换失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user