| | |
| | | package com.trafficaudit.reportexport.controller; |
| | | |
| | | import com.trafficaudit.common.Result; |
| | | import com.trafficaudit.reportexport.calc.FreightReadinessCheck; |
| | | import com.trafficaudit.reportexport.calc.SummaryMissingDataCheck; |
| | | 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; |
| | |
| | | |
| | | @Resource |
| | | private ReportExportService reportService; |
| | | @Resource |
| | | private FreightReadinessCheck freightReadinessCheck; |
| | | @Resource |
| | | private SummaryMissingDataCheck missingDataCheck; |
| | | @Resource |
| | | private ReportExportTaskService exportTaskService; |
| | | @Resource |
| | | private OperationLogService operationLogService; |
| | | |
| | |
| | | } |
| | | |
| | | /** 生成_道路运输量汇总表.xlsx(汇总工作簿 P0-P1 骨架:整本复制母版,页签/公式/2025 缓存保留) */ |
| | | /** 货运口径导出前体检(B4):只读返回命中的问题清单。 */ |
| | | @GetMapping("/summaryWorkbook/freightCheck") |
| | | public Result<java.util.List<String>> freightCheck(@RequestParam("period") String period) { |
| | | return Result.ok(freightReadinessCheck.check(period)); |
| | | } |
| | | |
| | | /** 汇总大表缺数清单(只读):列出目标期出表会缺的月份/市州/来源(与 freightCheck 互补)。 */ |
| | | @GetMapping("/summaryWorkbook/missing") |
| | | public Result<java.util.List<String>> missingCheck(@RequestParam("period") String period) { |
| | | return Result.ok(missingDataCheck.check(period)); |
| | | } |
| | | |
| | | /** 汇总大表按月扩列(Step 1,只做版式、数据留空):返回下一月版式 xlsx。 */ |
| | | @GetMapping("/export/summaryWorkbook/expand") |
| | | public ResponseEntity<byte[]> expandSummaryWorkbook(@RequestParam("period") String period, |
| | | @RequestParam(value = "titlesOnly", defaultValue = "false") boolean titlesOnly) throws Exception { |
| | | if (titlesOnly) { |
| | | byte[] titled = reportService.fixSummaryTitles(period); |
| | | return buildResponse(titled, String.format("标题修正_道路运输量汇总表_%s.xlsx", period)); |
| | | } |
| | | byte[] data = reportService.expandSummaryWorkbook(period); |
| | | return buildResponse(data, String.format("扩列_道路运输量汇总表_%s_待确认.xlsx", period)); |
| | | } |
| | | |
| | | @GetMapping("/export/summaryWorkbook") |
| | | public ResponseEntity<byte[]> exportSummaryWorkbook(@RequestParam("period") String period, |
| | | @RequestParam(value = "mode", defaultValue = "month") String mode, |
| | | @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 秒,走异步可避免点击后长时间无响应;同报表期结果直接复用(落盘保存、进程重启后仍有效;期间有导入则自动失效), |
| | | * 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 + 巡游出租月报) */ |
| | |
| | | .body(data); |
| | | } |
| | | } |
| | | |