Эх сурвалжийг харах

新增framework-download模块,替换framework-export模块;

woody 11 сар өмнө
parent
commit
fe10de6f36
16 өөрчлөгдсөн 314 нэмэгдсэн , 208 устгасан
  1. 1 1
      framework-common/src/main/java/com/chelvc/framework/common/crypto/AESCipherFactory.java
  2. 21 0
      framework-common/src/main/java/com/chelvc/framework/common/function/InputAcceptor.java
  3. 23 0
      framework-common/src/main/java/com/chelvc/framework/common/function/InputAdapter.java
  4. 21 0
      framework-common/src/main/java/com/chelvc/framework/common/function/OutputAcceptor.java
  5. 23 0
      framework-common/src/main/java/com/chelvc/framework/common/function/OutputAdapter.java
  6. 9 3
      framework-common/src/main/java/com/chelvc/framework/common/util/AESUtils.java
  7. 2 1
      framework-common/src/main/java/com/chelvc/framework/common/util/ExcelUtils.java
  8. 0 11
      framework-common/src/main/java/com/chelvc/framework/common/util/FileUtils.java
  9. 1 1
      framework-download/pom.xml
  10. 8 8
      framework-download/src/main/java/com/chelvc/framework/download/Download.java
  11. 124 0
      framework-download/src/main/java/com/chelvc/framework/download/DownloadHandler.java
  12. 8 10
      framework-download/src/main/java/com/chelvc/framework/download/config/DownloadConfigurer.java
  13. 5 5
      framework-download/src/main/java/com/chelvc/framework/download/config/DownloadProperties.java
  14. 67 53
      framework-download/src/main/java/com/chelvc/framework/download/support/DefaultDownloadHandler.java
  15. 0 114
      framework-export/src/main/java/com/chelvc/framework/export/ExportHandler.java
  16. 1 1
      pom.xml

+ 1 - 1
framework-common/src/main/java/com/chelvc/framework/common/crypto/AESCipherFactory.java

