update 禁止所有工具类实例化 优化代码书写规范
This commit is contained in:
parent
1b752c35cc
commit
e11a6163dd
@ -5,6 +5,8 @@ import cn.hutool.core.map.MapUtil;
|
|||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
import cn.hutool.extra.cglib.CglibUtil;
|
import cn.hutool.extra.cglib.CglibUtil;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -14,6 +16,7 @@ import java.util.Map;
|
|||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class BeanCopyUtils {
|
public class BeanCopyUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.ruoyi.common.utils;
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
@ -12,6 +14,7 @@ import java.util.Date;
|
|||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||||
|
|
||||||
public static String YYYY = "yyyy";
|
public static String YYYY = "yyyy";
|
||||||
|
@ -21,14 +21,18 @@ import java.util.Map;
|
|||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class JsonUtils {
|
public class JsonUtils {
|
||||||
|
|
||||||
private static ObjectMapper objectMapper = SpringUtils.getBean(ObjectMapper.class);
|
private static final ObjectMapper OBJECT_MAPPER = SpringUtils.getBean(ObjectMapper.class);
|
||||||
|
|
||||||
|
public static ObjectMapper getObjectMapper() {
|
||||||
|
return OBJECT_MAPPER;
|
||||||
|
}
|
||||||
|
|
||||||
public static String toJsonString(Object object) {
|
public static String toJsonString(Object object) {
|
||||||
if (StringUtils.isNull(object)) {
|
if (StringUtils.isNull(object)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return objectMapper.writeValueAsString(object);
|
return OBJECT_MAPPER.writeValueAsString(object);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -39,7 +43,7 @@ public class JsonUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return objectMapper.readValue(text, clazz);
|
return OBJECT_MAPPER.readValue(text, clazz);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -50,7 +54,7 @@ public class JsonUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return objectMapper.readValue(bytes, clazz);
|
return OBJECT_MAPPER.readValue(bytes, clazz);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -61,7 +65,7 @@ public class JsonUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return objectMapper.readValue(text, typeReference);
|
return OBJECT_MAPPER.readValue(text, typeReference);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -72,7 +76,7 @@ public class JsonUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return objectMapper.readValue(text, new TypeReference<Map<String, T>>() {
|
return OBJECT_MAPPER.readValue(text, new TypeReference<Map<String, T>>() {
|
||||||
});
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -84,7 +88,7 @@ public class JsonUtils {
|
|||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return objectMapper.readValue(text, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz));
|
return OBJECT_MAPPER.readValue(text, OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class, clazz));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
package com.ruoyi.common.utils;
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取i18n资源文件
|
* 获取i18n资源文件
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class MessageUtils {
|
public class MessageUtils {
|
||||||
|
|
||||||
|
private static final MessageSource MESSAGE_SOURCE = SpringUtils.getBean(MessageSource.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据消息键和参数 获取消息 委托给spring messageSource
|
* 根据消息键和参数 获取消息 委托给spring messageSource
|
||||||
*
|
*
|
||||||
@ -18,7 +24,6 @@ public class MessageUtils {
|
|||||||
* @return 获取国际化翻译值
|
* @return 获取国际化翻译值
|
||||||
*/
|
*/
|
||||||
public static String message(String code, Object... args) {
|
public static String message(String code, Object... args) {
|
||||||
MessageSource messageSource = SpringUtils.getBean(MessageSource.class);
|
return MESSAGE_SOURCE.getMessage(code, args, LocaleContextHolder.getLocale());
|
||||||
return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ import com.ruoyi.common.core.domain.PageQuery;
|
|||||||
import com.ruoyi.common.core.page.PagePlus;
|
import com.ruoyi.common.core.page.PagePlus;
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.utils.sql.SqlUtil;
|
import com.ruoyi.common.utils.sql.SqlUtil;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -16,6 +18,7 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class PageUtils {
|
public class PageUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.ruoyi.common.utils;
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import cn.hutool.core.collection.IterUtil;
|
||||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@ -23,7 +23,7 @@ import java.util.function.Consumer;
|
|||||||
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
||||||
public class RedisUtils {
|
public class RedisUtils {
|
||||||
|
|
||||||
private static RedissonClient client = SpringUtils.getBean(RedissonClient.class);
|
private static final RedissonClient CLIENT = SpringUtils.getBean(RedissonClient.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 限流
|
* 限流
|
||||||
@ -35,7 +35,7 @@ public class RedisUtils {
|
|||||||
* @return -1 表示失败
|
* @return -1 表示失败
|
||||||
*/
|
*/
|
||||||
public static long rateLimiter(String key, RateType rateType, int rate, int rateInterval) {
|
public static long rateLimiter(String key, RateType rateType, int rate, int rateInterval) {
|
||||||
RRateLimiter rateLimiter = client.getRateLimiter(key);
|
RRateLimiter rateLimiter = CLIENT.getRateLimiter(key);
|
||||||
rateLimiter.trySetRate(rateType, rate, rateInterval, RateIntervalUnit.SECONDS);
|
rateLimiter.trySetRate(rateType, rate, rateInterval, RateIntervalUnit.SECONDS);
|
||||||
if (rateLimiter.tryAcquire()) {
|
if (rateLimiter.tryAcquire()) {
|
||||||
return rateLimiter.availablePermits();
|
return rateLimiter.availablePermits();
|
||||||
@ -48,7 +48,7 @@ public class RedisUtils {
|
|||||||
* 获取实例id
|
* 获取实例id
|
||||||
*/
|
*/
|
||||||
public static String getClientId() {
|
public static String getClientId() {
|
||||||
return client.getId();
|
return CLIENT.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,13 +59,13 @@ public class RedisUtils {
|
|||||||
* @param consumer 自定义处理
|
* @param consumer 自定义处理
|
||||||
*/
|
*/
|
||||||
public static <T> void publish(String channelKey, T msg, Consumer<T> consumer) {
|
public static <T> void publish(String channelKey, T msg, Consumer<T> consumer) {
|
||||||
RTopic topic = client.getTopic(channelKey);
|
RTopic topic = CLIENT.getTopic(channelKey);
|
||||||
topic.publish(msg);
|
topic.publish(msg);
|
||||||
consumer.accept(msg);
|
consumer.accept(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void publish(String channelKey, T msg) {
|
public static <T> void publish(String channelKey, T msg) {
|
||||||
RTopic topic = client.getTopic(channelKey);
|
RTopic topic = CLIENT.getTopic(channelKey);
|
||||||
topic.publish(msg);
|
topic.publish(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ public class RedisUtils {
|
|||||||
* @param consumer 自定义处理
|
* @param consumer 自定义处理
|
||||||
*/
|
*/
|
||||||
public static <T> void subscribe(String channelKey, Class<T> clazz, Consumer<T> consumer) {
|
public static <T> void subscribe(String channelKey, Class<T> clazz, Consumer<T> consumer) {
|
||||||
RTopic topic = client.getTopic(channelKey);
|
RTopic topic = CLIENT.getTopic(channelKey);
|
||||||
topic.addListener(clazz, (channel, msg) -> consumer.accept(msg));
|
topic.addListener(clazz, (channel, msg) -> consumer.accept(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ public class RedisUtils {
|
|||||||
* @since Redis 6.X 以上使用 setAndKeepTTL 兼容 5.X 方案
|
* @since Redis 6.X 以上使用 setAndKeepTTL 兼容 5.X 方案
|
||||||
*/
|
*/
|
||||||
public static <T> void setCacheObject(final String key, final T value, final boolean isSaveTtl) {
|
public static <T> void setCacheObject(final String key, final T value, final boolean isSaveTtl) {
|
||||||
RBucket<Object> bucket = client.getBucket(key);
|
RBucket<Object> bucket = CLIENT.getBucket(key);
|
||||||
if (isSaveTtl) {
|
if (isSaveTtl) {
|
||||||
try {
|
try {
|
||||||
bucket.setAndKeepTTL(value);
|
bucket.setAndKeepTTL(value);
|
||||||
@ -123,7 +123,7 @@ public class RedisUtils {
|
|||||||
* @param timeUnit 时间颗粒度
|
* @param timeUnit 时间颗粒度
|
||||||
*/
|
*/
|
||||||
public static <T> void setCacheObject(final String key, final T value, final long timeout, final TimeUnit timeUnit) {
|
public static <T> void setCacheObject(final String key, final T value, final long timeout, final TimeUnit timeUnit) {
|
||||||
RBucket<T> result = client.getBucket(key);
|
RBucket<T> result = CLIENT.getBucket(key);
|
||||||
result.set(value);
|
result.set(value);
|
||||||
result.expire(timeout, timeUnit);
|
result.expire(timeout, timeUnit);
|
||||||
}
|
}
|
||||||
@ -148,7 +148,7 @@ public class RedisUtils {
|
|||||||
* @return true=设置成功;false=设置失败
|
* @return true=设置成功;false=设置失败
|
||||||
*/
|
*/
|
||||||
public static boolean expire(final String key, final long timeout, final TimeUnit unit) {
|
public static boolean expire(final String key, final long timeout, final TimeUnit unit) {
|
||||||
RBucket rBucket = client.getBucket(key);
|
RBucket rBucket = CLIENT.getBucket(key);
|
||||||
return rBucket.expire(timeout, unit);
|
return rBucket.expire(timeout, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ public class RedisUtils {
|
|||||||
* @return 缓存键值对应的数据
|
* @return 缓存键值对应的数据
|
||||||
*/
|
*/
|
||||||
public static <T> T getCacheObject(final String key) {
|
public static <T> T getCacheObject(final String key) {
|
||||||
RBucket<T> rBucket = client.getBucket(key);
|
RBucket<T> rBucket = CLIENT.getBucket(key);
|
||||||
return rBucket.get();
|
return rBucket.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ public class RedisUtils {
|
|||||||
* @return 剩余存活时间
|
* @return 剩余存活时间
|
||||||
*/
|
*/
|
||||||
public static <T> long getTimeToLive(final String key) {
|
public static <T> long getTimeToLive(final String key) {
|
||||||
RBucket<T> rBucket = client.getBucket(key);
|
RBucket<T> rBucket = CLIENT.getBucket(key);
|
||||||
return rBucket.remainTimeToLive();
|
return rBucket.remainTimeToLive();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ public class RedisUtils {
|
|||||||
* @param key
|
* @param key
|
||||||
*/
|
*/
|
||||||
public static boolean deleteObject(final String key) {
|
public static boolean deleteObject(final String key) {
|
||||||
return client.getBucket(key).delete();
|
return CLIENT.getBucket(key).delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
@ -192,7 +192,7 @@ public class RedisUtils {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static void deleteObject(final Collection collection) {
|
public static void deleteObject(final Collection collection) {
|
||||||
RBatch batch = client.createBatch();
|
RBatch batch = CLIENT.createBatch();
|
||||||
collection.forEach(t -> {
|
collection.forEach(t -> {
|
||||||
batch.getBucket(t.toString()).deleteAsync();
|
batch.getBucket(t.toString()).deleteAsync();
|
||||||
});
|
});
|
||||||
@ -207,7 +207,7 @@ public class RedisUtils {
|
|||||||
* @return 缓存的对象
|
* @return 缓存的对象
|
||||||
*/
|
*/
|
||||||
public static <T> boolean setCacheList(final String key, final List<T> dataList) {
|
public static <T> boolean setCacheList(final String key, final List<T> dataList) {
|
||||||
RList<T> rList = client.getList(key);
|
RList<T> rList = CLIENT.getList(key);
|
||||||
return rList.addAll(dataList);
|
return rList.addAll(dataList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ public class RedisUtils {
|
|||||||
* @return 缓存键值对应的数据
|
* @return 缓存键值对应的数据
|
||||||
*/
|
*/
|
||||||
public static <T> List<T> getCacheList(final String key) {
|
public static <T> List<T> getCacheList(final String key) {
|
||||||
RList<T> rList = client.getList(key);
|
RList<T> rList = CLIENT.getList(key);
|
||||||
return rList.readAll();
|
return rList.readAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ public class RedisUtils {
|
|||||||
* @return 缓存数据的对象
|
* @return 缓存数据的对象
|
||||||
*/
|
*/
|
||||||
public static <T> boolean setCacheSet(final String key, final Set<T> dataSet) {
|
public static <T> boolean setCacheSet(final String key, final Set<T> dataSet) {
|
||||||
RSet<T> rSet = client.getSet(key);
|
RSet<T> rSet = CLIENT.getSet(key);
|
||||||
return rSet.addAll(dataSet);
|
return rSet.addAll(dataSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ public class RedisUtils {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static <T> Set<T> getCacheSet(final String key) {
|
public static <T> Set<T> getCacheSet(final String key) {
|
||||||
RSet<T> rSet = client.getSet(key);
|
RSet<T> rSet = CLIENT.getSet(key);
|
||||||
return rSet.readAll();
|
return rSet.readAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ public class RedisUtils {
|
|||||||
*/
|
*/
|
||||||
public static <T> void setCacheMap(final String key, final Map<String, T> dataMap) {
|
public static <T> void setCacheMap(final String key, final Map<String, T> dataMap) {
|
||||||
if (dataMap != null) {
|
if (dataMap != null) {
|
||||||
RMap<String, T> rMap = client.getMap(key);
|
RMap<String, T> rMap = CLIENT.getMap(key);
|
||||||
rMap.putAll(dataMap);
|
rMap.putAll(dataMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,7 +265,7 @@ public class RedisUtils {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static <T> Map<String, T> getCacheMap(final String key) {
|
public static <T> Map<String, T> getCacheMap(final String key) {
|
||||||
RMap<String, T> rMap = client.getMap(key);
|
RMap<String, T> rMap = CLIENT.getMap(key);
|
||||||
return rMap.getAll(rMap.keySet());
|
return rMap.getAll(rMap.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,7 +277,7 @@ public class RedisUtils {
|
|||||||
* @param value 值
|
* @param value 值
|
||||||
*/
|
*/
|
||||||
public static <T> void setCacheMapValue(final String key, final String hKey, final T value) {
|
public static <T> void setCacheMapValue(final String key, final String hKey, final T value) {
|
||||||
RMap<String, T> rMap = client.getMap(key);
|
RMap<String, T> rMap = CLIENT.getMap(key);
|
||||||
rMap.put(hKey, value);
|
rMap.put(hKey, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ public class RedisUtils {
|
|||||||
* @return Hash中的对象
|
* @return Hash中的对象
|
||||||
*/
|
*/
|
||||||
public static <T> T getCacheMapValue(final String key, final String hKey) {
|
public static <T> T getCacheMapValue(final String key, final String hKey) {
|
||||||
RMap<String, T> rMap = client.getMap(key);
|
RMap<String, T> rMap = CLIENT.getMap(key);
|
||||||
return rMap.get(hKey);
|
return rMap.get(hKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +301,7 @@ public class RedisUtils {
|
|||||||
* @return Hash中的对象
|
* @return Hash中的对象
|
||||||
*/
|
*/
|
||||||
public static <T> T delCacheMapValue(final String key, final String hKey) {
|
public static <T> T delCacheMapValue(final String key, final String hKey) {
|
||||||
RMap<String, T> rMap = client.getMap(key);
|
RMap<String, T> rMap = CLIENT.getMap(key);
|
||||||
return rMap.remove(hKey);
|
return rMap.remove(hKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,7 +313,7 @@ public class RedisUtils {
|
|||||||
* @return Hash对象集合
|
* @return Hash对象集合
|
||||||
*/
|
*/
|
||||||
public static <K, V> Map<K, V> getMultiCacheMapValue(final String key, final Set<K> hKeys) {
|
public static <K, V> Map<K, V> getMultiCacheMapValue(final String key, final Set<K> hKeys) {
|
||||||
RMap<K, V> rMap = client.getMap(key);
|
RMap<K, V> rMap = CLIENT.getMap(key);
|
||||||
return rMap.getAll(hKeys);
|
return rMap.getAll(hKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ public class RedisUtils {
|
|||||||
* @return 对象列表
|
* @return 对象列表
|
||||||
*/
|
*/
|
||||||
public static Collection<String> keys(final String pattern) {
|
public static Collection<String> keys(final String pattern) {
|
||||||
Iterable<String> iterable = client.getKeys().getKeysByPattern(pattern);
|
Iterable<String> iterable = CLIENT.getKeys().getKeysByPattern(pattern);
|
||||||
return Lists.newArrayList(iterable);
|
return IterUtil.toList(iterable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package com.ruoyi.common.utils;
|
|||||||
import cn.hutool.http.HttpStatus;
|
import cn.hutool.http.HttpStatus;
|
||||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||||
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
@ -12,6 +14,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class SecurityUtils {
|
public class SecurityUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,8 @@ package com.ruoyi.common.utils;
|
|||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
import cn.hutool.extra.servlet.ServletUtil;
|
||||||
import cn.hutool.http.HttpStatus;
|
import cn.hutool.http.HttpStatus;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.context.request.RequestAttributes;
|
import org.springframework.web.context.request.RequestAttributes;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
@ -19,6 +21,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class ServletUtils extends ServletUtil {
|
public class ServletUtils extends ServletUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,6 +7,8 @@ import cn.hutool.core.util.ArrayUtil;
|
|||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.ReUtil;
|
import cn.hutool.core.util.ReUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -15,6 +17,7 @@ import java.util.*;
|
|||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package com.ruoyi.common.utils;
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import lombok.AccessLevel;
|
||||||
import org.slf4j.LoggerFactory;
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
@ -10,8 +11,9 @@ import java.util.concurrent.*;
|
|||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class Threads {
|
public class Threads {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Threads.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sleep等待,单位为毫秒
|
* sleep等待,单位为毫秒
|
||||||
@ -38,7 +40,7 @@ public class Threads {
|
|||||||
if (!pool.awaitTermination(120, TimeUnit.SECONDS)) {
|
if (!pool.awaitTermination(120, TimeUnit.SECONDS)) {
|
||||||
pool.shutdownNow();
|
pool.shutdownNow();
|
||||||
if (!pool.awaitTermination(120, TimeUnit.SECONDS)) {
|
if (!pool.awaitTermination(120, TimeUnit.SECONDS)) {
|
||||||
logger.info("Pool did not terminate");
|
log.info("Pool did not terminate");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
@ -67,7 +69,7 @@ public class Threads {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
logger.error(t.getMessage(), t);
|
log.error(t.getMessage(), t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import cn.hutool.core.lang.tree.Tree;
|
|||||||
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
||||||
import cn.hutool.core.lang.tree.TreeUtil;
|
import cn.hutool.core.lang.tree.TreeUtil;
|
||||||
import cn.hutool.core.lang.tree.parser.NodeParser;
|
import cn.hutool.core.lang.tree.parser.NodeParser;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -12,6 +14,7 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class TreeBuildUtils extends TreeUtil {
|
public class TreeBuildUtils extends TreeUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package com.ruoyi.common.utils;
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import javax.validation.ConstraintViolation;
|
import javax.validation.ConstraintViolation;
|
||||||
import javax.validation.ConstraintViolationException;
|
import javax.validation.ConstraintViolationException;
|
||||||
import javax.validation.Validation;
|
import javax.validation.Validation;
|
||||||
@ -11,6 +14,7 @@ import java.util.Set;
|
|||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class ValidatorUtils {
|
public class ValidatorUtils {
|
||||||
|
|
||||||
private static final Validator VALID = Validation.buildDefaultValidatorFactory().getValidator();
|
private static final Validator VALID = Validation.buildDefaultValidatorFactory().getValidator();
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.ruoyi.common.utils.file;
|
package com.ruoyi.common.utils.file;
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
@ -12,6 +14,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class FileUtils extends FileUtil {
|
public class FileUtils extends FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,6 +7,8 @@ import com.ruoyi.common.config.RuoYiConfig;
|
|||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.utils.JsonUtils;
|
import com.ruoyi.common.utils.JsonUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -17,6 +19,7 @@ import java.util.Map;
|
|||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class AddressUtils {
|
public class AddressUtils {
|
||||||
|
|
||||||
// IP地址查询
|
// IP地址查询
|
||||||
|
@ -9,6 +9,8 @@ import com.ruoyi.common.excel.ExcelListener;
|
|||||||
import com.ruoyi.common.excel.ExcelResult;
|
import com.ruoyi.common.excel.ExcelResult;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.file.FileUtils;
|
import com.ruoyi.common.utils.file.FileUtils;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@ -21,6 +23,7 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class ExcelUtil {
|
public class ExcelUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,6 +2,8 @@ package com.ruoyi.common.utils.reflect;
|
|||||||
|
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
@ -11,6 +13,7 @@ import java.lang.reflect.Method;
|
|||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class ReflectUtils extends ReflectUtil {
|
public class ReflectUtils extends ReflectUtil {
|
||||||
|
|
||||||
private static final String SETTER_PREFIX = "set";
|
private static final String SETTER_PREFIX = "set";
|
||||||
|
@ -2,17 +2,20 @@ package com.ruoyi.common.utils.sql;
|
|||||||
|
|
||||||
import com.ruoyi.common.exception.UtilException;
|
import com.ruoyi.common.exception.UtilException;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sql操作工具类
|
* sql操作工具类
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class SqlUtil {
|
public class SqlUtil {
|
||||||
/**
|
/**
|
||||||
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
|
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
|
||||||
*/
|
*/
|
||||||
public static String SQL_PATTERN = "[a-zA-Z0-9_\\ \\,\\.]+";
|
public static final String SQL_PATTERN = "[a-zA-Z0-9_\\ \\,\\.]+";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查字符,防止注入绕过
|
* 检查字符,防止注入绕过
|
||||||
|
Loading…
x
Reference in New Issue
Block a user