zjh
2024-12-07 148a7f11b0ead8539cae824f02dda19a703f4d0b
ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjReportTemplateController.java
@@ -55,7 +55,7 @@
    /**
     * 查询template列表
     */
    @PreAuthorize("@ss.hasPermi('hosp:template:list')")
    //@PreAuthorize("@ss.hasPermi('hosp:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(TjReportTemplate tjReportTemplate) {
        startPage();
@@ -67,7 +67,7 @@
    /**
     * 获取template详细信息
     */
    @PreAuthorize("@ss.hasPermi('hosp:template:query')")
    //@PreAuthorize("@ss.hasPermi('hosp:template:query')")
    @GetMapping(value = "/{reportTemId}")
    public AjaxResult getInfo(@PathVariable("reportTemId") Long reportTemId) {
        return success(tjReportTemplateService.selectTjReportTemplateByReportTemId(reportTemId));
@@ -133,8 +133,8 @@
            return;
        }
        String userId = SecurityUtils.getLoginUser().getUsername();
        PDFBinaryUtil.base64StringToPDF(one.getTemplate(), FileUtil.mkdir(value).getPath() + "\\" + userId + reportTemId + "_模板预览.pdf");
        String filePath = value + "\\" + userId + reportTemId + "_模板预览.pdf";
        PDFBinaryUtil.base64StringToPDF(one.getTemplate(), FileUtil.mkdir(value).getPath() + File.separator + userId + reportTemId + "_模板预览.pdf");
        String filePath = value + File.separator + userId + reportTemId + "_模板预览.pdf";
        File f = new File(filePath);
        if (filePath.isEmpty()) {
            System.out.println("文件不存在!");
@@ -188,4 +188,76 @@
            }
        }
    }
    @GetMapping("/zhiYeTable/{flag}")
    @ApiOperation(value = "下载职业健康表")
    public void zhiYeTable(HttpServletResponse response, @PathVariable("flag") boolean flag) {
        LambdaQueryWrapper<TjReportTemplate> we = new LambdaQueryWrapper<>();
        we.eq(TjReportTemplate::getName, "职业健康体检个人信息表");
        TjReportTemplate one = tjReportTemplateService.getOne(we);
        if (one == null) {
            return;
        }
        String userId = SecurityUtils.getLoginUser().getUsername();
        PDFBinaryUtil.base64StringToPDF(one.getTemplate(), FileUtil.mkdir(value).getPath() + File.separator + userId + "_职业健康体检个人信息表.pdf");
        String filePath = value + File.separator + userId + "_职业健康体检个人信息表.pdf";
        File f = new File(filePath);
        if (filePath.isEmpty()) {
            System.out.println("文件不存在!");
            return;
        }
        BufferedInputStream br = null;
        OutputStream out = null;
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(f);
            br = new BufferedInputStream(fileInputStream);
            byte[] bs = new byte[1024];
            int len = 0;
            response.reset(); // 非常重要
            if (flag) {
                // 在线打开方式
                URL u = new URL("file:///" + filePath);
                //System.out.println(u);
                String contentType = u.openConnection().getContentType();
                response.setContentType(contentType);
                response.setHeader("Content-Disposition", "inline;filename="
                        + userId +"_职业健康体检个人信息表.pdf");
            } else {
                // 纯下载方式
                response.setContentType("application/x-msdownload");
                response.setContentType("application/pdf;charset=utf-8");
                response.setHeader("Content-Disposition", "attachment;filename="
                        + userId +"_职业健康体检个人信息表.pdf");
            }
            out = response.getOutputStream();
            while ((len = br.read(bs)) > 0) {
                out.write(bs, 0, len);
            }
            out.flush();
            out.close();
            br.close();
            fileInputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
            //System.out.println("pdf处理文件异常" + e);
        } finally {
            if (out != null) {
                try {
                    out.close();
                    br.close();
                    fileInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}