liujie
2026-01-21 2d368b1f587edfe4e1c87e9dc1d5345cd43b8841
admin-server/src/main/java/com/estate/expert/admin/controller/stat/ReportController.java
@@ -73,6 +73,24 @@
        }
    }
    @ApiOperation("模糊评价报告PDF下载")
    @GetMapping("/fuzzyReportPdf")
    @IgnoreAuth
    public void fuzzyReportPdf(@ApiParam("检查任务ID") @RequestParam(value = "checkTaskId") Integer checkTaskId,
                               @ApiParam("报告模版ID") @RequestParam(value = "templateId") Integer templateId,
                               HttpServletResponse response) throws IOException {
        downloadPdf(checkTaskId, templateId, response, "模糊评价", true);
    }
    @ApiOperation("打分评价报告PDF下载")
    @GetMapping("/scoreReportPdf")
    @IgnoreAuth
    public void scoreReportPdf(@ApiParam("检查任务ID") @RequestParam(value = "checkTaskId") Integer checkTaskId,
                               @ApiParam("报告模版ID") @RequestParam(value = "templateId") Integer templateId,
                               HttpServletResponse response) throws IOException {
        downloadPdf(checkTaskId, templateId, response, "打分评价", false);
    }
    private void download(XWPFTemplate doc, HttpServletResponse response, String typeName,
                          Integer checkTaskId, Integer templateId) throws IOException {
        OutputStream out;
@@ -95,4 +113,31 @@
        out.flush();
    }
    private void downloadPdf(Integer checkTaskId, Integer templateId, HttpServletResponse response,
                             String typeName, boolean isFuzzy) throws IOException {
        OutputStream out;
        BufferedOutputStream bos;
        var checkTask = checkTaskService.get(checkTaskId, true);
        var reportTemplate = reportTemplateService.get(templateId);
        BizResultCode.TASK_NOT_FOUND.check(checkTask == null);
        var docName = checkTask.getProject().getName() + "_" + reportTemplate.getName() + "_" + typeName;
        String encodedFileName = URLEncoder.encode(docName, "UTF-8");
        response.setContentType("application/pdf");
        response.setHeader("Content-disposition", "attachment;filename=\"" + encodedFileName + ".pdf\"");
        out = response.getOutputStream();
        bos = new BufferedOutputStream(out);
        if (isFuzzy) {
            reportService.fuzzyReportPdf(checkTaskId, templateId, bos);
        } else {
            reportService.scoreReportPdf(checkTaskId, templateId, bos);
        }
        bos.flush();
        out.flush();
    }
}