| | |
| | | import com.ltkj.common.utils.SecurityUtils; |
| | | import com.ltkj.hosp.domain.TjReport; |
| | | import com.ltkj.hosp.domain.TjReservation; |
| | | import com.ltkj.system.service.ISysConfigService; |
| | | import com.ltkj.web.config.pdfutils.PDFBinaryUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | public class TjReportTemplateController extends BaseController { |
| | | @Autowired |
| | | private ITjReportTemplateService tjReportTemplateService; |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | | |
| | | @Value("${path.filePath}") |
| | | private String value; |
| | | // @Value("${path.filePath}") |
| | | // private String value; |
| | | |
| | | /** |
| | | * 查询template列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('hosp:template:list')") |
| | | //@PreAuthorize("@ss.hasPermi('hosp:template:list')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(TjReportTemplate tjReportTemplate) { |
| | | startPage(); |
| | |
| | | /** |
| | | * 获取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)); |
| | |
| | | if (one == null) { |
| | | return; |
| | | } |
| | | String value = configService.selectConfigByKey("path_filePath"); |
| | | 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("文件不存在!"); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @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 value = configService.selectConfigByKey("path_filePath"); |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | } |