diff --git a/pom.xml b/pom.xml
index f63154a..23bc21a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -32,6 +32,7 @@
4.5.2
5.0.0
5.0.0
+ 2.0.4
@@ -39,6 +40,10 @@
org.springframework.boot
spring-boot-starter-aop
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
org.springframework.boot
spring-boot-starter-web
@@ -193,6 +198,23 @@
${poi-ooxml.version}
+
+
+ com.aliyun
+ aliyun-java-sdk-core
+ 4.0.6
+
+
+
+ com.aliyun
+ aliyun-java-sdk-dysmsapi
+ 1.1.0
+
+
diff --git a/src/main/java/com/xkrs/common/config/RedisCacheAutoConfiguration.java b/src/main/java/com/xkrs/common/config/RedisCacheAutoConfiguration.java
new file mode 100644
index 0000000..6a0970b
--- /dev/null
+++ b/src/main/java/com/xkrs/common/config/RedisCacheAutoConfiguration.java
@@ -0,0 +1,30 @@
+package com.xkrs.common.config;
+
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+import java.io.Serializable;
+
+/**
+ * Redis 缓存自动配置
+ * @author tajochen
+ */
+@Configuration
+@AutoConfigureAfter(RedisAutoConfiguration.class)
+public class RedisCacheAutoConfiguration {
+
+ @Bean
+ public RedisTemplate redisCacheTemplate(LettuceConnectionFactory redisConnectionFactory) {
+ RedisTemplate template = new RedisTemplate<>();
+ template.setKeySerializer(new StringRedisSerializer());
+ template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
+ template.setConnectionFactory(redisConnectionFactory);
+ return template;
+ }
+}
diff --git a/src/main/java/com/xkrs/common/config/RedisConfig.java b/src/main/java/com/xkrs/common/config/RedisConfig.java
new file mode 100644
index 0000000..6c68f2c
--- /dev/null
+++ b/src/main/java/com/xkrs/common/config/RedisConfig.java
@@ -0,0 +1,161 @@
+package com.xkrs.common.config;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.annotation.CachingConfigurerSupport;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.cache.interceptor.CacheErrorHandler;
+import org.springframework.cache.interceptor.CacheResolver;
+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.RedisCacheManager;
+import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.RedisSerializationContext;
+import org.springframework.data.redis.serializer.RedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.time.Duration;
+
+/**
+ * redis配置
+ * @author tajochen
+ */
+@Configuration
+@EnableCaching
+public class RedisConfig extends CachingConfigurerSupport {
+
+ private static final Logger logger = LoggerFactory.getLogger(RedisConfig.class);
+
+ @Resource
+ private LettuceConnectionFactory lettuceConnectionFactory;
+
+ private Duration timeToLive = Duration.ofSeconds(3600*6);
+
+ @Bean
+ @Override
+ public KeyGenerator keyGenerator() {
+
+ // 设置自动key的生成规则,配置spring boot的注解,进行方法级别的缓存
+ return (target, method, params) -> {
+ StringBuilder sb = new StringBuilder();
+ sb.append(target.getClass().getName());
+ sb.append(":");
+ sb.append(method.getName());
+ for (Object obj : params) {
+ sb.append(":" + String.valueOf(obj));
+ }
+ String rsToUse = String.valueOf(sb);
+// logger.info("自动生成Redis Key -> [{}]", rsToUse);
+ return rsToUse;
+ };
+ }
+
+ @Bean
+ @Override
+ public CacheManager cacheManager() {
+ // 关键点,spring cache的注解使用的序列化都从这来,没有这个配置的话使用的jdk自己的序列化
+ RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
+ //key序列化方式
+ .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(keySerializer()))
+ //value序列化方式
+ .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(valueSerializer()))
+ .disableCachingNullValues()
+ .entryTtl(timeToLive);
+
+ RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager.RedisCacheManagerBuilder
+ .fromConnectionFactory(lettuceConnectionFactory)
+ .cacheDefaults(config)
+ .transactionAware();
+
+ return builder.build();
+ }
+
+
+ /**
+ * RedisTemplate配置 在单独使用redisTemplate的时候 重新定义序列化方式
+ */
+ @Bean
+ public RedisTemplate redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {
+ // 设置序列化
+ Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
+ ObjectMapper om = new ObjectMapper();
+ // 配置null值序列化成空字符串
+ om.getSerializerProvider().setNullValueSerializer(new JsonSerializer