| | |
| | | |
| | | 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; |
| | |
| | | |
| | | @Resource |
| | | private ReportExportService reportService; |
| | | @Resource |
| | | private ReportExportTaskService exportTaskService; |
| | | @Resource |
| | | private OperationLogService operationLogService; |
| | | |
| | |
| | | @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 + 巡游出租月报) */ |
| | |
| | | .body(data); |
| | | } |
| | | } |
| | | |