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;
@@ -93,6 +97,47 @@
        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 + 巡游出租月报) */
    @GetMapping("/export/wycSplit")
    public ResponseEntity<byte[]> exportWycSplit(@RequestParam("period") String period,
@@ -153,6 +198,22 @@
                                                      @RequestParam(value = "mode", defaultValue = "month") String mode) throws Exception {
        logExport("生成_经济强县交通物流基础设施投资统计报表.xls", period);
        return buildResponse(reportService.investCounty(period, mode), "生成_经济强县交通物流基础设施投资统计报表.xls");
    }
    /** 生成_X月客运站投资明细表.xlsx(投资模块明细表1:客运站场) */
    @GetMapping("/export/investPassengerDetail")
    public ResponseEntity<byte[]> exportInvestPassengerDetail(@RequestParam("period") String period,
                                                              @RequestParam(value = "mode", defaultValue = "month") String mode) throws Exception {
        logExport("生成_X月客运站投资明细表.xlsx", period);
        return buildResponse(reportService.exportInvestPassengerDetail(period, mode), "生成_客运站投资明细表.xlsx");
    }
    /** 生成_X月物流站场投资明细.xls(投资模块明细表2:物流园区) */
    @GetMapping("/export/investLogisticsDetail")
    public ResponseEntity<byte[]> exportInvestLogisticsDetail(@RequestParam("period") String period,
                                                              @RequestParam(value = "mode", defaultValue = "month") String mode) throws Exception {
        logExport("生成_X月物流站场投资明细.xls", period);
        return buildResponse(reportService.exportInvestLogisticsDetail(period, mode), "生成_物流站场投资明细.xls");
    }
    /** 生成_轨道轮渡客运量分市州明细.xlsx(城市客运,轨道/轮渡取自公交源文件) */
@@ -292,4 +353,3 @@
            .body(data);
    }
}