update 使用 策略+工厂 重写OSS模块

This commit is contained in:
疯狂的狮子li
2021-07-18 18:20:21 +08:00
parent d642c08c2e
commit 089e288a6e
26 changed files with 602 additions and 474 deletions

View File

@@ -0,0 +1,40 @@
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.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 SERVICES.get(type);
}
public static ICloudStorageService instance(String type) {
return SERVICES.get(type);
}
public static void register(String type, ICloudStorageService iCloudStorageService) {
Assert.notNull(type, "type can't be null");
SERVICES.put(type, iCloudStorageService);
}
}