| | |
| | | package com.ruoyi.oss.factory; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.common.utils.RedisUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | |
| | | @Slf4j |
| | | public class OssFactory { |
| | | |
| | | static { |
| | | RedisUtils.subscribe(CloudConstant.CACHE_CONFIG_KEY, String.class, msg -> { |
| | | refreshService(msg); |
| | | log.info("订阅刷新OSS配置 => " + msg); |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 服务实例缓存 |
| | | */ |
| | | private static final Map<String, ICloudStorageStrategy> SERVICES = new ConcurrentHashMap<>(); |
| | | |
| | | /** |
| | | * 初始化工厂 |
| | | */ |
| | | public static void init() { |
| | | log.info("初始化OSS工厂"); |
| | | RedisUtils.subscribe(CloudConstant.CACHE_CONFIG_KEY, String.class, msg -> { |
| | | refreshService(msg); |
| | | log.info("订阅刷新OSS配置 => " + msg); |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 获取默认实例 |
| | | */ |
| | | public static ICloudStorageStrategy instance() { |
| | | // 获取redis 默认类型 |
| | | String type = Convert.toStr(RedisUtils.getCacheObject(CloudConstant.CACHE_CONFIG_KEY)); |
| | | String type = RedisUtils.getCacheObject(CloudConstant.CACHE_CONFIG_KEY); |
| | | if (StringUtils.isEmpty(type)) { |
| | | throw new OssException("文件存储服务类型无法找到!"); |
| | | } |