mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-10-14 13:50:25 +00:00
feat 同步商业版代码
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.bootx.platform</groupId>
|
||||
<artifactId>bootx-platform-common</artifactId>
|
||||
<version>3.0.0.beta5</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>common-cache</artifactId>
|
||||
<description>缓存配置</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- 缓存包 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
</dependency>
|
||||
<!-- redis配置 -->
|
||||
<dependency>
|
||||
<groupId>cn.bootx.platform</groupId>
|
||||
<artifactId>common-redis</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
@@ -1,18 +0,0 @@
|
||||
package cn.bootx.platform.common.cache;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
/**
|
||||
* 缓存配置
|
||||
*
|
||||
* @author xxm
|
||||
* @since 2022/12/18
|
||||
*/
|
||||
@ComponentScan
|
||||
@ConfigurationPropertiesScan
|
||||
@AutoConfiguration
|
||||
public class CacheAutoConfiguration {
|
||||
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
package cn.bootx.platform.common.cache.configuration;
|
||||
|
||||
import org.springframework.data.redis.cache.RedisCache;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheWriter;
|
||||
import jakarta.annotation.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 自定义RedisCache, 缓存值为空不报错
|
||||
*
|
||||
* @author xxm
|
||||
* @since 2021/7/6
|
||||
*/
|
||||
public class BootxRedisCache extends RedisCache {
|
||||
|
||||
/**
|
||||
* Create new {@link RedisCache}.
|
||||
* @param name must not be {@literal null}.
|
||||
* @param cacheWriter must not be {@literal null}.
|
||||
* @param cacheConfig must not be {@literal null}.
|
||||
*/
|
||||
protected BootxRedisCache(String name, RedisCacheWriter cacheWriter, RedisCacheConfiguration cacheConfig) {
|
||||
super(name, cacheWriter, cacheConfig);
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Override
|
||||
public void put(Object key, @Nullable Object value) {
|
||||
// 允许为空或者非空值
|
||||
if (isAllowNullValues() || Objects.nonNull(value)) {
|
||||
super.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,89 +0,0 @@
|
||||
package cn.bootx.platform.common.cache.configuration;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.redis.cache.RedisCache;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
import org.springframework.data.redis.cache.RedisCacheWriter;
|
||||
import jakarta.annotation.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 自定义Redis缓存管理
|
||||
*
|
||||
* @author xxm
|
||||
* @since 2021/6/11
|
||||
*/
|
||||
public class BootxRedisCacheManager extends RedisCacheManager {
|
||||
|
||||
@Setter
|
||||
private Map<String, Integer> keysTtl;
|
||||
|
||||
private final RedisCacheWriter cacheWriter;
|
||||
|
||||
public BootxRedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) {
|
||||
super(cacheWriter, defaultCacheConfiguration);
|
||||
this.cacheWriter = cacheWriter;
|
||||
}
|
||||
|
||||
public BootxRedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
|
||||
String... initialCacheNames) {
|
||||
super(cacheWriter, defaultCacheConfiguration, initialCacheNames);
|
||||
this.cacheWriter = cacheWriter;
|
||||
}
|
||||
|
||||
public BootxRedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
|
||||
boolean allowInFlightCacheCreation, String... initialCacheNames) {
|
||||
super(cacheWriter, defaultCacheConfiguration, allowInFlightCacheCreation, initialCacheNames);
|
||||
this.cacheWriter = cacheWriter;
|
||||
}
|
||||
|
||||
public BootxRedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
|
||||
Map<String, RedisCacheConfiguration> initialCacheConfigurations) {
|
||||
super(cacheWriter, defaultCacheConfiguration, initialCacheConfigurations);
|
||||
this.cacheWriter = cacheWriter;
|
||||
}
|
||||
|
||||
public BootxRedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
|
||||
Map<String, RedisCacheConfiguration> initialCacheConfigurations, boolean allowInFlightCacheCreation) {
|
||||
super(cacheWriter, defaultCacheConfiguration, initialCacheConfigurations, allowInFlightCacheCreation);
|
||||
this.cacheWriter = cacheWriter;
|
||||
}
|
||||
|
||||
public BootxRedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
|
||||
boolean allowRuntimeCacheCreation, Map<String, RedisCacheConfiguration> initialCacheConfigurations) {
|
||||
super(cacheWriter, defaultCacheConfiguration, allowRuntimeCacheCreation, initialCacheConfigurations);
|
||||
this.cacheWriter = cacheWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Redis缓存
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
|
||||
protected RedisCache createRedisCache(@Nullable String name, @Nullable RedisCacheConfiguration cacheConfig) {
|
||||
Optional<String> keyOptional = keysTtl.keySet()
|
||||
.stream()
|
||||
.sorted((o1, o2) -> StrUtil.compare(o2, o1, false))
|
||||
.filter(name::startsWith)
|
||||
.findFirst();
|
||||
// 是自定义的key
|
||||
if (keyOptional.isPresent()) {
|
||||
String key = keyOptional.get();
|
||||
return this.createBootxRedisCache(name, cacheConfig.entryTtl(Duration.ofSeconds(keysTtl.get(key))));
|
||||
}
|
||||
return this.createBootxRedisCache(name, cacheConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换为自定义的RedisCache
|
||||
*/
|
||||
public BootxRedisCache createBootxRedisCache(String name, RedisCacheConfiguration cacheConfig) {
|
||||
return new BootxRedisCache(name, this.cacheWriter, cacheConfig);
|
||||
}
|
||||
|
||||
}
|
@@ -1,27 +0,0 @@
|
||||
package cn.bootx.platform.common.cache.configuration;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* spring cache 配置
|
||||
*
|
||||
* @author xxm
|
||||
* @since 2021/6/11
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ConfigurationProperties(prefix = "bootx-platform.common.cache")
|
||||
public class CachingProperties {
|
||||
|
||||
/** 默认超时时间 30分钟 */
|
||||
private Integer defaultTtl = 60 * 30;
|
||||
|
||||
/** 自定义过期时间 秒 */
|
||||
private Map<String, Integer> keysTtl = new HashMap<>();
|
||||
|
||||
}
|
@@ -1,87 +0,0 @@
|
||||
package cn.bootx.platform.common.cache.manager;
|
||||
|
||||
import cn.bootx.platform.common.cache.configuration.BootxRedisCacheManager;
|
||||
import cn.bootx.platform.common.cache.configuration.CachingProperties;
|
||||
import cn.bootx.platform.common.serializer.KryoRedisSerializer;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheWriter;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* 缓存自动配置
|
||||
*
|
||||
* @author xxm
|
||||
* @since 2021/6/11
|
||||
*/
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
@EnableConfigurationProperties(CachingProperties.class)
|
||||
@ConditionalOnClass(CacheManager.class)
|
||||
@ConditionalOnProperty(prefix = "bootx-platform.cache", value = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
public class CachingConfiguration extends CachingConfigurerSupport {
|
||||
|
||||
private final CachingProperties cachingProperties;
|
||||
|
||||
private final KryoRedisSerializer<?> kryoRedisSerializer;
|
||||
|
||||
public CachingConfiguration(CachingProperties cachingProperties, KryoRedisSerializer<?> kryoRedisSerializer) {
|
||||
this.cachingProperties = cachingProperties;
|
||||
this.kryoRedisSerializer = kryoRedisSerializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 不配置key的情况,将方法名作为缓存key名称
|
||||
*/
|
||||
@Override
|
||||
public KeyGenerator keyGenerator() {
|
||||
return (target, method, params) -> method.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存管理器
|
||||
*/
|
||||
@Bean
|
||||
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
|
||||
|
||||
BootxRedisCacheManager bootxRedisCacheManager = new BootxRedisCacheManager(
|
||||
// Redis 缓存写入器
|
||||
RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory),
|
||||
// 默认配置
|
||||
this.getRedisCacheConfigurationWithTtl(Duration.ofSeconds(cachingProperties.getDefaultTtl())));
|
||||
bootxRedisCacheManager.setKeysTtl(cachingProperties.getKeysTtl());
|
||||
return bootxRedisCacheManager;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存管理器策略过期时间配置
|
||||
*/
|
||||
private RedisCacheConfiguration getRedisCacheConfigurationWithTtl(Duration duration) {
|
||||
// redis缓存配置
|
||||
return RedisCacheConfiguration.defaultCacheConfig()
|
||||
// 设置key为String
|
||||
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
|
||||
// 设置value 序列化方式
|
||||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(kryoRedisSerializer))
|
||||
// 不缓存null
|
||||
.disableCachingNullValues()
|
||||
// 覆盖默认的构造key,否则会多出一个冒号
|
||||
.computePrefixWith(name -> name + ":")
|
||||
// 过期时间
|
||||
.entryTtl(duration);
|
||||
}
|
||||
|
||||
}
|
@@ -1 +0,0 @@
|
||||
cn.bootx.platform.common.cache.CacheAutoConfiguration
|
@@ -15,6 +15,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.converter.HttpMessageConversionException;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
@@ -38,6 +40,7 @@ public class RestExceptionHandler {
|
||||
|
||||
private final ExceptionHandlerProperties properties;
|
||||
|
||||
|
||||
/**
|
||||
* 普通业务异常, 不需要进行堆栈跟踪
|
||||
*/
|
||||
@@ -128,12 +131,13 @@ public class RestExceptionHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求参数校验未通过
|
||||
* 页面或资源不存在
|
||||
*/
|
||||
@ExceptionHandler({ NoResourceFoundException.class })
|
||||
public Result<Void> handleBusinessException(NoResourceFoundException ex) {
|
||||
public ResponseEntity<Result<Void>> handleBusinessException(NoResourceFoundException ex) {
|
||||
log.info(ex.getMessage(), ex);
|
||||
return Res.response(CommonErrorCode.SOURCES_NOT_EXIST, "页面或资源不存在", MDC.get(CommonCode.TRACE_ID));
|
||||
Result<Void> result = Res.response(CommonErrorCode.SOURCES_NOT_EXIST, "页面或资源不存在", MDC.get(CommonCode.TRACE_ID));
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -48,13 +48,13 @@
|
||||
</dependency>
|
||||
<!-- 翻译组件 -->
|
||||
<dependency>
|
||||
<groupId>com.fhs-opensource</groupId>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>easy-trans-spring-boot-starter</artifactId>
|
||||
<version>${easytrans.version}</version>
|
||||
</dependency>
|
||||
<!-- 翻译组件 MP扩展 -->
|
||||
<dependency>
|
||||
<groupId>com.fhs-opensource</groupId>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>easy-trans-mybatis-plus-extend</artifactId>
|
||||
<version>${easytrans.version}</version>
|
||||
</dependency>
|
||||
|
@@ -3,7 +3,7 @@ package cn.bootx.platform.common.mybatisplus.base;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.OrderBy;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fhs.core.trans.vo.TransPojo;
|
||||
import org.dromara.core.trans.vo.TransPojo;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
|
@@ -22,7 +22,6 @@
|
||||
<module>common-config</module>
|
||||
<module>common-header-holder</module>
|
||||
<module>common-redis</module>
|
||||
<module>common-cache</module>
|
||||
<module>common-log</module>
|
||||
</modules>
|
||||
|
||||
|
Reference in New Issue
Block a user