From 14a81d1080d1b8e0c922f372a3c4950c61a211d7 Mon Sep 17 00:00:00 2001 From: Timi Date: Mon, 26 Oct 2026 11:46:02 +0800 Subject: [PATCH] download from attachment api for data export --- .../controller/GaoDataExportController.java | 22 ------------------- .../gao/service/GaoDataExportService.java | 10 --------- .../GaoDataExportServiceImplement.java | 19 ---------------- 3 files changed, 51 deletions(-) diff --git a/src/main/java/com/imyeyu/api/modules/gao/controller/GaoDataExportController.java b/src/main/java/com/imyeyu/api/modules/gao/controller/GaoDataExportController.java index 63e2b51..a18815f 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/controller/GaoDataExportController.java +++ b/src/main/java/com/imyeyu/api/modules/gao/controller/GaoDataExportController.java @@ -7,12 +7,8 @@ import com.imyeyu.api.modules.gao.export.GaoDataExportStatRequest; import com.imyeyu.api.modules.gao.export.GaoDataExportStatView; import com.imyeyu.api.modules.gao.export.GaoDataExportTaskView; import com.imyeyu.api.modules.gao.service.GaoDataExportService; -import com.imyeyu.network.Network; -import com.imyeyu.spring.TimiSpring; import com.imyeyu.spring.annotation.AOPLog; -import com.imyeyu.spring.annotation.IgnoreGlobalReturn; import com.imyeyu.spring.annotation.RequestRateLimit; -import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -21,8 +17,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.io.IOException; - /// GAO 店长数据导出接口 /// /// @author Codex @@ -69,20 +63,4 @@ public class GaoDataExportController { public GaoDataExportTaskView detail(@PathVariable String taskId) { return service.detail(taskId); } - - /// 下载已完成的导出 ZIP - /// - /// @param taskId 任务 ID - /// @throws IOException 写入响应失败 - @AOPLog - @RequestRateLimit - @IgnoreGlobalReturn - @RequireGaoPermission(GaoPermissionCode.DATA_EXPORT) - @GetMapping("/task/{taskId}/download") - public void download(@PathVariable String taskId) throws IOException { - HttpServletResponse response = TimiSpring.getResponse(); - response.setContentType("application/zip"); - response.setHeader("Content-Disposition", Network.getFileDownloadHeader("GAO数据导出.zip")); - service.download(taskId, response.getOutputStream()); - } } diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/GaoDataExportService.java b/src/main/java/com/imyeyu/api/modules/gao/service/GaoDataExportService.java index 454a532..d4d7b71 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/service/GaoDataExportService.java +++ b/src/main/java/com/imyeyu/api/modules/gao/service/GaoDataExportService.java @@ -6,9 +6,6 @@ import com.imyeyu.api.modules.gao.export.GaoDataExportStatView; import com.imyeyu.api.modules.gao.export.GaoDataExportTaskView; import com.imyeyu.api.modules.gao.task.async.GaoDataExportAsyncTask; -import java.io.IOException; -import java.io.OutputStream; - /// /// GAO 数据导出服务 /// @@ -34,13 +31,6 @@ public interface GaoDataExportService { /// @return 任务视图 GaoDataExportTaskView detail(String taskId); - /// 下载已完成的导出文件 - /// - /// @param taskId 任务 ID - /// @param output 输出流 - /// @throws IOException 写入异常 - void download(String taskId, OutputStream output) throws IOException; - /// 执行异步导出任务 /// /// @param task 异步任务 diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoDataExportServiceImplement.java b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoDataExportServiceImplement.java index a88c5d1..190e8b2 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoDataExportServiceImplement.java +++ b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoDataExportServiceImplement.java @@ -129,25 +129,6 @@ public class GaoDataExportServiceImplement implements GaoDataExportService { return toTaskView(task, metadata, readResult(task)); } - @Override - public void download(String taskId, OutputStream output) throws IOException { - AsyncTask task = requireOwnedTask(taskId); - TimiException.requiredTrue(task.getStatus() == AsyncTask.Status.SUCCESS, "导出任务尚未完成"); - TimiException.requiredTrue(Time.now() < task.getExpiresAt(), "导出文件已过期"); - GaoDataExportResultView result = readResult(task); - TimiException.required(result, "未找到导出结果文件"); - Attachment attachment = attachmentService.get(result.getAttachmentId()); - TimiException.required(attachment, "导出结果文件已失效"); - TimiException.requiredTrue(Attachment.BizType.GAO_DATA_EXPORT == attachment.getBizType() && taskId.equals(attachment.getBizId()), "导出结果文件无权访问"); - try (InputStream input = new BufferedInputStream(attachmentService.getInputStreamByMongoId(attachment.getMongoId()))) { - byte[] buffer = new byte[32 * 1024]; - int length; - while ((length = input.read(buffer)) != -1) { - output.write(buffer, 0, length); - } - } - } - @Override public void execute(GaoDataExportAsyncTask task) throws Exception { AsyncTask record = asyncTaskService.getTaskRecord(task.getId());