@@ -27,7 +27,7 @@ public class AESCipherFactory implements CipherFactory {
     }
 
     public AESCipherFactory(@NonNull String name, @NonNull String secret, @NonNull String iv) {
-        this.key = name + secret;
+        this.key = name + secret + iv;
         this.name = name;
         this.secret = secret;
         this.iv = iv;

+ 21 - 0
framework-common/src/main/java/com/chelvc/framework/common/function/InputAcceptor.java

@@ -0,0 +1,21 @@
+package com.chelvc.framework.common.function;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * 输入流接收函数
+ *
+ * @author Woody
+ * @date 2024/6/26
+ */
+@FunctionalInterface
+public interface InputAcceptor {
+    /**
+     * 接收输入流
+     *
+     * @param input 输入流实例
+     * @throws IOException I/O异常
+     */
+    void accept(InputStream input) throws IOException;
+}

+ 23 - 0
framework-common/src/main/java/com/chelvc/framework/common/function/InputAdapter.java

@@ -0,0 +1,23 @@
+package com.chelvc.framework.common.function;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * 输入流适配函数
+ *
+ * @param <T> 适配目标类型
+ * @author Woody
+ * @date 2024/6/26
+ */
+@FunctionalInterface
+public interface InputAdapter<T> {
+    /**
+     * 适配输入流
+     *
+     * @param input 输入流实例
+     * @return 适配结果
+     * @throws IOException I/O异常
+     */
+    T apply(InputStream input) throws IOException;
+}

+ 21 - 0
framework-common/src/main/java/com/chelvc/framework/common/function/OutputAcceptor.java

@@ -0,0 +1,21 @@
+package com.chelvc.framework.common.function;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * 输出流接收函数
+ *
+ * @author Woody
+ * @date 2024/6/26
+ */
+@FunctionalInterface
+public interface OutputAcceptor {
+    /**
+     * 接收输出流
+     *
+     * @param output 输出流实例
+     * @throws IOException I/O异常
+     */
+    void accept(OutputStream output) throws IOException;
+}

+ 23 - 0
framework-common/src/main/java/com/chelvc/framework/common/function/OutputAdapter.java

@@ -0,0 +1,23 @@
+package com.chelvc.framework.common.function;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * 输出流适配函数
+ *
+ * @param <T> 适配目标类型
+ * @author Woody
+ * @date 2024/6/26
+ */
+@FunctionalInterface
+public interface OutputAdapter<T> {
+    /**
+     * 适配输出流
+     *
+     * @param output 输出流实例
+     * @return 适配结果
+     * @throws IOException I/O异常
+     */
+    T apply(OutputStream output) throws IOException;
+}

+ 9 - 3
framework-common/src/main/java/com/chelvc/framework/common/util/AESUtils.java

@@ -213,9 +213,15 @@ public final class AESUtils {
      * @return 处理器实例
      */
     public static Cipher lookupCipher(@NonNull String key, int mode, @NonNull Supplier<Cipher> supplier) {
-        Map<String, Pool<Cipher>> cache = mode == Cipher.ENCRYPT_MODE ? ENCRYPTOR_CACHE : DECRYPTER_CACHE;
-        Pool<Cipher> pool = cache.computeIfAbsent(key, k -> new Pool<>(supplier));
-        return pool.get();
+        Map<String, Pool<Cipher>> cache;
+        if (mode == Cipher.ENCRYPT_MODE) {
+            cache = ENCRYPTOR_CACHE;
+        } else if (mode == Cipher.DECRYPT_MODE) {
+            cache = DECRYPTER_CACHE;
+        } else {
+            throw new IllegalArgumentException("Not support cipher mode: " + mode);
+        }
+        return cache.computeIfAbsent(key, k -> new Pool<>(supplier)).get();
     }
 
     /**

+ 2 - 1
framework-common/src/main/java/com/chelvc/framework/common/util/ExcelUtils.java

@@ -1,6 +1,7 @@
 package com.chelvc.framework.common.util;
 
 import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -270,7 +271,7 @@ public final class ExcelUtils {
      */
     public static int read(@NonNull InputStream input, int index, @NonNull Reader reader) throws IOException {
         // 标记输入流开始位置
-        if (!(input instanceof BufferedInputStream)) {
+        if (!(input instanceof BufferedInputStream || input instanceof ByteArrayInputStream)) {
             input = new BufferedInputStream(input);
         }
         input.mark(0);

+ 0 - 11
framework-common/src/main/java/com/chelvc/framework/common/util/FileUtils.java

@@ -33,11 +33,6 @@ public final class FileUtils {
      */
     public static final String TEMPORARY = System.getProperty("java.io.tmpdir");
 
-    /**
-     * 文件导出目录
-     */
-    public static final String EXPORT = new File(TEMPORARY, "export").getPath();
-
     /**
      * 文件上传目录
      */
@@ -49,12 +44,6 @@ public final class FileUtils {
     public static final String DOWNLOAD = new File(TEMPORARY, "download").getPath();
 
     static {
-        // 初始化文件导出目录
-        File export = new File(EXPORT);
-        if (!export.exists() && !export.mkdirs()) {
-            log.warn("Make export dir failed: {}", EXPORT);
-        }
-
         // 初始化文件上传目录
         File upload = new File(UPLOAD);
         if (!upload.exists() && !upload.mkdirs()) {

+ 1 - 1
framework-export/pom.xml → framework-download/pom.xml

@@ -11,7 +11,7 @@
         <relativePath/>
     </parent>
 
-    <artifactId>framework-export</artifactId>
+    <artifactId>framework-download</artifactId>
     <version>1.0.0-RELEASE</version>
 
     <properties>

+ 8 - 8
framework-export/src/main/java/com/chelvc/framework/export/Exporting.java → framework-download/src/main/java/com/chelvc/framework/download/Download.java

@@ -1,4 +1,4 @@
-package com.chelvc.framework.export;
+package com.chelvc.framework.download;
 
 import java.io.Serializable;
 
@@ -10,7 +10,7 @@ import lombok.NoArgsConstructor;
 import lombok.experimental.SuperBuilder;
 
 /**
- * 数据导出对象
+ * 数据下载对象模型
  *
  * @author Woody
  * @date 2024/5/11
@@ -19,19 +19,19 @@ import lombok.experimental.SuperBuilder;
 @SuperBuilder
 @NoArgsConstructor
 @AllArgsConstructor
-public class Exporting implements Serializable {
+public class Download implements Serializable {
     /**
-     * 文件名称
+     * 数据处理状态
      */
-    private String filename;
+    private Status status;
 
     /**
-     * 导出状态
+     * 下载文件名称
      */
-    private Status status;
+    private String filename;
 
     /**
-     * 导出状态枚举
+     * 数据处理状态枚举
      */
     @Getter
     public enum Status implements Enumerable {

+ 124 - 0
framework-download/src/main/java/com/chelvc/framework/download/DownloadHandler.java

@@ -0,0 +1,124 @@
+package com.chelvc.framework.download;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
+import javax.servlet.http.HttpServletResponse;
+
+import com.chelvc.framework.common.function.Adapter;
+import com.chelvc.framework.common.function.OutputAcceptor;
+import com.chelvc.framework.common.util.ExcelUtils;
+import org.apache.poi.ss.usermodel.Workbook;
+
+/**
+ * 数据下载处理器接口
+ *
+ * @author Woody
+ * @date 2024/6/26
+ */
+public interface DownloadHandler {
+    /**
+     * 初始化处理器
+     */
+    default void initialize() {
+    }
+
+    /**
+     * 获取下载任务状态
+     *
+     * @param id 下载任务ID
+     * @return 下载任务状态
+     */
+    Download.Status status(long id);
+
+    /**
+     * 写入Excel下载数据
+     *
+     * @param id       下载任务ID
+     * @param workbook Excel工作薄
+     * @throws IOException I/O异常
+     */
+    void write(long id, Workbook workbook) throws IOException;
+
+    /**
+     * 写入下载数据
+     *
+     * @param id       下载任务ID
+     * @param acceptor 输出流回调函数
+     * @throws IOException I/O异常
+     */
+    void write(long id, OutputAcceptor acceptor) throws IOException;
+
+    /**
+     * 下载数据
+     *
+     * @param id       下载任务ID
+     * @param response Http响应对象
+     * @throws IOException I/O操作异常
+     */
+    void download(long id, HttpServletResponse response) throws IOException;
+
+    /**
+     * 异步下载数据
+     *
+     * @param filename 文件名称
+     * @param adapter  数据处理回调函数
+     * @return 下载任务ID
+     */
+    default long async(String filename, Adapter<Long, Integer> adapter) {
+        return this.async(filename, adapter, (id, volume) -> {
+        });
+    }
+
+    /**
+     * 异步下载数据
+     *
+     * @param filename 文件名称
+     * @param adapter  数据处理回调函数
+     * @param listener 处理完成监听器
+     * @return 下载任务ID
+     */
+    long async(String filename, Adapter<Long, Integer> adapter, BiConsumer<Long, Integer> listener);
+
+    /**
+     * 异步下载数据
+     *
+     * @param filename 文件名称
+     * @param provider 数据生产者
+     * @param writer   Excel对象实例写入接口
+     * @param titles   表头数组
+     * @param <T>      数据类型
+     * @return 下载任务ID
+     */
+    default <T> long async(String filename, BiFunction<Integer, Integer, Collection<T>> provider,
+                           ExcelUtils.Writer<T> writer, String... titles) {
+        return this.async(
+                filename,
+                (id, volume) -> {
+                },
+                provider, writer, titles
+        );
+    }
+
+    /**
+     * 异步下载数据
+     *
+     * @param filename 文件名称
+     * @param listener 处理完成监听器
+     * @param provider 数据生产者
+     * @param writer   Excel对象实例写入接口
+     * @param titles   表头数组
+     * @param <T>      数据类型
+     * @return 下载任务ID
+     */
+    <T> long async(String filename, BiConsumer<Long, Integer> listener,
+                   BiFunction<Integer, Integer, Collection<T>> provider, ExcelUtils.Writer<T> writer,
+                   String... titles);
+
+    /**
+     * 销毁处理器
+     */
+    default void destroy() {
+    }
+}

+ 8 - 10
framework-export/src/main/java/com/chelvc/framework/export/config/ExportConfigurer.java → framework-download/src/main/java/com/chelvc/framework/download/config/DownloadConfigurer.java

@@ -1,29 +1,27 @@
-package com.chelvc.framework.export.config;
+package com.chelvc.framework.download.config;
 
-import com.chelvc.framework.export.ExportHandler;
-import com.chelvc.framework.export.support.DefaultExportHandler;
+import com.chelvc.framework.download.DownloadHandler;
+import com.chelvc.framework.download.support.DefaultDownloadHandler;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.data.redis.core.RedisTemplate;
 
 /**
- * 数据导出配置
+ * 文件下载配置
  *
  * @author Woody
  * @date 2024/5/10
  */
 @Configuration
 @RequiredArgsConstructor(onConstructor = @__(@Autowired))
-public class ExportConfigurer {
-    private final ExportProperties properties;
+public class DownloadConfigurer {
+    private final DownloadProperties properties;
     private final RedisTemplate<String, Object> redisTemplate;
 
-    @ConditionalOnMissingBean(ExportHandler.class)
     @Bean(initMethod = "initialize", destroyMethod = "destroy")
-    public ExportHandler exportHandler() {
-        return new DefaultExportHandler(this.redisTemplate, this.properties);
+    public DownloadHandler downloadHandler() {
+        return new DefaultDownloadHandler(this.properties, this.redisTemplate);
     }
 }

+ 5 - 5
framework-export/src/main/java/com/chelvc/framework/export/config/ExportProperties.java → framework-download/src/main/java/com/chelvc/framework/download/config/DownloadProperties.java

@@ -1,4 +1,4 @@
-package com.chelvc.framework.export.config;
+package com.chelvc.framework.download.config;
 
 import com.chelvc.framework.common.util.FileUtils;
 import lombok.Data;
@@ -6,19 +6,19 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
 
 /**
- * 数据导出配置
+ * 文件下载配置属性
  *
  * @author Woody
  * @date 2024/5/9
  */
 @Data
 @Configuration
-@ConfigurationProperties("export")
-public class ExportProperties {
+@ConfigurationProperties("download")
+public class DownloadProperties {
     /**
      * 文件存储目录
      */
-    private String directory = FileUtils.EXPORT;
+    private String directory = FileUtils.DOWNLOAD;
 
     /**
      * 文件过期时间(秒)

+ 67 - 53
framework-export/src/main/java/com/chelvc/framework/export/support/DefaultExportHandler.java → framework-download/src/main/java/com/chelvc/framework/download/support/DefaultDownloadHandler.java

@@ -1,7 +1,9 @@
-package com.chelvc.framework.export.support;
+package com.chelvc.framework.download.support;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.io.Serializable;
 import java.time.Duration;
 import java.util.Collection;
@@ -17,14 +19,15 @@ import com.chelvc.framework.base.context.ThreadContextHolder;
 import com.chelvc.framework.base.util.HttpUtils;
 import com.chelvc.framework.common.function.Adapter;
 import com.chelvc.framework.common.function.Executor;
+import com.chelvc.framework.common.function.OutputAcceptor;
 import com.chelvc.framework.common.util.AssertUtils;
 import com.chelvc.framework.common.util.ExcelUtils;
 import com.chelvc.framework.common.util.FileUtils;
 import com.chelvc.framework.common.util.ObjectUtils;
 import com.chelvc.framework.common.util.ThreadUtils;
-import com.chelvc.framework.export.ExportHandler;
-import com.chelvc.framework.export.Exporting;
-import com.chelvc.framework.export.config.ExportProperties;
+import com.chelvc.framework.download.Download;
+import com.chelvc.framework.download.DownloadHandler;
+import com.chelvc.framework.download.config.DownloadProperties;
 import com.chelvc.framework.redis.context.RedisContextHolder;
 import com.google.common.collect.Lists;
 import lombok.NonNull;
@@ -36,26 +39,26 @@ import org.springframework.context.ApplicationListener;
 import org.springframework.data.redis.core.RedisTemplate;
 
 /**
- * 数据导出默认实现
+ * 数据下载处理器默认实现
  *
  * @author Woody
  * @date 2024/5/9
  */
 @Slf4j
-public class DefaultExportHandler implements ExportHandler, ApplicationListener<ApplicationStartedEvent> {
+public class DefaultDownloadHandler implements DownloadHandler, ApplicationListener<ApplicationStartedEvent> {
     private final String directory;
     private final Duration duration;
     private final RedisTemplate<String, Object> redisTemplate;
 
-    public DefaultExportHandler(@NonNull RedisTemplate<String, Object> redisTemplate,
-                                @NonNull ExportProperties properties) {
+    public DefaultDownloadHandler(@NonNull DownloadProperties properties,
+                                  @NonNull RedisTemplate<String, Object> redisTemplate) {
         this.directory = properties.getDirectory();
         this.duration = Duration.ofSeconds(properties.getExpiration());
         this.redisTemplate = redisTemplate;
     }
 
     /**
-     * 清理导出文件
+     * 清理下载文件
      */
     private void clear() {
         int batch = 100;
@@ -73,7 +76,7 @@ public class DefaultExportHandler implements ExportHandler, ApplicationListener<
     }
 
     /**
-     * 清理导出文件
+     * 清理下载文件
      *
      * @param files 文件列表
      */
@@ -96,41 +99,41 @@ public class DefaultExportHandler implements ExportHandler, ApplicationListener<
      * @return 任务标识
      */
     private String key(Serializable id) {
-        return "exporting:" + id;
+        return "download:" + id;
     }
 
     /**
-     * 获取导出任务信息
+     * 获取下载任务信息
      *
-     * @param id 导出任务ID
-     * @return 导出任务信息
+     * @param id 下载任务ID
+     * @return 下载任务信息
      */
-    private Exporting exporting(Serializable id) {
-        return (Exporting) this.redisTemplate.opsForValue().get(this.key(id));
+    private Download download(Serializable id) {
+        return (Download) this.redisTemplate.opsForValue().get(this.key(id));
     }
 
     /**
-     * 设置导出任务信息
+     * 处理下载任务信息
      *
-     * @param id       导出任务ID
+     * @param id       任务ID
      * @param filename 文件名称
-     * @param status   导出状态
+     * @param status   任务状态
      * @param duration 任务有效期
      */
-    private void exporting(Serializable id, String filename, Exporting.Status status, Duration duration) {
-        Exporting exporting = Exporting.builder().filename(filename).status(status).build();
-        this.redisTemplate.opsForValue().set(this.key(id), exporting, duration);
+    private void processing(Serializable id, String filename, Download.Status status, Duration duration) {
+        Download download = Download.builder().filename(filename).status(status).build();
+        this.redisTemplate.opsForValue().set(this.key(id), download, duration);
     }
 
     @Override
     public void onApplicationEvent(ApplicationStartedEvent event) {
-        // 初始化导出文件清理线程
+        // 初始化下载文件清理线程
         ThreadUtils.run(() -> {
             while (!Thread.currentThread().isInterrupted()) {
                 try {
-                    RedisContextHolder.tryLockAround("exporting:clear:lock", (Executor) this::clear);
+                    RedisContextHolder.tryLockAround("download:clear:lock", (Executor) this::clear);
                 } catch (Exception e) {
-                    log.error("Export file clear failed", e);
+                    log.error("Download temp file clear failed", e);
                 }
                 ThreadUtils.sleep(this.duration.toMillis());
             }
@@ -138,69 +141,80 @@ public class DefaultExportHandler implements ExportHandler, ApplicationListener<
     }
 
     @Override
-    public Exporting.Status status(long id) {
-        return ObjectUtils.ifNull(this.exporting(id), Exporting::getStatus);
+    public Download.Status status(long id) {
+        return ObjectUtils.ifNull(this.download(id), Download::getStatus);
     }
 
     @Override
-    public void save(long id, @NonNull Workbook workbook) throws IOException {
-        ExcelUtils.save(workbook, new File(this.directory, String.valueOf(id)));
+    public void write(long id, @NonNull Workbook workbook) throws IOException {
+        this.write(id, output -> {
+            workbook.write(output);
+            workbook.close();
+        });
+    }
+
+    @Override
+    public void write(long id, @NonNull OutputAcceptor acceptor) throws IOException {
+        File file = new File(this.directory, String.valueOf(id));
+        try (OutputStream output = new FileOutputStream(file)) {
+            acceptor.accept(output);
+        }
     }
 
     @Override
     public void download(long id, @NonNull HttpServletResponse response) throws IOException {
-        Exporting exporting = this.exporting(id);
-        AssertUtils.available(exporting, () -> ApplicationContextHolder.getMessage("Export.Expired"));
-        boolean completed = ObjectUtils.ifNull(exporting, Exporting::getStatus) == Exporting.Status.COMPLETED;
-        AssertUtils.available(completed, () -> ApplicationContextHolder.getMessage("Export.Uncompleted"));
-        String filename = ObjectUtils.ifNull(exporting, Exporting::getFilename);
+        Download download = this.download(id);
+        AssertUtils.available(download, () -> ApplicationContextHolder.getMessage("Download.Expired"));
+        boolean completed = ObjectUtils.ifNull(download, Download::getStatus) == Download.Status.COMPLETED;
+        AssertUtils.available(completed, () -> ApplicationContextHolder.getMessage("Download.Uncompleted"));
+        String filename = ObjectUtils.ifNull(download, Download::getFilename);
         HttpUtils.write(response, new File(this.directory, String.valueOf(id)), filename);
     }
 
     @Override
-    public long export(@NonNull String filename, @NonNull Adapter<Long, Integer> adapter,
-                       @NonNull BiConsumer<Long, Integer> listener) {
-        // 生成导出任务ID
+    public long async(@NonNull String filename, @NonNull Adapter<Long, Integer> adapter,
+                      @NonNull BiConsumer<Long, Integer> listener) {
+        // 生成任务ID
         long id = RedisContextHolder.identity();
 
-        // 初始化数据导出状态
-        this.exporting(id, filename, Exporting.Status.RUNNING, Duration.ofDays(1));
+        // 初始化任务状态
+        this.processing(id, filename, Download.Status.RUNNING, Duration.ofDays(1));
 
-        // 异步执行导出任务
+        // 异步执行任务处理
         ThreadContextHolder.run(() -> {
             int volume;
             try {
-                // 导出任务处理回调
+                // 任务处理回调
                 volume = adapter.apply(id);
 
-                // 更新导出任务完成状态
-                this.exporting(id, filename, Exporting.Status.COMPLETED, this.duration);
+                // 更新任务完成状态
+                this.processing(id, filename, Download.Status.COMPLETED, this.duration);
             } catch (Exception e) {
-                log.error("Export execute failed", e);
+                log.error("Download execute failed", e);
 
-                // 更新导出任务失败状态
-                this.exporting(id, filename, Exporting.Status.FAILED, this.duration);
+                // 更新任务失败状态
+                this.processing(id, filename, Download.Status.FAILED, this.duration);
                 return;
             }
 
-            // 数据导出完成监听回调
+            // 任务完成监听回调
             try {
                 listener.accept(id, volume);
             } catch (Exception e) {
-                log.error("Export listening failed", e);
+                log.error("Download listening failed", e);
             }
         });
         return id;
     }
 
     @Override
-    public <T> long export(@NonNull String filename, @NonNull BiConsumer<Long, Integer> listener,
-                           @NonNull BiFunction<Integer, Integer, Collection<T>> provider,
-                           @NonNull ExcelUtils.Writer<T> writer, @NonNull String... titles) {
-        return this.export(filename, id -> {
+    public <T> long async(@NonNull String filename, @NonNull BiConsumer<Long, Integer> listener,
+                          @NonNull BiFunction<Integer, Integer, Collection<T>> provider,
+                          @NonNull ExcelUtils.Writer<T> writer, @NonNull String... titles) {
+        return this.async(filename, id -> {
             Workbook workbook = new SXSSFWorkbook();
             int volume = ExcelUtils.write(workbook, provider, writer, titles);
-            this.save(id, workbook);
+            this.write(id, workbook);
             return volume;
         }, listener);
     }

+ 0 - 114
framework-export/src/main/java/com/chelvc/framework/export/ExportHandler.java

@@ -1,114 +0,0 @@
-package com.chelvc.framework.export;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
-import javax.servlet.http.HttpServletResponse;
-
-import com.chelvc.framework.common.function.Adapter;
-import com.chelvc.framework.common.util.ExcelUtils;
-import org.apache.poi.ss.usermodel.Workbook;
-
-/**
- * 数据导出操作接口
- *
- * @author Woody
- * @date 2024/5/9
- */
-public interface ExportHandler {
-    /**
-     * 初始化处理器
-     */
-    default void initialize() {
-    }
-
-    /**
-     * 获取导出任务状态
-     *
-     * @param id 导出任务ID
-     * @return 导出任务状态
-     */
-    Exporting.Status status(long id);
-
-    /**
-     * 保存工作薄到文件
-     *
-     * @param id       导出任务ID
-     * @param workbook 工作薄
-     * @throws IOException I/O异常
-     */
-    void save(long id, Workbook workbook) throws IOException;
-
-    /**
-     * 下载数据导出文件
-     *
-     * @param id       导出任务ID
-     * @param response Http响应对象
-     * @throws IOException I/O操作异常
-     */
-    void download(long id, HttpServletResponse response) throws IOException;
-
-    /**
-     * 异步导出数据
-     *
-     * @param filename 文件名称
-     * @param adapter  数据处理回调函数
-     * @return 导出任务ID
-     */
-    default long export(String filename, Adapter<Long, Integer> adapter) {
-        return this.export(filename, adapter, (id, volume) -> {
-        });
-    }
-
-    /**
-     * 异步导出数据
-     *
-     * @param filename 文件名称
-     * @param adapter  数据处理回调函数
-     * @param listener 导出完成监听器
-     * @return 导出任务ID
-     */
-    long export(String filename, Adapter<Long, Integer> adapter, BiConsumer<Long, Integer> listener);
-
-    /**
-     * 异步导出数据
-     *
-     * @param filename 文件名称
-     * @param provider 数据生产者
-     * @param writer   Excel对象实例写入接口
-     * @param titles   表头数组
-     * @param <T>      数据类型
-     * @return 导出任务ID
-     */
-    default <T> long export(String filename, BiFunction<Integer, Integer, Collection<T>> provider,
-                            ExcelUtils.Writer<T> writer, String... titles) {
-        return this.export(
-                filename,
-                (id, volume) -> {
-                },
-                provider, writer, titles
-        );
-    }
-
-    /**
-     * 异步导出数据
-     *
-     * @param filename 文件名称
-     * @param listener 导出完成监听器
-     * @param provider 数据生产者
-     * @param writer   Excel对象实例写入接口
-     * @param titles   表头数组
-     * @param <T>      数据类型
-     * @return 导出任务ID
-     */
-    <T> long export(String filename, BiConsumer<Long, Integer> listener,
-                    BiFunction<Integer, Integer, Collection<T>> provider, ExcelUtils.Writer<T> writer,
-                    String... titles);
-
-    /**
-     * 销毁处理器
-     */
-    default void destroy() {
-    }
-}

+ 1 - 1
pom.xml

@@ -28,7 +28,7 @@
         <module>framework-sms</module>
         <module>framework-upload</module>
         <module>framework-wechat</module>
-        <module>framework-export</module>
+        <module>framework-download</module>
         <module>framework-dependencies</module>
         <module>framework-cloud</module>
         <module>framework-cloud-nacos</module>