From 35d098a89613c96179391178b7f8143dec393ada Mon Sep 17 00:00:00 2001
From: zhizhijie <zhizhijie@users.noreply.gitee.com>
Date: 星期日, 20 九月 2026 15:52:36 +0800
Subject: [PATCH] feat(报表): 汇总大表导出异步化 + 结果缓存 + 进度弹窗

---
 traffic-audit-server/src/main/java/com/trafficaudit/reportexport/controller/ReportExportController.java |   46 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 45 insertions(+), 1 deletions(-)

diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/controller/ReportExportController.java b/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/controller/ReportExportController.java
index b955d53..f4e8e8a 100644
--- a/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/controller/ReportExportController.java
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/controller/ReportExportController.java
@@ -2,12 +2,14 @@
 
 import com.trafficaudit.common.Result;
 import com.trafficaudit.reportexport.service.ReportExportService;
+import com.trafficaudit.reportexport.service.ReportExportTaskService;
 import com.trafficaudit.system.service.OperationLogService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
@@ -24,6 +26,8 @@
 
     @Resource
     private ReportExportService reportService;
+    @Resource
+    private ReportExportTaskService exportTaskService;
     @Resource
     private OperationLogService operationLogService;
 
@@ -91,6 +95,47 @@
                                                         @RequestParam(value = "toMonth", required = false) Integer toMonth) throws Exception {
         logExport("閬撹矾杩愯緭閲忔眹鎬昏〃.xlsx", period);
         return buildResponse(reportService.exportSummaryWorkbook(period, mode, toMonth), String.format("鐢熸垚_閬撹矾杩愯緭閲忔眹鎬昏〃_%s.xlsx", period));
+    }
+
+    /**
+     * 姹囨�诲ぇ琛ㄥ紓姝ュ鍑猴細绔嬪嵆杩斿洖浠诲姟鍙凤紝鍓嶇杞杩涘害銆佸畬鎴愬悗鍐嶄笅杞芥枃浠躲��
+     * 鐢熸垚涓�娆$害 10~20 绉掞紝璧板紓姝ュ彲閬垮厤鐐瑰嚮鍚庨暱鏃堕棿鏃犲搷搴旓紱鍚屾姤琛ㄦ湡 10 鍒嗛挓鍐呯殑缁撴灉鐩存帴澶嶇敤锛堟湡闂存湁瀵煎叆鍒欒嚜鍔ㄥけ鏁堬級锛�
+     * refresh=true 鍙己鍒堕噸鏂扮敓鎴愩��
+     */
+    @GetMapping("/exportTask/summaryWorkbook")
+    public Result<java.util.Map<String, Object>> submitSummaryWorkbookTask(@RequestParam("period") String period,
+                                                                          @RequestParam(value = "mode", defaultValue = "month") String mode,
+                                                                          @RequestParam(value = "toMonth", required = false) Integer toMonth,
+                                                                          @RequestParam(value = "refresh", defaultValue = "false") boolean refresh) {
+        ReportExportTaskService.Task task = exportTaskService.submit(
+                ReportExportTaskService.TYPE_SUMMARY_WORKBOOK, period, mode, toMonth, refresh);
+        if (!task.isFromCache()) {
+            logExport("閬撹矾杩愯緭閲忔眹鎬昏〃.xlsx", period);
+        }
+        return Result.ok(task.toView());
+    }
+
+    /** 鏌ヨ寮傛瀵煎嚭浠诲姟杩涘害锛堢粨鏋滀繚鐣� 30 鍒嗛挓锛� */
+    @GetMapping("/exportTask/{taskId}")
+    public Result<java.util.Map<String, Object>> exportTaskStatus(@PathVariable("taskId") String taskId) {
+        ReportExportTaskService.Task task = exportTaskService.get(taskId);
+        if (task == null) {
+            return Result.error("瀵煎嚭浠诲姟涓嶅瓨鍦ㄦ垨宸茶繃鏈燂紙鐢熸垚缁撴灉淇濈暀 30 鍒嗛挓锛�");
+        }
+        return Result.ok(task.toView());
+    }
+
+    /** 涓嬭浇寮傛瀵煎嚭浠诲姟宸茬敓鎴愮殑鏂囦欢 */
+    @GetMapping("/exportTask/{taskId}/file")
+    public ResponseEntity<byte[]> exportTaskFile(@PathVariable("taskId") String taskId) throws Exception {
+        ReportExportTaskService.Task task = exportTaskService.get(taskId);
+        if (task == null) {
+            throw new RuntimeException("瀵煎嚭浠诲姟涓嶅瓨鍦ㄦ垨宸茶繃鏈燂紙鐢熸垚缁撴灉淇濈暀 30 鍒嗛挓锛�");
+        }
+        if (!task.isDone()) {
+            throw new RuntimeException("瀵煎嚭浠诲姟灏氭湭瀹屾垚锛堝綋鍓嶇姸鎬侊細" + task.getStatus() + "锛夛紝璇风◢鍚庡啀璇�");
+        }
+        return buildResponse(task.getData(), task.getFileName());
     }
 
     /** 鐢熸垚_缃戠害杞﹀杩愰噺鎷嗗垎琛�.xlsx锛堟湀搴︼細璁㈠崟闄勪欢1 + 鍏ㄧ渷 pin + 宸℃父鍑虹鏈堟姤锛� */
@@ -308,4 +353,3 @@
             .body(data);
     }
 }
-

--
Gitblit v1.9.1