wang-hao-jie
2021-10-19 e48043a2df9ca0c73fe18298bab3c4d42ca5c0c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package cn.exrick.xboot.file.manage;
 
import cn.exrick.xboot.core.common.constant.CommonConstant;
import cn.exrick.xboot.core.common.constant.SettingConstant;
import cn.exrick.xboot.core.common.exception.XbootException;
import cn.exrick.xboot.core.entity.Setting;
import cn.exrick.xboot.core.service.SettingService;
import cn.exrick.xboot.file.manage.impl.*;
import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
/**
 * 工厂模式
 * @author Exrick
 */
@Component
public class FileManageFactory {
 
    @Autowired
    private SettingService settingService;
 
    @Autowired
    private QiniuFileManage qiniuFileManage;
 
    @Autowired
    private AliFileManage aliFileManage;
 
    @Autowired
    private TencentFileManage tencentFileManage;
 
    @Autowired
    private MinioFileManage minioFileManage;
 
    @Autowired
    private LocalFileManage localFileManage;
 
    /**
     * 使用配置的服务上传时location传入null 管理文件时需传入存储位置location
     * @param location
     * @return
     */
    public FileManage getFileManage(Integer location) {
 
        Setting setting = settingService.get(SettingConstant.OSS_USED);
        if (setting == null || StrUtil.isBlank(setting.getValue())) {
            throw new XbootException("您还未配置OSS存储服务");
        }
        String type = setting.getValue();
        if ((type.equals(SettingConstant.QINIU_OSS) && location == null) || CommonConstant.OSS_QINIU.equals(location)) {
            return qiniuFileManage;
        } else if ((type.equals(SettingConstant.ALI_OSS) && location == null) || CommonConstant.OSS_ALI.equals(location)) {
            return aliFileManage;
        } else if ((type.equals(SettingConstant.TENCENT_OSS) && location == null) || CommonConstant.OSS_TENCENT.equals(location)) {
            return tencentFileManage;
        } else if ((type.equals(SettingConstant.MINIO_OSS) && location == null) || CommonConstant.OSS_MINIO.equals(location)) {
            return minioFileManage;
        } else if ((type.equals(SettingConstant.LOCAL_OSS) && location == null) || CommonConstant.OSS_LOCAL.equals(location)) {
            return localFileManage;
        } else {
            throw new XbootException("暂不支持该存储配置,请检查配置");
        }
    }
}