From 05d4aae65d624ba08935792f64f33468f199b77f Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 14 Mar 2022 23:07:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20yudao-spring-boot-starter-?= =?UTF-8?q?file=20=E7=BB=84=E4=BB=B6=EF=BC=8C=E6=94=AF=E6=8C=81=20S3=20?= =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E4=BA=91=E5=AD=98=E5=82=A8=E3=80=81local?= =?UTF-8?q?=E3=80=81ftp=E3=80=81sftp=E3=80=81db=20=E7=AD=89=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pay/config/YudaoPayAutoConfiguration.java | 1 + .../client/impl/PayClientFactoryImpl.java | 10 +-- .../pay/core/enums/PayChannelEnum.java | 1 - .../config/YudaoFileAutoConfiguration.java | 21 ++++++ .../client/{impl => }/AbstractFileClient.java | 2 +- .../file/core/client/FileClientFactory.java | 22 ++++++ .../core/client/FileClientFactoryImpl.java | 69 +++++++++++++++++++ .../file/core/client/db/DBFileClient.java | 41 +++++++++++ .../core/client/db/DBFileClientConfig.java | 24 +++++++ .../client/db/DBFileContentFrameworkDAO.java | 16 +++++ .../client/{impl => }/ftp/FtpFileClient.java | 4 +- .../{impl => }/ftp/FtpFileClientConfig.java | 2 +- .../{impl => }/local/LocalFileClient.java | 4 +- .../local/LocalFileClientConfig.java | 2 +- .../client/{impl => }/s3/S3FileClient.java | 6 +- .../{impl => }/s3/S3FileClientConfig.java | 2 +- .../s3/S3ModifyPathInterceptor.java | 2 +- .../{impl => }/sftp/SftpFileClient.java | 4 +- .../{impl => }/sftp/SftpFileClientConfig.java | 2 +- .../file/core/enums/FileStorageEnum.java | 55 +++++++++++++++ .../main/resources/META-INF/spring.factories | 2 + .../core/client/ftp/FtpFileClientTest.java | 2 - .../client/local/LocalFileClientTest.java | 2 - .../file/core/client/package-info.java | 4 -- .../file/core/client/s3/S3FileClientTest.java | 2 - .../core/client/sftp/SftpFileClientTest.java | 2 - 26 files changed, 271 insertions(+), 33 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/config/YudaoFileAutoConfiguration.java rename yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/{impl => }/AbstractFileClient.java (96%) create mode 100644 yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/FileClientFactory.java create mode 100644 yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/FileClientFactoryImpl.java create mode 100644 yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileClient.java create mode 100644 yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileClientConfig.java create mode 100644 yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileContentFrameworkDAO.java rename yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/{impl => }/ftp/FtpFileClient.java (94%) rename yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/{impl => }/ftp/FtpFileClientConfig.java (95%) rename yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/{impl => }/local/LocalFileClient.java (89%) rename yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/{impl => }/local/LocalFileClientConfig.java (90%) rename yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/{impl => }/s3/S3FileClient.java (93%) rename yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/{impl => }/s3/S3FileClientConfig.java (97%) rename yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/{impl => }/s3/S3ModifyPathInterceptor.java (95%) rename yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/{impl => }/sftp/SftpFileClient.java (92%) rename yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/{impl => }/sftp/SftpFileClientConfig.java (94%) create mode 100644 yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/enums/FileStorageEnum.java create mode 100644 yudao-framework/yudao-spring-boot-starter-file/src/main/resources/META-INF/spring.factories delete mode 100644 yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/package-info.java diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/config/YudaoPayAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/config/YudaoPayAutoConfiguration.java index d49c1c2b2..c4d41b6f5 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/config/YudaoPayAutoConfiguration.java +++ b/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; * * @author 芋道源码 */ +@Configuration @EnableConfigurationProperties(PayProperties.class) public class YudaoPayAutoConfiguration { diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java index edfd44952..647152196 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java +++ b/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 { * 支付客户端 Map * key:渠道编号 */ - private final ConcurrentMap> channelIdClients = new ConcurrentHashMap<>(); + private final ConcurrentMap> clients = new ConcurrentHashMap<>(); @Override public PayClient getPayClient(Long channelId) { - AbstractPayClient client = channelIdClients.get(channelId); + AbstractPayClient client = clients.get(channelId); if (client == null) { log.error("[getPayClient][渠道编号({}) 找不到客户端]", channelId); } @@ -42,11 +42,11 @@ public class PayClientFactoryImpl implements PayClientFactory { @SuppressWarnings("unchecked") public void createOrUpdatePayClient(Long channelId, String channelCode, Config config) { - AbstractPayClient client = (AbstractPayClient) channelIdClients.get(channelId); + AbstractPayClient client = (AbstractPayClient) clients.get(channelId); if (client == null) { client = this.createPayClient(channelId, channelCode, config); client.init(); - channelIdClients.put(client.getId(), client); + clients.put(client.getId(), client); } else { client.refresh(config); } @@ -69,7 +69,7 @@ public class PayClientFactoryImpl implements PayClientFactory { case ALIPAY_PC: return (AbstractPayClient) new AlipayQrPayClient(channelId, (AlipayPayClientConfig) config); } // 创建失败,错误日志 + 抛出异常 - log.error("[createSmsClient][配置({}) 找不到合适的客户端实现]", config); + log.error("[createPayClient][配置({}) 找不到合适的客户端实现]", config); throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", config)); } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java index f8a4971a1..fccbab84b 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java +++ b/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 { return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values()); } - } diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/config/YudaoFileAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/config/YudaoFileAutoConfiguration.java new file mode 100644 index 000000000..5f7bd91fe --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/config/YudaoFileAutoConfiguration.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.framework.file.config; + +import cn.iocoder.yudao.framework.file.core.client.FileClientFactory; +import cn.iocoder.yudao.framework.file.core.client.FileClientFactoryImpl; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * 文件配置类 + * + * @author 芋道源码 + */ +@Configuration +public class YudaoFileAutoConfiguration { + + @Bean + public FileClientFactory fileClientFactory() { + return new FileClientFactoryImpl(); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/AbstractFileClient.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/AbstractFileClient.java similarity index 96% rename from yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/AbstractFileClient.java rename to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/AbstractFileClient.java index 4aef2f387..262ceab20 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/AbstractFileClient.java +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/AbstractFileClient.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.framework.file.core.client.impl; +package cn.iocoder.yudao.framework.file.core.client; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.file.core.client.FileClient; diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/FileClientFactory.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/FileClientFactory.java new file mode 100644 index 000000000..85b21766f --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/FileClientFactory.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.framework.file.core.client; + +public interface FileClientFactory { + + /** + * 获得文件客户端 + * + * @param channelId 渠道编号 + * @return 文件客户端 + */ + FileClient getFileClient(Long channelId); + + /** + * 创建文件客户端 + * + * @param configId 配置编号 + * @param storage 存储器的枚举 {@link cn.iocoder.yudao.framework.file.core.enums.FileStorageEnum} + * @param config 文件配置 + */ + void createOrUpdateFileClient(Long configId, Integer storage, Config config); + +} diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/FileClientFactoryImpl.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/FileClientFactoryImpl.java new file mode 100644 index 000000000..8573cf10a --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/FileClientFactoryImpl.java @@ -0,0 +1,69 @@ +package cn.iocoder.yudao.framework.file.core.client; + +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.ReflectUtil; +import cn.iocoder.yudao.framework.file.core.enums.FileStorageEnum; +import lombok.extern.slf4j.Slf4j; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +/** + * 文件客户端的工厂实现类 + * + * @author 芋道源码 + */ +@Slf4j +public class FileClientFactoryImpl implements FileClientFactory { + + /** + * 文件客户端 Map + * key:配置编号 + */ + private final ConcurrentMap> clients = new ConcurrentHashMap<>(); + + @Override + public FileClient getFileClient(Long channelId) { + AbstractFileClient client = clients.get(channelId); + if (client == null) { + log.error("[getFileClient][配置编号({}) 找不到客户端]", channelId); + } + return client; + } + + @Override + @SuppressWarnings("unchecked") + public void createOrUpdateFileClient(Long configId, Integer storage, Config config) { + AbstractFileClient client = (AbstractFileClient) clients.get(configId); + if (client == null) { + client = this.createFileClient(configId, storage, config); + client.init(); + clients.put(client.getId(), client); + } else { + client.refresh(config); + } + } + + @SuppressWarnings("unchecked") + private AbstractFileClient createFileClient( + Long configId, Integer storage, Config config) { + FileStorageEnum storageEnum = FileStorageEnum.getByStorage(storage); + Assert.notNull(storageEnum, String.format("文件配置(%s) 为空", storageEnum)); + // 创建客户端 +// switch (storageEnum) { +// case WX_PUB: return (AbstractFileClient) new WXPubFileClient(channelId, (WXFileClientConfig) config); +// case WX_LITE: return (AbstractFileClient) new WXPubFileClient(channelId, (WXFileClientConfig) config); +// case WX_APP: return (AbstractFileClient) new WXPubFileClient(channelId, (WXFileClientConfig) config); +// case ALIPAY_WAP: return (AbstractFileClient) new AlipayWapFileClient(channelId, (AlipayFileClientConfig) config); +// case ALIPAY_QR: return (AbstractFileClient) new AlipayQrFileClient(channelId, (AlipayFileClientConfig) config); +// case ALIPAY_APP: return (AbstractFileClient) new AlipayQrFileClient(channelId, (AlipayFileClientConfig) config); +// case ALIPAY_PC: return (AbstractFileClient) new AlipayQrFileClient(channelId, (AlipayFileClientConfig) config); +// } + return (AbstractFileClient) ReflectUtil.newInstance(storageEnum.getClientClass(), configId, config); +// storageEnum.getClientClass().newInstance() +// // 创建失败,错误日志 + 抛出异常 +// log.error("[createSmsClient][配置({}) 找不到合适的客户端实现]", config); +// throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", config)); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileClient.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileClient.java new file mode 100644 index 000000000..57c649a88 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileClient.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.framework.file.core.client.db; + +import cn.hutool.extra.spring.SpringUtil; +import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient; + +/** + * 基于 DB 存储的文件客户端的配置类 + * + * @author 芋道源码 + */ +public class DBFileClient extends AbstractFileClient { + + private DBFileContentFrameworkDAO dao; + + public DBFileClient(Long id, DBFileClientConfig config) { + super(id, config); + } + + @Override + protected void doInit() { + dao = SpringUtil.getBean(DBFileContentFrameworkDAO.class); + } + + @Override + public String upload(byte[] content, String path) { + dao.insert(getId(), path, content); + // 拼接返回路径 + return super.formatFileUrl(config.getDomain(), path); + } + + @Override + public void delete(String path) { + dao.delete(getId(), path); + } + + @Override + public byte[] getContent(String path) { + return dao.selectContent(getId(), path); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileClientConfig.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileClientConfig.java new file mode 100644 index 000000000..65d837b44 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileClientConfig.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.framework.file.core.client.db; + +import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; +import lombok.Data; +import org.hibernate.validator.constraints.URL; + +import javax.validation.constraints.NotEmpty; + +/** + * 基于 DB 存储的文件客户端的配置类 + * + * @author 芋道源码 + */ +@Data +public class DBFileClientConfig implements FileClientConfig { + + /** + * 自定义域名 + */ + @NotEmpty(message = "domain 不能为空") + @URL(message = "domain 必须是 URL 格式") + private String domain; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileContentFrameworkDAO.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileContentFrameworkDAO.java new file mode 100644 index 000000000..44850ed77 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileContentFrameworkDAO.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.framework.file.core.client.db; + +/** + * 文件内容 Framework DAO 接口 + * + * @author 芋道源码 + */ +public interface DBFileContentFrameworkDAO { + + void insert(Long configId, String path, byte[] content); + + void delete(Long configId, String path); + + byte[] selectContent(Long configId, String path); + +} diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/ftp/FtpFileClient.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClient.java similarity index 94% rename from yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/ftp/FtpFileClient.java rename to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClient.java index 556f4e28c..c02b469ff 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/ftp/FtpFileClient.java +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClient.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.framework.file.core.client.impl.ftp; +package cn.iocoder.yudao.framework.file.core.client.ftp; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.CharsetUtil; @@ -6,7 +6,7 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.extra.ftp.Ftp; import cn.hutool.extra.ftp.FtpException; import cn.hutool.extra.ftp.FtpMode; -import cn.iocoder.yudao.framework.file.core.client.impl.AbstractFileClient; +import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/ftp/FtpFileClientConfig.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClientConfig.java similarity index 95% rename from yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/ftp/FtpFileClientConfig.java rename to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClientConfig.java index bc0038219..5ccf86cd4 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/ftp/FtpFileClientConfig.java +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClientConfig.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.framework.file.core.client.impl.ftp; +package cn.iocoder.yudao.framework.file.core.client.ftp; import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; import lombok.Data; diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/local/LocalFileClient.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClient.java similarity index 89% rename from yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/local/LocalFileClient.java rename to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClient.java index aea6b1ee2..1c79f8999 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/local/LocalFileClient.java +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClient.java @@ -1,7 +1,7 @@ -package cn.iocoder.yudao.framework.file.core.client.impl.local; +package cn.iocoder.yudao.framework.file.core.client.local; import cn.hutool.core.io.FileUtil; -import cn.iocoder.yudao.framework.file.core.client.impl.AbstractFileClient; +import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient; import java.io.File; diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/local/LocalFileClientConfig.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClientConfig.java similarity index 90% rename from yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/local/LocalFileClientConfig.java rename to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClientConfig.java index 9820de7dd..1f595ed89 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/local/LocalFileClientConfig.java +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClientConfig.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.framework.file.core.client.impl.local; +package cn.iocoder.yudao.framework.file.core.client.local; import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; import lombok.Data; diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/s3/S3FileClient.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClient.java similarity index 93% rename from yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/s3/S3FileClient.java rename to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClient.java index 1f2b4aaae..4fcc674d5 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/s3/S3FileClient.java +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClient.java @@ -1,7 +1,7 @@ -package cn.iocoder.yudao.framework.file.core.client.impl.s3; +package cn.iocoder.yudao.framework.file.core.client.s3; import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.file.core.client.impl.AbstractFileClient; +import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; import software.amazon.awssdk.core.sync.RequestBody; @@ -13,7 +13,7 @@ import software.amazon.awssdk.services.s3.model.PutObjectRequest; import java.net.URI; -import static cn.iocoder.yudao.framework.file.core.client.impl.s3.S3FileClientConfig.ENDPOINT_QINIU; +import static cn.iocoder.yudao.framework.file.core.client.s3.S3FileClientConfig.ENDPOINT_QINIU; /** * 基于 S3 协议的文件客户端,实现 MinIO、阿里云、腾讯云、七牛云、华为云等云服务 diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/s3/S3FileClientConfig.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientConfig.java similarity index 97% rename from yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/s3/S3FileClientConfig.java rename to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientConfig.java index 858759c26..3cb702db1 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/s3/S3FileClientConfig.java +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientConfig.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.framework.file.core.client.impl.s3; +package cn.iocoder.yudao.framework.file.core.client.s3; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/s3/S3ModifyPathInterceptor.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3ModifyPathInterceptor.java similarity index 95% rename from yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/s3/S3ModifyPathInterceptor.java rename to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3ModifyPathInterceptor.java index 2f4f19f84..1b7550dd7 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/s3/S3ModifyPathInterceptor.java +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3ModifyPathInterceptor.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.framework.file.core.client.impl.s3; +package cn.iocoder.yudao.framework.file.core.client.s3; import software.amazon.awssdk.core.interceptor.Context; import software.amazon.awssdk.core.interceptor.ExecutionAttributes; diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/sftp/SftpFileClient.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClient.java similarity index 92% rename from yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/sftp/SftpFileClient.java rename to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClient.java index 704300264..3e18e888d 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/sftp/SftpFileClient.java +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClient.java @@ -1,9 +1,9 @@ -package cn.iocoder.yudao.framework.file.core.client.impl.sftp; +package cn.iocoder.yudao.framework.file.core.client.sftp; import cn.hutool.core.io.FileUtil; import cn.hutool.extra.ssh.Sftp; import cn.iocoder.yudao.framework.common.util.io.FileUtils; -import cn.iocoder.yudao.framework.file.core.client.impl.AbstractFileClient; +import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient; import java.io.File; diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/sftp/SftpFileClientConfig.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClientConfig.java similarity index 94% rename from yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/sftp/SftpFileClientConfig.java rename to yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClientConfig.java index 6941e1521..1a976f5d9 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/impl/sftp/SftpFileClientConfig.java +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClientConfig.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.framework.file.core.client.impl.sftp; +package cn.iocoder.yudao.framework.file.core.client.sftp; import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; import lombok.Data; diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/enums/FileStorageEnum.java b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/enums/FileStorageEnum.java new file mode 100644 index 000000000..03c6ed8a7 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/enums/FileStorageEnum.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.framework.file.core.enums; + +import cn.hutool.core.util.ArrayUtil; +import cn.iocoder.yudao.framework.file.core.client.FileClient; +import cn.iocoder.yudao.framework.file.core.client.FileClientConfig; +import cn.iocoder.yudao.framework.file.core.client.db.DBFileClient; +import cn.iocoder.yudao.framework.file.core.client.db.DBFileClientConfig; +import cn.iocoder.yudao.framework.file.core.client.ftp.FtpFileClient; +import cn.iocoder.yudao.framework.file.core.client.ftp.FtpFileClientConfig; +import cn.iocoder.yudao.framework.file.core.client.local.LocalFileClient; +import cn.iocoder.yudao.framework.file.core.client.local.LocalFileClientConfig; +import cn.iocoder.yudao.framework.file.core.client.s3.S3FileClient; +import cn.iocoder.yudao.framework.file.core.client.s3.S3FileClientConfig; +import cn.iocoder.yudao.framework.file.core.client.sftp.SftpFileClient; +import cn.iocoder.yudao.framework.file.core.client.sftp.SftpFileClientConfig; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 文件存储器枚举 + * + * @author 芋道源码 + */ +@AllArgsConstructor +@Getter +public enum FileStorageEnum { + + DB(1, DBFileClientConfig.class, DBFileClient.class), + + LOCAL(10, LocalFileClientConfig.class, LocalFileClient.class), + FTP(11, FtpFileClientConfig.class, FtpFileClient.class), + SFTP(12, SftpFileClientConfig.class, SftpFileClient.class), + + S3(20, S3FileClientConfig.class, S3FileClient.class), + ; + + /** + * 存储器 + */ + private final Integer storage; + + /** + * 配置类 + */ + private final Class configClass; + /** + * 客户端类 + */ + private final Class clientClass; + + public static FileStorageEnum getByStorage(Integer storage) { + return ArrayUtil.firstMatch(o -> o.getStorage().equals(storage), values()); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/main/resources/META-INF/spring.factories b/yudao-framework/yudao-spring-boot-starter-file/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..8d2a4be45 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-file/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + cn.iocoder.yudao.framework.file.config.YudaoFileAutoConfiguration diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClientTest.java b/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClientTest.java index 7c37c014d..ee0d74078 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClientTest.java +++ b/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; import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.extra.ftp.FtpMode; -import cn.iocoder.yudao.framework.file.core.client.impl.ftp.FtpFileClient; -import cn.iocoder.yudao.framework.file.core.client.impl.ftp.FtpFileClientConfig; import org.junit.jupiter.api.Test; public class FtpFileClientTest { diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClientTest.java b/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClientTest.java index 62e5ea249..60f781b01 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClientTest.java +++ b/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; import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.util.IdUtil; -import cn.iocoder.yudao.framework.file.core.client.impl.local.LocalFileClient; -import cn.iocoder.yudao.framework.file.core.client.impl.local.LocalFileClientConfig; import org.junit.jupiter.api.Test; public class LocalFileClientTest { diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/package-info.java b/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/package-info.java deleted file mode 100644 index b6c1cd4a9..000000000 --- a/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * 占位,避免 package 无法提交到 Git 仓库 - */ -package cn.iocoder.yudao.framework.file.core.client; diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientTest.java b/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientTest.java index 5d9224b74..145894a44 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientTest.java +++ b/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; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; -import cn.iocoder.yudao.framework.file.core.client.impl.s3.S3FileClient; -import cn.iocoder.yudao.framework.file.core.client.impl.s3.S3FileClientConfig; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; diff --git a/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClientTest.java b/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClientTest.java index 13e331047..cc8e59ede 100644 --- a/yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClientTest.java +++ b/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; import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.util.IdUtil; -import cn.iocoder.yudao.framework.file.core.client.impl.sftp.SftpFileClient; -import cn.iocoder.yudao.framework.file.core.client.impl.sftp.SftpFileClientConfig; import org.junit.jupiter.api.Test; public class SftpFileClientTest {