Commit 05d4aae65d624ba08935792f64f33468f199b77f

Authored by YunaiV
1 parent 3d40fc81

完成 yudao-spring-boot-starter-file 组件,支持 S3 对接云存储、local、ftp、sftp、db 等协议

Showing 26 changed files with 271 additions and 33 deletions
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/config/YudaoPayAutoConfiguration.java
@@ -11,6 +11,7 @@ import org.springframework.context.annotation.Configuration; @@ -11,6 +11,7 @@ import org.springframework.context.annotation.Configuration;
11 * 11 *
12 * @author 芋道源码 12 * @author 芋道源码
13 */ 13 */
  14 +@Configuration
14 @EnableConfigurationProperties(PayProperties.class) 15 @EnableConfigurationProperties(PayProperties.class)
15 public class YudaoPayAutoConfiguration { 16 public class YudaoPayAutoConfiguration {
16 17
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java
@@ -27,11 +27,11 @@ public class PayClientFactoryImpl implements PayClientFactory { @@ -27,11 +27,11 @@ public class PayClientFactoryImpl implements PayClientFactory {
27 * 支付客户端 Map 27 * 支付客户端 Map
28 * key:渠道编号 28 * key:渠道编号
29 */ 29 */
30 - private final ConcurrentMap<Long, AbstractPayClient<?>> channelIdClients = new ConcurrentHashMap<>(); 30 + private final ConcurrentMap<Long, AbstractPayClient<?>> clients = new ConcurrentHashMap<>();
31 31
32 @Override 32 @Override
33 public PayClient getPayClient(Long channelId) { 33 public PayClient getPayClient(Long channelId) {
34 - AbstractPayClient<?> client = channelIdClients.get(channelId); 34 + AbstractPayClient<?> client = clients.get(channelId);
35 if (client == null) { 35 if (client == null) {
36 log.error("[getPayClient][渠道编号({}) 找不到客户端]", channelId); 36 log.error("[getPayClient][渠道编号({}) 找不到客户端]", channelId);
37 } 37 }
@@ -42,11 +42,11 @@ public class PayClientFactoryImpl implements PayClientFactory { @@ -42,11 +42,11 @@ public class PayClientFactoryImpl implements PayClientFactory {
42 @SuppressWarnings("unchecked") 42 @SuppressWarnings("unchecked")
43 public <Config extends PayClientConfig> void createOrUpdatePayClient(Long channelId, String channelCode, 43 public <Config extends PayClientConfig> void createOrUpdatePayClient(Long channelId, String channelCode,
44 Config config) { 44 Config config) {
45 - AbstractPayClient<Config> client = (AbstractPayClient<Config>) channelIdClients.get(channelId); 45 + AbstractPayClient<Config> client = (AbstractPayClient<Config>) clients.get(channelId);
46 if (client == null) { 46 if (client == null) {
47 client = this.createPayClient(channelId, channelCode, config); 47 client = this.createPayClient(channelId, channelCode, config);
48 client.init(); 48 client.init();
49 - channelIdClients.put(client.getId(), client); 49 + clients.put(client.getId(), client);
50 } else { 50 } else {
51 client.refresh(config); 51 client.refresh(config);
52 } 52 }
@@ -69,7 +69,7 @@ public class PayClientFactoryImpl implements PayClientFactory { @@ -69,7 +69,7 @@ public class PayClientFactoryImpl implements PayClientFactory {
69 case ALIPAY_PC: return (AbstractPayClient<Config>) new AlipayQrPayClient(channelId, (AlipayPayClientConfig) config); 69 case ALIPAY_PC: return (AbstractPayClient<Config>) new AlipayQrPayClient(channelId, (AlipayPayClientConfig) config);
70 } 70 }
71 // 创建失败,错误日志 + 抛出异常 71 // 创建失败,错误日志 + 抛出异常
72 - log.error("[createSmsClient][配置({}) 找不到合适的客户端实现]", config); 72 + log.error("[createPayClient][配置({}) 找不到合适的客户端实现]", config);
73 throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", config)); 73 throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", config));
74 } 74 }
75 75
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java
@@ -56,5 +56,4 @@ public enum PayChannelEnum { @@ -56,5 +56,4 @@ public enum PayChannelEnum {
56 return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values()); 56 return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values());
57 } 57 }
58 58
59 -  
60 } 59 }
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/config/YudaoFileAutoConfiguration.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.file.config;
  2 +
  3 +import cn.iocoder.yudao.framework.file.core.client.FileClientFactory;
  4 +import cn.iocoder.yudao.framework.file.core.client.FileClientFactoryImpl;
  5 +import org.springframework.context.annotation.Bean;
  6 +import org.springframework.context.annotation.Configuration;
  7 +
  8 +/**
  9 + * 文件配置类
  10 + *
  11 + * @author 芋道源码
  12 + */
  13 +@Configuration
  14 +public class YudaoFileAutoConfiguration {
  15 +
  16 + @Bean
  17 + public FileClientFactory fileClientFactory() {
  18 + return new FileClientFactoryImpl();
  19 + }
  20 +
  21 +}
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/AbstractFileClient.java renamed to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/AbstractFileClient.java
1 -package cn.iocoder.yudao.framework.file.core.client.impl; 1 +package cn.iocoder.yudao.framework.file.core.client;
2 2
3 import cn.hutool.core.util.StrUtil; 3 import cn.hutool.core.util.StrUtil;
4 import cn.iocoder.yudao.framework.file.core.client.FileClient; 4 import cn.iocoder.yudao.framework.file.core.client.FileClient;
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/FileClientFactory.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.file.core.client;
  2 +
  3 +public interface FileClientFactory {
  4 +
  5 + /**
  6 + * 获得文件客户端
  7 + *
  8 + * @param channelId 渠道编号
  9 + * @return 文件客户端
  10 + */
  11 + FileClient getFileClient(Long channelId);
  12 +
  13 + /**
  14 + * 创建文件客户端
  15 + *
  16 + * @param configId 配置编号
  17 + * @param storage 存储器的枚举 {@link cn.iocoder.yudao.framework.file.core.enums.FileStorageEnum}
  18 + * @param config 文件配置
  19 + */
  20 + <Config extends FileClientConfig> void createOrUpdateFileClient(Long configId, Integer storage, Config config);
  21 +
  22 +}
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/FileClientFactoryImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.file.core.client;
  2 +
  3 +import cn.hutool.core.lang.Assert;
  4 +import cn.hutool.core.util.ReflectUtil;
  5 +import cn.iocoder.yudao.framework.file.core.enums.FileStorageEnum;
  6 +import lombok.extern.slf4j.Slf4j;
  7 +
  8 +import java.util.concurrent.ConcurrentHashMap;
  9 +import java.util.concurrent.ConcurrentMap;
  10 +
  11 +/**
  12 + * 文件客户端的工厂实现类
  13 + *
  14 + * @author 芋道源码
  15 + */
  16 +@Slf4j
  17 +public class FileClientFactoryImpl implements FileClientFactory {
  18 +
  19 + /**
  20 + * 文件客户端 Map
  21 + * key:配置编号
  22 + */
  23 + private final ConcurrentMap<Long, AbstractFileClient<?>> clients = new ConcurrentHashMap<>();
  24 +
  25 + @Override
  26 + public FileClient getFileClient(Long channelId) {
  27 + AbstractFileClient<?> client = clients.get(channelId);
  28 + if (client == null) {
  29 + log.error("[getFileClient][配置编号({}) 找不到客户端]", channelId);
  30 + }
  31 + return client;
  32 + }
  33 +
  34 + @Override
  35 + @SuppressWarnings("unchecked")
  36 + public <Config extends FileClientConfig> void createOrUpdateFileClient(Long configId, Integer storage, Config config) {
  37 + AbstractFileClient<Config> client = (AbstractFileClient<Config>) clients.get(configId);
  38 + if (client == null) {
  39 + client = this.createFileClient(configId, storage, config);
  40 + client.init();
  41 + clients.put(client.getId(), client);
  42 + } else {
  43 + client.refresh(config);
  44 + }
  45 + }
  46 +
  47 + @SuppressWarnings("unchecked")
  48 + private <Config extends FileClientConfig> AbstractFileClient<Config> createFileClient(
  49 + Long configId, Integer storage, Config config) {
  50 + FileStorageEnum storageEnum = FileStorageEnum.getByStorage(storage);
  51 + Assert.notNull(storageEnum, String.format("文件配置(%s) 为空", storageEnum));
  52 + // 创建客户端
  53 +// switch (storageEnum) {
  54 +// case WX_PUB: return (AbstractFileClient<Config>) new WXPubFileClient(channelId, (WXFileClientConfig) config);
  55 +// case WX_LITE: return (AbstractFileClient<Config>) new WXPubFileClient(channelId, (WXFileClientConfig) config);
  56 +// case WX_APP: return (AbstractFileClient<Config>) new WXPubFileClient(channelId, (WXFileClientConfig) config);
  57 +// case ALIPAY_WAP: return (AbstractFileClient<Config>) new AlipayWapFileClient(channelId, (AlipayFileClientConfig) config);
  58 +// case ALIPAY_QR: return (AbstractFileClient<Config>) new AlipayQrFileClient(channelId, (AlipayFileClientConfig) config);
  59 +// case ALIPAY_APP: return (AbstractFileClient<Config>) new AlipayQrFileClient(channelId, (AlipayFileClientConfig) config);
  60 +// case ALIPAY_PC: return (AbstractFileClient<Config>) new AlipayQrFileClient(channelId, (AlipayFileClientConfig) config);
  61 +// }
  62 + return (AbstractFileClient<Config>) ReflectUtil.newInstance(storageEnum.getClientClass(), configId, config);
  63 +// storageEnum.getClientClass().newInstance()
  64 +// // 创建失败,错误日志 + 抛出异常
  65 +// log.error("[createSmsClient][配置({}) 找不到合适的客户端实现]", config);
  66 +// throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", config));
  67 + }
  68 +
  69 +}
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileClient.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.file.core.client.db;
  2 +
  3 +import cn.hutool.extra.spring.SpringUtil;
  4 +import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient;
  5 +
  6 +/**
  7 + * 基于 DB 存储的文件客户端的配置类
  8 + *
  9 + * @author 芋道源码
  10 + */
  11 +public class DBFileClient extends AbstractFileClient<DBFileClientConfig> {
  12 +
  13 + private DBFileContentFrameworkDAO dao;
  14 +
  15 + public DBFileClient(Long id, DBFileClientConfig config) {
  16 + super(id, config);
  17 + }
  18 +
  19 + @Override
  20 + protected void doInit() {
  21 + dao = SpringUtil.getBean(DBFileContentFrameworkDAO.class);
  22 + }
  23 +
  24 + @Override
  25 + public String upload(byte[] content, String path) {
  26 + dao.insert(getId(), path, content);
  27 + // 拼接返回路径
  28 + return super.formatFileUrl(config.getDomain(), path);
  29 + }
  30 +
  31 + @Override
  32 + public void delete(String path) {
  33 + dao.delete(getId(), path);
  34 + }
  35 +
  36 + @Override
  37 + public byte[] getContent(String path) {
  38 + return dao.selectContent(getId(), path);
  39 + }
  40 +
  41 +}
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileClientConfig.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.file.core.client.db;
  2 +
  3 +import cn.iocoder.yudao.framework.file.core.client.FileClientConfig;
  4 +import lombok.Data;
  5 +import org.hibernate.validator.constraints.URL;
  6 +
  7 +import javax.validation.constraints.NotEmpty;
  8 +
  9 +/**
  10 + * 基于 DB 存储的文件客户端的配置类
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +@Data
  15 +public class DBFileClientConfig implements FileClientConfig {
  16 +
  17 + /**
  18 + * 自定义域名
  19 + */
  20 + @NotEmpty(message = "domain 不能为空")
  21 + @URL(message = "domain 必须是 URL 格式")
  22 + private String domain;
  23 +
  24 +}
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileContentFrameworkDAO.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.file.core.client.db;
  2 +
  3 +/**
  4 + * 文件内容 Framework DAO 接口
  5 + *
  6 + * @author 芋道源码
  7 + */
  8 +public interface DBFileContentFrameworkDAO {
  9 +
  10 + void insert(Long configId, String path, byte[] content);
  11 +
  12 + void delete(Long configId, String path);
  13 +
  14 + byte[] selectContent(Long configId, String path);
  15 +
  16 +}
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/ftp/FtpFileClient.java renamed to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClient.java
1 -package cn.iocoder.yudao.framework.file.core.client.impl.ftp; 1 +package cn.iocoder.yudao.framework.file.core.client.ftp;
2 2
3 import cn.hutool.core.io.FileUtil; 3 import cn.hutool.core.io.FileUtil;
4 import cn.hutool.core.util.CharsetUtil; 4 import cn.hutool.core.util.CharsetUtil;
@@ -6,7 +6,7 @@ import cn.hutool.core.util.StrUtil; @@ -6,7 +6,7 @@ import cn.hutool.core.util.StrUtil;
6 import cn.hutool.extra.ftp.Ftp; 6 import cn.hutool.extra.ftp.Ftp;
7 import cn.hutool.extra.ftp.FtpException; 7 import cn.hutool.extra.ftp.FtpException;
8 import cn.hutool.extra.ftp.FtpMode; 8 import cn.hutool.extra.ftp.FtpMode;
9 -import cn.iocoder.yudao.framework.file.core.client.impl.AbstractFileClient; 9 +import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient;
10 10
11 import java.io.ByteArrayInputStream; 11 import java.io.ByteArrayInputStream;
12 import java.io.ByteArrayOutputStream; 12 import java.io.ByteArrayOutputStream;
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/ftp/FtpFileClientConfig.java renamed to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClientConfig.java
1 -package cn.iocoder.yudao.framework.file.core.client.impl.ftp; 1 +package cn.iocoder.yudao.framework.file.core.client.ftp;
2 2
3 import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; 3 import cn.iocoder.yudao.framework.file.core.client.FileClientConfig;
4 import lombok.Data; 4 import lombok.Data;
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/local/LocalFileClient.java renamed to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClient.java
1 -package cn.iocoder.yudao.framework.file.core.client.impl.local; 1 +package cn.iocoder.yudao.framework.file.core.client.local;
2 2
3 import cn.hutool.core.io.FileUtil; 3 import cn.hutool.core.io.FileUtil;
4 -import cn.iocoder.yudao.framework.file.core.client.impl.AbstractFileClient; 4 +import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient;
5 5
6 import java.io.File; 6 import java.io.File;
7 7
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/local/LocalFileClientConfig.java renamed to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClientConfig.java
1 -package cn.iocoder.yudao.framework.file.core.client.impl.local; 1 +package cn.iocoder.yudao.framework.file.core.client.local;
2 2
3 import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; 3 import cn.iocoder.yudao.framework.file.core.client.FileClientConfig;
4 import lombok.Data; 4 import lombok.Data;
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/s3/S3FileClient.java renamed to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClient.java
1 -package cn.iocoder.yudao.framework.file.core.client.impl.s3; 1 +package cn.iocoder.yudao.framework.file.core.client.s3;
2 2
3 import cn.hutool.core.util.StrUtil; 3 import cn.hutool.core.util.StrUtil;
4 -import cn.iocoder.yudao.framework.file.core.client.impl.AbstractFileClient; 4 +import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient;
5 import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; 5 import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
6 import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; 6 import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
7 import software.amazon.awssdk.core.sync.RequestBody; 7 import software.amazon.awssdk.core.sync.RequestBody;
@@ -13,7 +13,7 @@ import software.amazon.awssdk.services.s3.model.PutObjectRequest; @@ -13,7 +13,7 @@ import software.amazon.awssdk.services.s3.model.PutObjectRequest;
13 13
14 import java.net.URI; 14 import java.net.URI;
15 15
16 -import static cn.iocoder.yudao.framework.file.core.client.impl.s3.S3FileClientConfig.ENDPOINT_QINIU; 16 +import static cn.iocoder.yudao.framework.file.core.client.s3.S3FileClientConfig.ENDPOINT_QINIU;
17 17
18 /** 18 /**
19 * 基于 S3 协议的文件客户端,实现 MinIO、阿里云、腾讯云、七牛云、华为云等云服务 19 * 基于 S3 协议的文件客户端,实现 MinIO、阿里云、腾讯云、七牛云、华为云等云服务
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/s3/S3FileClientConfig.java renamed to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientConfig.java
1 -package cn.iocoder.yudao.framework.file.core.client.impl.s3; 1 +package cn.iocoder.yudao.framework.file.core.client.s3;
2 2
3 import cn.hutool.core.util.StrUtil; 3 import cn.hutool.core.util.StrUtil;
4 import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; 4 import cn.iocoder.yudao.framework.file.core.client.FileClientConfig;
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/s3/S3ModifyPathInterceptor.java renamed to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3ModifyPathInterceptor.java
1 -package cn.iocoder.yudao.framework.file.core.client.impl.s3; 1 +package cn.iocoder.yudao.framework.file.core.client.s3;
2 2
3 import software.amazon.awssdk.core.interceptor.Context; 3 import software.amazon.awssdk.core.interceptor.Context;
4 import software.amazon.awssdk.core.interceptor.ExecutionAttributes; 4 import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/sftp/SftpFileClient.java renamed to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClient.java
1 -package cn.iocoder.yudao.framework.file.core.client.impl.sftp; 1 +package cn.iocoder.yudao.framework.file.core.client.sftp;
2 2
3 import cn.hutool.core.io.FileUtil; 3 import cn.hutool.core.io.FileUtil;
4 import cn.hutool.extra.ssh.Sftp; 4 import cn.hutool.extra.ssh.Sftp;
5 import cn.iocoder.yudao.framework.common.util.io.FileUtils; 5 import cn.iocoder.yudao.framework.common.util.io.FileUtils;
6 -import cn.iocoder.yudao.framework.file.core.client.impl.AbstractFileClient; 6 +import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient;
7 7
8 import java.io.File; 8 import java.io.File;
9 9
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/sftp/SftpFileClientConfig.java renamed to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClientConfig.java
1 -package cn.iocoder.yudao.framework.file.core.client.impl.sftp; 1 +package cn.iocoder.yudao.framework.file.core.client.sftp;
2 2
3 import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; 3 import cn.iocoder.yudao.framework.file.core.client.FileClientConfig;
4 import lombok.Data; 4 import lombok.Data;
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/enums/FileStorageEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.file.core.enums;
  2 +
  3 +import cn.hutool.core.util.ArrayUtil;
  4 +import cn.iocoder.yudao.framework.file.core.client.FileClient;
  5 +import cn.iocoder.yudao.framework.file.core.client.FileClientConfig;
  6 +import cn.iocoder.yudao.framework.file.core.client.db.DBFileClient;
  7 +import cn.iocoder.yudao.framework.file.core.client.db.DBFileClientConfig;
  8 +import cn.iocoder.yudao.framework.file.core.client.ftp.FtpFileClient;
  9 +import cn.iocoder.yudao.framework.file.core.client.ftp.FtpFileClientConfig;
  10 +import cn.iocoder.yudao.framework.file.core.client.local.LocalFileClient;
  11 +import cn.iocoder.yudao.framework.file.core.client.local.LocalFileClientConfig;
  12 +import cn.iocoder.yudao.framework.file.core.client.s3.S3FileClient;
  13 +import cn.iocoder.yudao.framework.file.core.client.s3.S3FileClientConfig;
  14 +import cn.iocoder.yudao.framework.file.core.client.sftp.SftpFileClient;
  15 +import cn.iocoder.yudao.framework.file.core.client.sftp.SftpFileClientConfig;
  16 +import lombok.AllArgsConstructor;
  17 +import lombok.Getter;
  18 +
  19 +/**
  20 + * 文件存储器枚举
  21 + *
  22 + * @author 芋道源码
  23 + */
  24 +@AllArgsConstructor
  25 +@Getter
  26 +public enum FileStorageEnum {
  27 +
  28 + DB(1, DBFileClientConfig.class, DBFileClient.class),
  29 +
  30 + LOCAL(10, LocalFileClientConfig.class, LocalFileClient.class),
  31 + FTP(11, FtpFileClientConfig.class, FtpFileClient.class),
  32 + SFTP(12, SftpFileClientConfig.class, SftpFileClient.class),
  33 +
  34 + S3(20, S3FileClientConfig.class, S3FileClient.class),
  35 + ;
  36 +
  37 + /**
  38 + * 存储器
  39 + */
  40 + private final Integer storage;
  41 +
  42 + /**
  43 + * 配置类
  44 + */
  45 + private final Class<? extends FileClientConfig> configClass;
  46 + /**
  47 + * 客户端类
  48 + */
  49 + private final Class<? extends FileClient> clientClass;
  50 +
  51 + public static FileStorageEnum getByStorage(Integer storage) {
  52 + return ArrayUtil.firstMatch(o -> o.getStorage().equals(storage), values());
  53 + }
  54 +
  55 +}
yudao-framework/yudao-spring-boot-starter-file/src/main/resources/META-INF/spring.factories 0 → 100644
  1 +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
  2 + cn.iocoder.yudao.framework.file.config.YudaoFileAutoConfiguration
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClientTest.java
@@ -3,8 +3,6 @@ package cn.iocoder.yudao.framework.file.core.client.ftp; @@ -3,8 +3,6 @@ package cn.iocoder.yudao.framework.file.core.client.ftp;
3 import cn.hutool.core.io.resource.ResourceUtil; 3 import cn.hutool.core.io.resource.ResourceUtil;
4 import cn.hutool.core.util.IdUtil; 4 import cn.hutool.core.util.IdUtil;
5 import cn.hutool.extra.ftp.FtpMode; 5 import cn.hutool.extra.ftp.FtpMode;
6 -import cn.iocoder.yudao.framework.file.core.client.impl.ftp.FtpFileClient;  
7 -import cn.iocoder.yudao.framework.file.core.client.impl.ftp.FtpFileClientConfig;  
8 import org.junit.jupiter.api.Test; 6 import org.junit.jupiter.api.Test;
9 7
10 public class FtpFileClientTest { 8 public class FtpFileClientTest {
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClientTest.java
@@ -2,8 +2,6 @@ package cn.iocoder.yudao.framework.file.core.client.local; @@ -2,8 +2,6 @@ package cn.iocoder.yudao.framework.file.core.client.local;
2 2
3 import cn.hutool.core.io.resource.ResourceUtil; 3 import cn.hutool.core.io.resource.ResourceUtil;
4 import cn.hutool.core.util.IdUtil; 4 import cn.hutool.core.util.IdUtil;
5 -import cn.iocoder.yudao.framework.file.core.client.impl.local.LocalFileClient;  
6 -import cn.iocoder.yudao.framework.file.core.client.impl.local.LocalFileClientConfig;  
7 import org.junit.jupiter.api.Test; 5 import org.junit.jupiter.api.Test;
8 6
9 public class LocalFileClientTest { 7 public class LocalFileClientTest {
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/package-info.java deleted
1 -/**  
2 - * 占位,避免 package 无法提交到 Git 仓库  
3 - */  
4 -package cn.iocoder.yudao.framework.file.core.client;  
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientTest.java
@@ -4,8 +4,6 @@ import cn.hutool.core.io.resource.ResourceUtil; @@ -4,8 +4,6 @@ import cn.hutool.core.io.resource.ResourceUtil;
4 import cn.hutool.core.util.IdUtil; 4 import cn.hutool.core.util.IdUtil;
5 import cn.hutool.core.util.StrUtil; 5 import cn.hutool.core.util.StrUtil;
6 import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; 6 import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
7 -import cn.iocoder.yudao.framework.file.core.client.impl.s3.S3FileClient;  
8 -import cn.iocoder.yudao.framework.file.core.client.impl.s3.S3FileClientConfig;  
9 import org.junit.jupiter.api.Disabled; 7 import org.junit.jupiter.api.Disabled;
10 import org.junit.jupiter.api.Test; 8 import org.junit.jupiter.api.Test;
11 9
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClientTest.java
@@ -2,8 +2,6 @@ package cn.iocoder.yudao.framework.file.core.client.sftp; @@ -2,8 +2,6 @@ package cn.iocoder.yudao.framework.file.core.client.sftp;
2 2
3 import cn.hutool.core.io.resource.ResourceUtil; 3 import cn.hutool.core.io.resource.ResourceUtil;
4 import cn.hutool.core.util.IdUtil; 4 import cn.hutool.core.util.IdUtil;
5 -import cn.iocoder.yudao.framework.file.core.client.impl.sftp.SftpFileClient;  
6 -import cn.iocoder.yudao.framework.file.core.client.impl.sftp.SftpFileClientConfig;  
7 import org.junit.jupiter.api.Test; 5 import org.junit.jupiter.api.Test;
8 6
9 public class SftpFileClientTest { 7 public class SftpFileClientTest {