签到模块
This commit is contained in:
@@ -56,6 +56,10 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package cn.novalon.gym.manage.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* Redis 配置类(响应式版本)
|
||||
*
|
||||
* @author 付嘉
|
||||
* @date 2026-05-29
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
/**
|
||||
* 配置 ReactiveRedisTemplate
|
||||
*/
|
||||
@Bean
|
||||
public ReactiveRedisTemplate<String, Object> reactiveRedisTemplate(
|
||||
ReactiveRedisConnectionFactory connectionFactory) {
|
||||
|
||||
// 配置序列化上下文
|
||||
RedisSerializationContext<String, Object> serializationContext =
|
||||
RedisSerializationContext.<String, Object>newSerializationContext()
|
||||
.key(StringRedisSerializer.UTF_8)
|
||||
.value(new GenericJackson2JsonRedisSerializer())
|
||||
.hashKey(StringRedisSerializer.UTF_8)
|
||||
.hashValue(new GenericJackson2JsonRedisSerializer())
|
||||
.build();
|
||||
|
||||
return new ReactiveRedisTemplate<>(connectionFactory, serializationContext);
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package cn.novalon.gym.manage.common.constant;
|
||||
|
||||
/**
|
||||
* Redis 缓存 Key 常量类
|
||||
* 统一管理项目中所有 Redis 缓存的 key 前缀
|
||||
*
|
||||
* @author auto-generated
|
||||
* @date 2026-05-30
|
||||
*/
|
||||
public final class RedisKeyConstants {
|
||||
|
||||
private RedisKeyConstants() {
|
||||
}
|
||||
|
||||
// ==================== 会员模块 ====================
|
||||
|
||||
/**
|
||||
* 会员信息缓存
|
||||
* 格式:member:info:{memberId}
|
||||
*/
|
||||
public static final String MEMBER_INFO = "member:info:";
|
||||
|
||||
/**
|
||||
* 会员详情缓存
|
||||
* 格式:member:detail:{memberId}
|
||||
*/
|
||||
public static final String MEMBER_DETAIL = "member:detail:";
|
||||
|
||||
/**
|
||||
* 会员卡类型缓存
|
||||
* 格式:member:card:{memberCardId}
|
||||
*/
|
||||
public static final String MEMBER_CARD = "member:card:";
|
||||
|
||||
/**
|
||||
* 会员卡记录缓存(包含剩余次数/金额)
|
||||
* 格式:member:card:record:{recordId}
|
||||
*/
|
||||
public static final String MEMBER_CARD_RECORD = "member:card:record:";
|
||||
|
||||
/**
|
||||
* 会员退款申请缓存
|
||||
* 格式:member:refund:{recordId}
|
||||
*/
|
||||
public static final String MEMBER_REFUND = "member:refund:";
|
||||
|
||||
// ==================== 签到模块 ====================
|
||||
|
||||
/**
|
||||
* 用户当日二维码缓存
|
||||
* 格式:qrcode:user:daily:{userId}:{date}
|
||||
* 示例:qrcode:user:daily:1:2026-05-30
|
||||
*/
|
||||
public static final String QRCODE_USER_DAILY = "qrcode:user:daily:";
|
||||
|
||||
// ==================== 微信模块 ====================
|
||||
|
||||
/**
|
||||
* 微信 access_token 缓存
|
||||
* 格式:wechat:access_token:{appType}
|
||||
* appType: miniapp(小程序), mp(公众号)
|
||||
*/
|
||||
public static final String WECHAT_ACCESS_TOKEN = "wechat:access_token:";
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package cn.novalon.gym.manage.common.util;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* Redis 工具类(响应式版本)
|
||||
*
|
||||
* @author liwentao
|
||||
* @date 2026/5/15
|
||||
*/
|
||||
@Component
|
||||
public class RedisUtil {
|
||||
|
||||
@Autowired
|
||||
private ReactiveRedisTemplate<String, Object> reactiveRedisTemplate;
|
||||
|
||||
/**
|
||||
* 设置值
|
||||
*/
|
||||
public Mono<Boolean> set(String key, Object value) {
|
||||
return reactiveRedisTemplate.opsForValue().set(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置值并指定过期时间(秒)
|
||||
*/
|
||||
public Mono<Boolean> setWithExpire(String key, Object value, long timeoutSeconds) {
|
||||
return reactiveRedisTemplate.opsForValue().set(key, value, Duration.ofSeconds(timeoutSeconds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Mono<T> get(String key, Class<T> clazz) {
|
||||
return reactiveRedisTemplate.opsForValue().get(key)
|
||||
.map(obj -> clazz.isInstance(obj) ? (T) obj : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值(返回 Object)
|
||||
*/
|
||||
public Mono<Object> get(String key) {
|
||||
return reactiveRedisTemplate.opsForValue().get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除key
|
||||
*/
|
||||
public Mono<Long> delete(String key) {
|
||||
return reactiveRedisTemplate.delete(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断key是否存在
|
||||
*/
|
||||
public Mono<Boolean> hasKey(String key) {
|
||||
return reactiveRedisTemplate.hasKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置过期时间(秒)
|
||||
*/
|
||||
public Mono<Boolean> expire(String key, long timeoutSeconds) {
|
||||
return reactiveRedisTemplate.expire(key, Duration.ofSeconds(timeoutSeconds));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user