疯狂的狮子Li
2024-05-27 94797a2d2b815fe7a4e8d884059a34e1d9bc74f3
ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/factory/OssFactory.java
@@ -24,6 +24,7 @@
public class OssFactory {
    private static final Map<String, OssClient> CLIENT_CACHE = new ConcurrentHashMap<>();
    private static final ReentrantLock LOCK = new ReentrantLock();
    /**
     * 获取默认实例
@@ -47,18 +48,23 @@
        }
        OssProperties properties = JsonUtils.parseObject(json, OssProperties.class);
        // 使用租户标识避免多个租户相同key实例覆盖
        String key = properties.getTenantId() + ":" + configKey;
        String key = configKey;
        if (StringUtils.isNotBlank(properties.getTenantId())) {
            key = properties.getTenantId() + ":" + configKey;
        }
        OssClient client = CLIENT_CACHE.get(key);
        // 客户端不存在或配置不相同则重新构建
        if (client == null || !client.checkPropertiesSame(properties)) {
            ReentrantLock lock = new ReentrantLock();
            lock.lock();
            LOCK.lock();
            try {
                CLIENT_CACHE.put(key, new OssClient(configKey, properties));
                log.info("创建OSS实例 key => {}", configKey);
                return CLIENT_CACHE.get(key);
                client = CLIENT_CACHE.get(key);
                if (client == null || !client.checkPropertiesSame(properties)) {
                    CLIENT_CACHE.put(key, new OssClient(configKey, properties));
                    log.info("创建OSS实例 key => {}", configKey);
                    return CLIENT_CACHE.get(key);
                }
            } finally {
                lock.unlock();
                LOCK.unlock();
            }
        }
        return client;