From eb2be90e74adfa06ee251f80c08243d0301ce467 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期三, 28 七月 2021 10:49:16 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' --- ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 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 new file mode 100644 index 0000000..bc7e7f3 --- /dev/null +++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/factory/OssFactory.java @@ -0,0 +1,45 @@ +package com.ruoyi.oss.factory; + +import cn.hutool.core.lang.Assert; +import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.oss.constant.CloudConstant; +import com.ruoyi.oss.enumd.CloudServiceEnumd; +import com.ruoyi.oss.service.ICloudStorageService; +import com.ruoyi.system.service.ISysConfigService; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * 鏂囦欢涓婁紶Factory + * + * @author Lion Li + */ +public class OssFactory { + + private static ISysConfigService sysConfigService; + + static { + OssFactory.sysConfigService = SpringUtils.getBean(ISysConfigService.class); + } + + private static final Map<String, ICloudStorageService> SERVICES = new ConcurrentHashMap<>(); + + public static ICloudStorageService instance() { + String type = sysConfigService.selectConfigByKey(CloudConstant.CLOUD_STORAGE_CONFIG_KEY); + return instance(type); + } + + public static ICloudStorageService instance(String type) { + ICloudStorageService service = SERVICES.get(type); + if (service == null) { + service = (ICloudStorageService) SpringUtils.getBean(CloudServiceEnumd.getServiceClass(type)); + } + return service; + } + + public static void register(String type, ICloudStorageService iCloudStorageService) { + Assert.notNull(type, "type can't be null"); + SERVICES.put(type, iCloudStorageService); + } +} -- Gitblit v1.9.3