From c636e6909b8ed1dc1dba18bceca2554d5adde7f9 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期五, 21 一月 2022 18:29:44 +0800
Subject: [PATCH] Merge remote-tracking branch 'ruoyi-vue/master' into dev

---
 ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java |   79 ++++++++++++++++++++-------------------
 1 files changed, 41 insertions(+), 38 deletions(-)

diff --git a/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java b/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java
index 56ea522..0107955 100644
--- a/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java
+++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java
@@ -1,8 +1,8 @@
 package com.ruoyi.oss.factory;
 
 import com.ruoyi.common.utils.JsonUtils;
-import com.ruoyi.common.utils.RedisUtils;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.redis.RedisUtils;
 import com.ruoyi.common.utils.reflect.ReflectUtils;
 import com.ruoyi.oss.constant.OssConstant;
 import com.ruoyi.oss.enumd.OssEnumd;
@@ -23,56 +23,59 @@
 @Slf4j
 public class OssFactory {
 
-	/**
-	 * 鏈嶅姟瀹炰緥缂撳瓨
-	 */
-	private static final Map<String, IOssStrategy> SERVICES = new ConcurrentHashMap<>();
+    /**
+     * 鏈嶅姟瀹炰緥缂撳瓨
+     */
+    private static final Map<String, IOssStrategy> SERVICES = new ConcurrentHashMap<>();
 
     /**
      * 鍒濆鍖栧伐鍘�
      */
     public static void init() {
         log.info("鍒濆鍖朞SS宸ュ巶");
-        RedisUtils.subscribe(OssConstant.CACHE_CONFIG_KEY, String.class, msg -> {
-            refreshService(msg);
-            log.info("璁㈤槄鍒锋柊OSS閰嶇疆 => " + msg);
+        RedisUtils.subscribe(OssConstant.CACHE_CONFIG_KEY, String.class, type -> {
+            // 娌℃湁鐨勫疄渚嬩笉澶勭悊
+            if (SERVICES.containsKey(type)) {
+                refreshService(type);
+                log.info("璁㈤槄鍒锋柊OSS閰嶇疆 => " + type);
+            }
         });
     }
 
-	/**
-	 * 鑾峰彇榛樿瀹炰緥
-	 */
-	public static IOssStrategy instance() {
-		// 鑾峰彇redis 榛樿绫诲瀷
-		String type = RedisUtils.getCacheObject(OssConstant.CACHE_CONFIG_KEY);
-		if (StringUtils.isEmpty(type)) {
-			throw new OssException("鏂囦欢瀛樺偍鏈嶅姟绫诲瀷鏃犳硶鎵惧埌!");
-		}
-		return instance(type);
-	}
+    /**
+     * 鑾峰彇榛樿瀹炰緥
+     */
+    public static IOssStrategy instance() {
+        // 鑾峰彇redis 榛樿绫诲瀷
+        String type = RedisUtils.getCacheObject(OssConstant.CACHE_CONFIG_KEY);
+        if (StringUtils.isEmpty(type)) {
+            throw new OssException("鏂囦欢瀛樺偍鏈嶅姟绫诲瀷鏃犳硶鎵惧埌!");
+        }
+        return instance(type);
+    }
 
-	/**
-	 * 鏍规嵁绫诲瀷鑾峰彇瀹炰緥
-	 */
-	public static IOssStrategy instance(String type) {
+    /**
+     * 鏍规嵁绫诲瀷鑾峰彇瀹炰緥
+     */
+    public static IOssStrategy instance(String type) {
         IOssStrategy service = SERVICES.get(type);
-		if (service == null) {
-			refreshService(type);
-			service = SERVICES.get(type);
-		}
-		return service;
-	}
+        if (service == null) {
+            refreshService(type);
+            service = SERVICES.get(type);
+        }
+        return service;
+    }
 
-	private static void refreshService(String type) {
-		Object json = RedisUtils.getCacheObject(OssConstant.SYS_OSS_KEY + type);
+    private static void refreshService(String type) {
+        Object json = RedisUtils.getCacheObject(OssConstant.SYS_OSS_KEY + type);
         OssProperties properties = JsonUtils.parseObject(json.toString(), OssProperties.class);
-		if (properties == null) {
-			throw new OssException("绯荤粺寮傚父, '" + type + "'閰嶇疆淇℃伅涓嶅瓨鍦�!");
-		}
-		// 鑾峰彇redis閰嶇疆淇℃伅 鍒涘缓瀵硅薄 骞剁紦瀛�
+        if (properties == null) {
+            throw new OssException("绯荤粺寮傚父, '" + type + "'閰嶇疆淇℃伅涓嶅瓨鍦�!");
+        }
+        // 鑾峰彇redis閰嶇疆淇℃伅 鍒涘缓瀵硅薄 骞剁紦瀛�
         IOssStrategy service = (IOssStrategy) ReflectUtils.newInstance(OssEnumd.getServiceClass(type));
-		((AbstractOssStrategy)service).init(properties);
-		SERVICES.put(type, service);
-	}
+        ((AbstractOssStrategy) service).init(properties);
+        SERVICES.put(type, service);
+    }
 
 }

--
Gitblit v1.9.3