mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-07 12:59:01 +00:00
update 优化整体代码 适配jdk17
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.dromara.common.core.config;
|
||||
|
||||
import jakarta.validation.Validator;
|
||||
import org.hibernate.validator.HibernateValidator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
@@ -7,7 +8,6 @@ import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
|
||||
import jakarta.validation.Validator;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
@@ -26,18 +26,19 @@ public class ValidatorConfig {
|
||||
*/
|
||||
@Bean
|
||||
public Validator validator() {
|
||||
LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
|
||||
// 国际化
|
||||
factoryBean.setValidationMessageSource(messageSource);
|
||||
// 设置使用 HibernateValidator 校验器
|
||||
factoryBean.setProviderClass(HibernateValidator.class);
|
||||
Properties properties = new Properties();
|
||||
// 设置 快速异常返回
|
||||
properties.setProperty("hibernate.validator.fail_fast", "true");
|
||||
factoryBean.setValidationProperties(properties);
|
||||
// 加载配置
|
||||
factoryBean.afterPropertiesSet();
|
||||
return factoryBean.getValidator();
|
||||
try (LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean()) {
|
||||
// 国际化
|
||||
factoryBean.setValidationMessageSource(messageSource);
|
||||
// 设置使用 HibernateValidator 校验器
|
||||
factoryBean.setProviderClass(HibernateValidator.class);
|
||||
Properties properties = new Properties();
|
||||
// 设置 快速异常返回
|
||||
properties.setProperty("hibernate.validator.fail_fast", "true");
|
||||
factoryBean.setValidationProperties(properties);
|
||||
// 加载配置
|
||||
factoryBean.afterPropertiesSet();
|
||||
return factoryBean.getValidator();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.dromara.common.core.constant.HttpStatus;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -14,6 +15,8 @@ import java.io.Serializable;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class R<T> implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
@@ -2,12 +2,15 @@ package org.dromara.common.core.exception;
|
||||
|
||||
import org.dromara.common.core.exception.user.UserException;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 验证码错误异常类
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public class CaptchaException extends UserException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CaptchaException() {
|
||||
|
@@ -1,11 +1,14 @@
|
||||
package org.dromara.common.core.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 检查异常
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class CheckedException extends RuntimeException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CheckedException(String message) {
|
||||
|
@@ -1,11 +1,14 @@
|
||||
package org.dromara.common.core.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 演示模式异常
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class DemoModeException extends RuntimeException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public DemoModeException() {
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package org.dromara.common.core.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 全局异常
|
||||
*
|
||||
@@ -7,6 +9,7 @@ package org.dromara.common.core.exception;
|
||||
*/
|
||||
public class GlobalException extends RuntimeException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
@@ -1,11 +1,14 @@
|
||||
package org.dromara.common.core.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 业务异常
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public final class ServiceException extends RuntimeException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
@@ -1,11 +1,14 @@
|
||||
package org.dromara.common.core.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 工具类异常
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UtilException extends RuntimeException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 8247610319171014183L;
|
||||
|
||||
public UtilException(Throwable e) {
|
||||
|
@@ -5,6 +5,8 @@ import org.dromara.common.core.utils.StringUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 基础异常
|
||||
*
|
||||
@@ -13,6 +15,7 @@ import lombok.Getter;
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class BaseException extends RuntimeException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
@@ -2,12 +2,15 @@ package org.dromara.common.core.exception.file;
|
||||
|
||||
import org.dromara.common.core.exception.base.BaseException;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 文件信息异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class FileException extends BaseException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public FileException(String code, Object[] args) {
|
||||
|
@@ -1,11 +1,14 @@
|
||||
package org.dromara.common.core.exception.file;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 文件名称超长限制异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class FileNameLengthLimitExceededException extends FileException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public FileNameLengthLimitExceededException(int defaultFileNameLength) {
|
||||
|
@@ -1,11 +1,14 @@
|
||||
package org.dromara.common.core.exception.file;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 文件名大小限制异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class FileSizeLimitExceededException extends FileException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public FileSizeLimitExceededException(long defaultMaxSize) {
|
||||
|
@@ -1,11 +1,14 @@
|
||||
package org.dromara.common.core.exception.user;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 验证码失效异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class CaptchaExpireException extends UserException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CaptchaExpireException() {
|
||||
|
@@ -2,12 +2,15 @@ package org.dromara.common.core.exception.user;
|
||||
|
||||
import org.dromara.common.core.exception.base.BaseException;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 用户信息异常类
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public class UserException extends BaseException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UserException(String code, Object... args) {
|
||||
|
@@ -1,11 +1,14 @@
|
||||
package org.dromara.common.core.exception.user;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 用户密码不正确或不符合规范异常类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UserPasswordNotMatchException extends UserException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UserPasswordNotMatchException() {
|
||||
|
@@ -1,200 +0,0 @@
|
||||
package org.dromara.common.core.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.SimpleCache;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.cglib.beans.BeanCopier;
|
||||
import org.springframework.cglib.beans.BeanMap;
|
||||
import org.springframework.cglib.core.Converter;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* bean拷贝工具(基于 cglib 性能优异)
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class BeanCopyUtils {
|
||||
|
||||
/**
|
||||
* 单对象基于class创建拷贝
|
||||
*
|
||||
* @param source 数据来源实体
|
||||
* @param desc 描述对象 转换后的对象
|
||||
* @return desc
|
||||
*/
|
||||
public static <T, V> V copy(T source, Class<V> desc) {
|
||||
if (ObjectUtil.isNull(source)) {
|
||||
return null;
|
||||
}
|
||||
if (ObjectUtil.isNull(desc)) {
|
||||
return null;
|
||||
}
|
||||
final V target = ReflectUtil.newInstanceIfPossible(desc);
|
||||
return copy(source, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单对象基于对象创建拷贝
|
||||
*
|
||||
* @param source 数据来源实体
|
||||
* @param desc 转换后的对象
|
||||
* @return desc
|
||||
*/
|
||||
public static <T, V> V copy(T source, V desc) {
|
||||
if (ObjectUtil.isNull(source)) {
|
||||
return null;
|
||||
}
|
||||
if (ObjectUtil.isNull(desc)) {
|
||||
return null;
|
||||
}
|
||||
BeanCopier beanCopier = BeanCopierCache.INSTANCE.get(source.getClass(), desc.getClass(), null);
|
||||
beanCopier.copy(source, desc, null);
|
||||
return desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表对象基于class创建拷贝
|
||||
*
|
||||
* @param sourceList 数据来源实体列表
|
||||
* @param desc 描述对象 转换后的对象
|
||||
* @return desc
|
||||
*/
|
||||
public static <T, V> List<V> copyList(List<T> sourceList, Class<V> desc) {
|
||||
if (ObjectUtil.isNull(sourceList)) {
|
||||
return null;
|
||||
}
|
||||
if (CollUtil.isEmpty(sourceList)) {
|
||||
return CollUtil.newArrayList();
|
||||
}
|
||||
return StreamUtils.toList(sourceList, source -> {
|
||||
V target = ReflectUtil.newInstanceIfPossible(desc);
|
||||
copy(source, target);
|
||||
return target;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* bean拷贝到map
|
||||
*
|
||||
* @param bean 数据来源实体
|
||||
* @return map对象
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Map<String, Object> copyToMap(T bean) {
|
||||
if (ObjectUtil.isNull(bean)) {
|
||||
return null;
|
||||
}
|
||||
return BeanMap.create(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* map拷贝到bean
|
||||
*
|
||||
* @param map 数据来源
|
||||
* @param beanClass bean类
|
||||
* @return bean对象
|
||||
*/
|
||||
public static <T> T mapToBean(Map<String, Object> map, Class<T> beanClass) {
|
||||
if (MapUtil.isEmpty(map)) {
|
||||
return null;
|
||||
}
|
||||
if (ObjectUtil.isNull(beanClass)) {
|
||||
return null;
|
||||
}
|
||||
T bean = ReflectUtil.newInstanceIfPossible(beanClass);
|
||||
return mapToBean(map, bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* map拷贝到bean
|
||||
*
|
||||
* @param map 数据来源
|
||||
* @param bean bean对象
|
||||
* @return bean对象
|
||||
*/
|
||||
public static <T> T mapToBean(Map<String, Object> map, T bean) {
|
||||
if (MapUtil.isEmpty(map)) {
|
||||
return null;
|
||||
}
|
||||
if (ObjectUtil.isNull(bean)) {
|
||||
return null;
|
||||
}
|
||||
BeanMap.create(bean).putAll(map);
|
||||
return bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* map拷贝到map
|
||||
*
|
||||
* @param map 数据来源
|
||||
* @param clazz 返回的对象类型
|
||||
* @return map对象
|
||||
*/
|
||||
public static <T, V> Map<String, V> mapToMap(Map<String, T> map, Class<V> clazz) {
|
||||
if (MapUtil.isEmpty(map)) {
|
||||
return null;
|
||||
}
|
||||
if (ObjectUtil.isNull(clazz)) {
|
||||
return null;
|
||||
}
|
||||
Map<String, V> copyMap = new LinkedHashMap<>(map.size());
|
||||
map.forEach((k, v) -> copyMap.put(k, copy(v, clazz)));
|
||||
return copyMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* BeanCopier属性缓存<br>
|
||||
* 缓存用于防止多次反射造成的性能问题
|
||||
*
|
||||
* @author Looly
|
||||
* @since 5.4.1
|
||||
*/
|
||||
public enum BeanCopierCache {
|
||||
/**
|
||||
* BeanCopier属性缓存单例
|
||||
*/
|
||||
INSTANCE;
|
||||
|
||||
private final SimpleCache<String, BeanCopier> cache = new SimpleCache<>();
|
||||
|
||||
/**
|
||||
* 获得类与转换器生成的key在{@link BeanCopier}的Map中对应的元素
|
||||
*
|
||||
* @param srcClass 源Bean的类
|
||||
* @param targetClass 目标Bean的类
|
||||
* @param converter 转换器
|
||||
* @return Map中对应的BeanCopier
|
||||
*/
|
||||
public BeanCopier get(Class<?> srcClass, Class<?> targetClass, Converter converter) {
|
||||
final String key = genKey(srcClass, targetClass, converter);
|
||||
return cache.get(key, () -> BeanCopier.create(srcClass, targetClass, converter != null));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得类与转换器生成的key
|
||||
*
|
||||
* @param srcClass 源Bean的类
|
||||
* @param targetClass 目标Bean的类
|
||||
* @param converter 转换器
|
||||
* @return 属性名和Map映射的key
|
||||
*/
|
||||
private String genKey(Class<?> srcClass, Class<?> targetClass, Converter converter) {
|
||||
final StringBuilder key = StrUtil.builder()
|
||||
.append(srcClass.getName()).append('#').append(targetClass.getName());
|
||||
if(null != converter){
|
||||
key.append('#').append(converter.getClass().getName());
|
||||
}
|
||||
return key.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -2,9 +2,11 @@ package org.dromara.common.core.utils;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.extra.servlet.JakartaServletUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import org.dromara.common.core.constant.Constants;
|
||||
import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -13,12 +15,7 @@ import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -215,11 +212,7 @@ public class ServletUtils extends JakartaServletUtil {
|
||||
* @return 编码后的内容
|
||||
*/
|
||||
public static String urlEncode(String str) {
|
||||
try {
|
||||
return URLEncoder.encode(str, Constants.UTF8);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
return URLEncoder.encode(str, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,11 +222,7 @@ public class ServletUtils extends JakartaServletUtil {
|
||||
* @return 解码后的内容
|
||||
*/
|
||||
public static String urlDecode(String str) {
|
||||
try {
|
||||
return URLDecoder.decode(str, Constants.UTF8);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
return URLDecoder.decode(str, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -256,17 +256,13 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
if (s != null) {
|
||||
final int len = s.length();
|
||||
if (s.length() <= size) {
|
||||
for (int i = size - len; i > 0; i--) {
|
||||
sb.append(c);
|
||||
}
|
||||
sb.append(String.valueOf(c).repeat(size - len));
|
||||
sb.append(s);
|
||||
} else {
|
||||
return s.substring(len - size, len);
|
||||
}
|
||||
} else {
|
||||
for (int i = size; i > 0; i--) {
|
||||
sb.append(c);
|
||||
}
|
||||
sb.append(String.valueOf(c).repeat(Math.max(0, size)));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
@@ -47,8 +47,8 @@ public class FileUtils extends FileUtil {
|
||||
* @param s 需要百分号编码的字符串
|
||||
* @return 百分号编码后的字符串
|
||||
*/
|
||||
public static String percentEncode(String s) throws UnsupportedEncodingException {
|
||||
String encode = URLEncoder.encode(s, StandardCharsets.UTF_8.toString());
|
||||
public static String percentEncode(String s) {
|
||||
String encode = URLEncoder.encode(s, StandardCharsets.UTF_8);
|
||||
return encode.replaceAll("\\+", "%20");
|
||||
}
|
||||
}
|
||||
|
@@ -56,21 +56,20 @@ public class MybatisDecryptInterceptor implements Interceptor {
|
||||
if (ObjectUtil.isNull(sourceObject)) {
|
||||
return;
|
||||
}
|
||||
if (sourceObject instanceof Map<?, ?>) {
|
||||
new HashSet<>(((Map<?, ?>) sourceObject).values()).forEach(this::decryptHandler);
|
||||
if (sourceObject instanceof Map<?, ?> map) {
|
||||
new HashSet<>(map.values()).forEach(this::decryptHandler);
|
||||
return;
|
||||
}
|
||||
if (sourceObject instanceof List<?>) {
|
||||
List<?> sourceList = (List<?>) sourceObject;
|
||||
if(CollUtil.isEmpty(sourceList)) {
|
||||
if (sourceObject instanceof List<?> list) {
|
||||
if(CollUtil.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
// 判断第一个元素是否含有注解。如果没有直接返回,提高效率
|
||||
Object firstItem = sourceList.get(0);
|
||||
Object firstItem = list.get(0);
|
||||
if (ObjectUtil.isNull(firstItem) || CollUtil.isEmpty(encryptorManager.getFieldCache(firstItem.getClass()))) {
|
||||
return;
|
||||
}
|
||||
((List<?>) sourceObject).forEach(this::decryptHandler);
|
||||
list.forEach(this::decryptHandler);
|
||||
return;
|
||||
}
|
||||
Set<Field> fields = encryptorManager.getFieldCache(sourceObject.getClass());
|
||||
|
@@ -46,9 +46,8 @@ public class MybatisEncryptInterceptor implements Interceptor {
|
||||
|
||||
@Override
|
||||
public Object plugin(Object target) {
|
||||
if (target instanceof ParameterHandler) {
|
||||
if (target instanceof ParameterHandler parameterHandler) {
|
||||
// 进行加密操作
|
||||
ParameterHandler parameterHandler = (ParameterHandler) target;
|
||||
Object parameterObject = parameterHandler.getParameterObject();
|
||||
if (ObjectUtil.isNotNull(parameterObject) && !(parameterObject instanceof String)) {
|
||||
this.encryptHandler(parameterObject);
|
||||
@@ -66,21 +65,20 @@ public class MybatisEncryptInterceptor implements Interceptor {
|
||||
if (ObjectUtil.isNull(sourceObject)) {
|
||||
return;
|
||||
}
|
||||
if (sourceObject instanceof Map<?, ?>) {
|
||||
new HashSet<>(((Map<?, ?>) sourceObject).values()).forEach(this::encryptHandler);
|
||||
if (sourceObject instanceof Map<?, ?> map) {
|
||||
new HashSet<>(map.values()).forEach(this::encryptHandler);
|
||||
return;
|
||||
}
|
||||
if (sourceObject instanceof List<?>) {
|
||||
List<?> sourceList = (List<?>) sourceObject;
|
||||
if(CollUtil.isEmpty(sourceList)) {
|
||||
if (sourceObject instanceof List<?> list) {
|
||||
if(CollUtil.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
// 判断第一个元素是否含有注解。如果没有直接返回,提高效率
|
||||
Object firstItem = sourceList.get(0);
|
||||
Object firstItem = list.get(0);
|
||||
if (ObjectUtil.isNull(firstItem) || CollUtil.isEmpty(encryptorManager.getFieldCache(firstItem.getClass()))) {
|
||||
return;
|
||||
}
|
||||
((List<?>) sourceObject).forEach(this::encryptHandler);
|
||||
list.forEach(this::encryptHandler);
|
||||
return;
|
||||
}
|
||||
Set<Field> fields = encryptorManager.getFieldCache(sourceObject.getClass());
|
||||
|
@@ -28,20 +28,19 @@ import java.util.Map;
|
||||
@Slf4j
|
||||
public class CellMergeStrategy extends AbstractMergeStrategy {
|
||||
|
||||
private final List<?> list;
|
||||
private final List<CellRangeAddress> cellList;
|
||||
private final boolean hasTitle;
|
||||
private int rowIndex;
|
||||
|
||||
public CellMergeStrategy(List<?> list, boolean hasTitle) {
|
||||
this.list = list;
|
||||
this.hasTitle = hasTitle;
|
||||
// 行合并开始下标
|
||||
this.rowIndex = hasTitle ? 1 : 0;
|
||||
this.cellList = handle(list, hasTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) {
|
||||
List<CellRangeAddress> cellList = handle(list, hasTitle);
|
||||
// judge the list is not null
|
||||
if (CollUtil.isNotEmpty(cellList)) {
|
||||
// the judge is necessary
|
||||
|
@@ -55,9 +55,8 @@ public class DefaultExcelListener<T> extends AnalysisEventListener<T> implements
|
||||
@Override
|
||||
public void onException(Exception exception, AnalysisContext context) throws Exception {
|
||||
String errMsg = null;
|
||||
if (exception instanceof ExcelDataConvertException) {
|
||||
if (exception instanceof ExcelDataConvertException excelDataConvertException) {
|
||||
// 如果是某一个单元格的转换异常 能获取到具体行号
|
||||
ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception;
|
||||
Integer rowIndex = excelDataConvertException.getRowIndex();
|
||||
Integer columnIndex = excelDataConvertException.getColumnIndex();
|
||||
errMsg = StrUtil.format("第{}行-第{}列-表头{}: 解析异常<br/>",
|
||||
@@ -66,8 +65,7 @@ public class DefaultExcelListener<T> extends AnalysisEventListener<T> implements
|
||||
log.error(errMsg);
|
||||
}
|
||||
}
|
||||
if (exception instanceof ConstraintViolationException) {
|
||||
ConstraintViolationException constraintViolationException = (ConstraintViolationException) exception;
|
||||
if (exception instanceof ConstraintViolationException constraintViolationException) {
|
||||
Set<ConstraintViolation<?>> constraintViolations = constraintViolationException.getConstraintViolations();
|
||||
String constraintViolationsMsg = StreamUtils.join(constraintViolations, ConstraintViolation::getMessage, ", ");
|
||||
errMsg = StrUtil.format("第{}行数据校验异常: {}", context.readRowHolder().getRowIndex() + 1, constraintViolationsMsg);
|
||||
|
@@ -276,7 +276,7 @@ public class ExcelUtil {
|
||||
if (StringUtils.containsAny(propertyValue, separator)) {
|
||||
for (String value : propertyValue.split(separator)) {
|
||||
if (itemArray[0].equals(value)) {
|
||||
propertyString.append(itemArray[1] + separator);
|
||||
propertyString.append(itemArray[1]).append(separator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -305,7 +305,7 @@ public class ExcelUtil {
|
||||
if (StringUtils.containsAny(propertyValue, separator)) {
|
||||
for (String value : propertyValue.split(separator)) {
|
||||
if (itemArray[1].equals(value)) {
|
||||
propertyString.append(itemArray[0] + separator);
|
||||
propertyString.append(itemArray[0]).append(separator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -76,9 +76,8 @@ public class RepeatSubmitAspect {
|
||||
*/
|
||||
@AfterReturning(pointcut = "@annotation(repeatSubmit)", returning = "jsonResult")
|
||||
public void doAfterReturning(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Object jsonResult) {
|
||||
if (jsonResult instanceof R) {
|
||||
if (jsonResult instanceof R<?> r) {
|
||||
try {
|
||||
R<?> r = (R<?>) jsonResult;
|
||||
// 成功则不删除redis数据 保证在有效时间内无法重复提交
|
||||
if (r.getCode() == R.SUCCESS) {
|
||||
return;
|
||||
|
@@ -1,25 +0,0 @@
|
||||
package org.dromara.common.log.domain.convert;
|
||||
|
||||
import org.dromara.common.log.event.OperLogEvent;
|
||||
import org.dromara.system.api.domain.bo.RemoteOperLogBo;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 操作日志转换器
|
||||
* @author zhujie
|
||||
*/
|
||||
@Mapper
|
||||
public interface OperLogEventConvert {
|
||||
|
||||
OperLogEventConvert INSTANCE = Mappers.getMapper(OperLogEventConvert.class);
|
||||
|
||||
/**
|
||||
* OperLogEventToRemoteOperLogBo
|
||||
* @param operLogEvent 待转换对象
|
||||
* @return 转换后对象
|
||||
*/
|
||||
@Mapping(target = "params", ignore = true)
|
||||
RemoteOperLogBo convert(OperLogEvent operLogEvent);
|
||||
}
|
@@ -1,14 +1,15 @@
|
||||
package org.dromara.common.log.event;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.http.useragent.UserAgent;
|
||||
import cn.hutool.http.useragent.UserAgentUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.common.core.constant.Constants;
|
||||
import org.dromara.common.core.utils.ServletUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.core.utils.ip.AddressUtils;
|
||||
import org.dromara.common.log.domain.convert.OperLogEventConvert;
|
||||
import org.dromara.system.api.RemoteLogService;
|
||||
import org.dromara.system.api.domain.bo.RemoteLogininforBo;
|
||||
import org.dromara.system.api.domain.bo.RemoteOperLogBo;
|
||||
@@ -16,8 +17,6 @@ import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 异步调用日志服务
|
||||
*
|
||||
@@ -36,7 +35,7 @@ public class LogEventListener {
|
||||
@Async
|
||||
@EventListener
|
||||
public void saveLog(OperLogEvent operLogEvent) {
|
||||
RemoteOperLogBo sysOperLog = OperLogEventConvert.INSTANCE.convert(operLogEvent);
|
||||
RemoteOperLogBo sysOperLog = BeanUtil.toBean(operLogEvent, RemoteOperLogBo.class);
|
||||
remoteLogService.saveLog(sysOperLog);
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,8 @@ package org.dromara.common.log.event;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -14,6 +16,7 @@ import java.io.Serializable;
|
||||
@Data
|
||||
public class LogininforEvent implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
@@ -2,6 +2,7 @@ package org.dromara.common.log.event;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -14,6 +15,7 @@ import java.util.Date;
|
||||
@Data
|
||||
public class OperLogEvent implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
@@ -9,6 +9,7 @@ import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.core.utils.sql.SqlUtil;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -22,6 +23,7 @@ import java.util.List;
|
||||
@Data
|
||||
public class PageQuery implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@@ -17,6 +18,7 @@ import java.util.List;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class TableDataInfo<T> implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
@@ -23,8 +23,8 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler {
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
try {
|
||||
if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) {
|
||||
BaseEntity baseEntity = (BaseEntity) metaObject.getOriginalObject();
|
||||
if (ObjectUtil.isNotNull(metaObject)
|
||||
&& metaObject.getOriginalObject() instanceof BaseEntity baseEntity) {
|
||||
Date current = ObjectUtil.isNotNull(baseEntity.getCreateTime())
|
||||
? baseEntity.getCreateTime() : new Date();
|
||||
baseEntity.setCreateTime(current);
|
||||
@@ -47,8 +47,8 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler {
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
try {
|
||||
if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) {
|
||||
BaseEntity baseEntity = (BaseEntity) metaObject.getOriginalObject();
|
||||
if (ObjectUtil.isNotNull(metaObject)
|
||||
&& metaObject.getOriginalObject() instanceof BaseEntity baseEntity) {
|
||||
Date current = new Date();
|
||||
// 更新时间填充(不管为不为空)
|
||||
baseEntity.setUpdateTime(current);
|
||||
|
@@ -6,6 +6,12 @@ import cn.hutool.core.collection.ConcurrentHashSet;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
import net.sf.jsqlparser.expression.Expression;
|
||||
import net.sf.jsqlparser.expression.Parenthesis;
|
||||
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
|
||||
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
@@ -17,12 +23,6 @@ import org.dromara.common.mybatis.helper.DataPermissionHelper;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.system.api.model.LoginUser;
|
||||
import org.dromara.system.api.model.RoleDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
import net.sf.jsqlparser.expression.Expression;
|
||||
import net.sf.jsqlparser.expression.Parenthesis;
|
||||
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
|
||||
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
||||
import org.springframework.context.expression.BeanFactoryResolver;
|
||||
import org.springframework.expression.BeanResolver;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
@@ -35,7 +35,6 @@ import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据权限过滤
|
||||
@@ -163,7 +162,7 @@ public class PlusDataPermissionHandler {
|
||||
String methodName = sb.substring(index + 1, sb.length());
|
||||
Class<?> clazz = ClassUtil.loadClass(clazzName);
|
||||
List<Method> methods = Arrays.stream(ClassUtil.getDeclaredMethods(clazz))
|
||||
.filter(method -> method.getName().equals(methodName)).collect(Collectors.toList());
|
||||
.filter(method -> method.getName().equals(methodName)).toList();
|
||||
DataPermission dataPermission;
|
||||
// 获取方法注解
|
||||
for (Method method : methods) {
|
||||
|
@@ -58,15 +58,15 @@ public class DataBaseHelper {
|
||||
String var = Convert.toStr(var1);
|
||||
if (dataBasyType == DataBaseType.SQL_SERVER) {
|
||||
// charindex(',100,' , ',0,100,101,') <> 0
|
||||
return "charindex('," + var + ",' , ','+" + var2 + "+',') <> 0";
|
||||
return "charindex(',%s,' , ','+%s+',') <> 0".formatted(var, var2);
|
||||
} else if (dataBasyType == DataBaseType.POSTGRE_SQL) {
|
||||
// (select position(',100,' in ',0,100,101,')) <> 0
|
||||
return "(select position('," + var + ",' in ','||" + var2 + "||',')) <> 0";
|
||||
return "(select position(',%s,' in ','||%s||',')) <> 0".formatted(var, var2);
|
||||
} else if (dataBasyType == DataBaseType.ORACLE) {
|
||||
// instr(',0,100,101,' , ',100,') <> 0
|
||||
return "instr(','||" + var2 + "||',' , '," + var + ",') <> 0";
|
||||
return "instr(','||%s||',' , ',%s,') <> 0".formatted(var2, var);
|
||||
}
|
||||
// find_in_set('100' , '0,100,101')
|
||||
return "find_in_set('" + var + "' , " + var2 + ") <> 0";
|
||||
return "find_in_set('%s' , %s) <> 0".formatted(var, var2);
|
||||
}
|
||||
}
|
||||
|
@@ -68,8 +68,7 @@ public class PlusDataPermissionInterceptor extends JsqlParserSupport implements
|
||||
SelectBody selectBody = select.getSelectBody();
|
||||
if (selectBody instanceof PlainSelect) {
|
||||
this.setWhere((PlainSelect) selectBody, (String) obj);
|
||||
} else if (selectBody instanceof SetOperationList) {
|
||||
SetOperationList setOperationList = (SetOperationList) selectBody;
|
||||
} else if (selectBody instanceof SetOperationList setOperationList) {
|
||||
List<SelectBody> selectBodyList = setOperationList.getSelects();
|
||||
selectBodyList.forEach(s -> this.setWhere((PlainSelect) s, (String) obj));
|
||||
}
|
||||
|
@@ -218,12 +218,11 @@ public class OssClient {
|
||||
private static String getPolicy(String bucketName, PolicyType policyType) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("{\n\"Statement\": [\n{\n\"Action\": [\n");
|
||||
if (policyType == PolicyType.WRITE) {
|
||||
builder.append("\"s3:GetBucketLocation\",\n\"s3:ListBucketMultipartUploads\"\n");
|
||||
} else if (policyType == PolicyType.READ_WRITE) {
|
||||
builder.append("\"s3:GetBucketLocation\",\n\"s3:ListBucket\",\n\"s3:ListBucketMultipartUploads\"\n");
|
||||
} else {
|
||||
builder.append("\"s3:GetBucketLocation\"\n");
|
||||
switch (policyType) {
|
||||
case WRITE -> builder.append("\"s3:GetBucketLocation\",\n\"s3:ListBucketMultipartUploads\"\n");
|
||||
case READ_WRITE ->
|
||||
builder.append("\"s3:GetBucketLocation\",\n\"s3:ListBucket\",\n\"s3:ListBucketMultipartUploads\"\n");
|
||||
default -> builder.append("\"s3:GetBucketLocation\"\n");
|
||||
}
|
||||
builder.append("],\n\"Effect\": \"Allow\",\n\"Principal\": \"*\",\n\"Resource\": \"arn:aws:s3:::");
|
||||
builder.append(bucketName);
|
||||
@@ -235,15 +234,11 @@ public class OssClient {
|
||||
}
|
||||
builder.append("{\n\"Action\": ");
|
||||
switch (policyType) {
|
||||
case WRITE:
|
||||
case WRITE ->
|
||||
builder.append("[\n\"s3:AbortMultipartUpload\",\n\"s3:DeleteObject\",\n\"s3:ListMultipartUploadParts\",\n\"s3:PutObject\"\n],\n");
|
||||
break;
|
||||
case READ_WRITE:
|
||||
case READ_WRITE ->
|
||||
builder.append("[\n\"s3:AbortMultipartUpload\",\n\"s3:DeleteObject\",\n\"s3:GetObject\",\n\"s3:ListMultipartUploadParts\",\n\"s3:PutObject\"\n],\n");
|
||||
break;
|
||||
default:
|
||||
builder.append("\"s3:GetObject\",\n");
|
||||
break;
|
||||
default -> builder.append("\"s3:GetObject\",\n");
|
||||
}
|
||||
builder.append("\"Effect\": \"Allow\",\n\"Principal\": \"*\",\n\"Resource\": \"arn:aws:s3:::");
|
||||
builder.append(bucketName);
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package org.dromara.common.oss.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* OSS异常类
|
||||
*
|
||||
@@ -7,6 +9,7 @@ package org.dromara.common.oss.exception;
|
||||
*/
|
||||
public class OssException extends RuntimeException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public OssException(String msg) {
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package org.dromara.common.sms.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* Sms异常类
|
||||
*
|
||||
@@ -7,6 +9,7 @@ package org.dromara.common.sms.exception;
|
||||
*/
|
||||
public class SmsException extends RuntimeException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SmsException(String msg) {
|
||||
|
@@ -3,6 +3,8 @@ package org.dromara.common.tenant.exception;
|
||||
|
||||
import org.dromara.common.core.exception.base.BaseException;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 租户异常类
|
||||
*
|
||||
@@ -10,6 +12,7 @@ import org.dromara.common.core.exception.base.BaseException;
|
||||
*/
|
||||
public class TenantException extends BaseException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public TenantException(String code, Object... args) {
|
||||
|
Reference in New Issue
Block a user