mirror of
https://gitee.com/orangeform/orange-admin.git
synced 2026-01-18 11:06:36 +08:00
commit:添加多对多关联中间表更新支持,功能位于 班级管理 -> 课程 -> 编辑课程顺序
This commit is contained in:
@@ -20,8 +20,8 @@ import java.util.stream.Collectors;
|
||||
*
|
||||
* @param <K> 字典表主键类型。
|
||||
* @param <V> 字典表对象类型。
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Slf4j
|
||||
public class RedisDictionaryCache<K, V> implements DictionaryCache<K, V> {
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.util.stream.Collectors;
|
||||
*
|
||||
* @param <K> 字典表主键类型。
|
||||
* @param <V> 字典表对象类型。
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Slf4j
|
||||
public class RedisTreeDictionaryCache<K, V> extends RedisDictionaryCache<K, V> {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.orange.demo.common.redis.cache;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.redisson.spring.cache.CacheConfig;
|
||||
import org.redisson.spring.cache.RedissonSpringCacheManager;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 使用Redisson作为Redis的分布式缓存库。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
public class RedissonCacheConfig {
|
||||
|
||||
private static final int DEFAULT_TTL = 3600000;
|
||||
|
||||
/**
|
||||
* 定义cache名称、超时时长(毫秒)。
|
||||
*/
|
||||
public enum CacheEnum {
|
||||
/**
|
||||
* session下上传文件名的缓存(时间是24小时)。
|
||||
*/
|
||||
UPLOAD_FILENAME_CACHE(86400000);
|
||||
|
||||
/**
|
||||
* 缓存的时长(单位:毫秒)
|
||||
*/
|
||||
private int ttl = DEFAULT_TTL;
|
||||
|
||||
CacheEnum() {
|
||||
}
|
||||
|
||||
CacheEnum(int ttl) {
|
||||
this.ttl = ttl;
|
||||
}
|
||||
|
||||
public int getTtl() {
|
||||
return ttl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化缓存配置。
|
||||
*/
|
||||
@Bean
|
||||
CacheManager cacheManager(RedissonClient redissonClient) {
|
||||
Map<String, CacheConfig> config = Maps.newHashMap();
|
||||
for (CacheEnum c : CacheEnum.values()) {
|
||||
config.put(c.name(), new CacheConfig(c.getTtl(), 0));
|
||||
}
|
||||
return new RedissonSpringCacheManager(redissonClient, config);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.orange.demo.common.redis.cache;
|
||||
|
||||
import com.orange.demo.common.core.object.TokenData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Session数据缓存辅助类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Component
|
||||
public class SessionCacheHelper {
|
||||
|
||||
@Autowired
|
||||
private CacheManager cacheManager;
|
||||
|
||||
/**
|
||||
* 缓存当前session内,上传过的文件名。
|
||||
*
|
||||
* @param filename 通常是本地存储的文件名,而不是上传时的原始文件名。
|
||||
*/
|
||||
public void putSessionUploadFile(String filename) {
|
||||
if (filename != null) {
|
||||
Set<String> sessionUploadFileSet = null;
|
||||
Cache cache = cacheManager.getCache(RedissonCacheConfig.CacheEnum.UPLOAD_FILENAME_CACHE.name());
|
||||
Cache.ValueWrapper valueWrapper = cache.get(TokenData.takeFromRequest().getSessionId());
|
||||
if (valueWrapper != null) {
|
||||
sessionUploadFileSet = (Set<String>) valueWrapper.get();
|
||||
}
|
||||
if (sessionUploadFileSet == null) {
|
||||
sessionUploadFileSet = new HashSet<>();
|
||||
}
|
||||
sessionUploadFileSet.add(filename);
|
||||
cache.put(TokenData.takeFromRequest().getSessionId(), sessionUploadFileSet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断参数中的文件名,是否有当前session上传。
|
||||
*
|
||||
* @param filename 通常是本地存储的文件名,而不是上传时的原始文件名。
|
||||
* @return true表示该文件是由当前session上传并存储在本地的,否则false。
|
||||
*/
|
||||
public boolean existSessionUploadFile(String filename) {
|
||||
if (filename == null) {
|
||||
return false;
|
||||
}
|
||||
Cache cache = cacheManager.getCache(RedissonCacheConfig.CacheEnum.UPLOAD_FILENAME_CACHE.name());
|
||||
Cache.ValueWrapper valueWrapper = cache.get(TokenData.takeFromRequest().getSessionId());
|
||||
if (valueWrapper == null) {
|
||||
return false;
|
||||
}
|
||||
return ((Set<String>) valueWrapper.get()).contains(filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除当前session的所有缓存数据。
|
||||
*/
|
||||
public void removeAllSessionCache() {
|
||||
for (RedissonCacheConfig.CacheEnum c : RedissonCacheConfig.CacheEnum.values()) {
|
||||
cacheManager.getCache(c.name()).clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,8 @@ import redis.clients.jedis.JedisPoolConfig;
|
||||
/**
|
||||
* Redis配置类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(name = "redis.jedis.enabled", havingValue = "true")
|
||||
|
||||
@@ -12,8 +12,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
* Redisson配置类。和Jedis一样都是Redis客户端,但是Redisson提供了更多的数据结构抽象。
|
||||
* 这里我们只是使用了Redisson的分布式锁,以及map等数据结构作为字典缓存使用。更多用法请参考其文档。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(name = "redis.redisson.enabled", havingValue = "true")
|
||||
|
||||
Reference in New Issue
Block a user