feat(react-web-next): 新增.editorconfig和.prettierrc配置文件,添加public/.gitkeep占位文件
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
||||
package com.central.common.redis.tenant;
|
||||
|
||||
import com.central.common.service.UserTenantSelectionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 基于 Redis 的用户当前查询租户选择存储
|
||||
*/
|
||||
@Component
|
||||
@Primary
|
||||
@ConditionalOnClass(StringRedisTemplate.class)
|
||||
public class RedisUserTenantSelectionService implements UserTenantSelectionService {
|
||||
|
||||
private static final String KEY_PREFIX = "tenant:selection:"; // tenant:selection:{userId}
|
||||
private static final Duration TTL = Duration.ofDays(7);
|
||||
|
||||
@Autowired(required = false)
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Override
|
||||
public void setCurrentTenant(Long userId, String tenantId) {
|
||||
if (stringRedisTemplate == null || userId == null) {
|
||||
return;
|
||||
}
|
||||
String key = KEY_PREFIX + userId;
|
||||
if (tenantId == null) {
|
||||
stringRedisTemplate.delete(key);
|
||||
} else {
|
||||
stringRedisTemplate.opsForValue().set(key, tenantId, TTL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getCurrentTenant(Long userId) {
|
||||
if (stringRedisTemplate == null || userId == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
String val = stringRedisTemplate.opsForValue().get(KEY_PREFIX + userId);
|
||||
return Optional.ofNullable(val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCurrentTenant(Long userId) {
|
||||
if (stringRedisTemplate == null || userId == null) {
|
||||
return;
|
||||
}
|
||||
stringRedisTemplate.delete(KEY_PREFIX + userId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user