| | |
| | | package com.ltkj.hosp.service.impl; |
| | | |
| | | import java.io.File; |
| | | import java.io.OutputStream; |
| | | import java.io.*; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.io.FileUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.itextpdf.text.*; |
| | | import com.itextpdf.text.pdf.*; |
| | | import com.itextpdf.text.pdf.draw.LineSeparator; |
| | | import com.ltkj.common.core.domain.AjaxResult; |
| | | import com.ltkj.common.core.domain.entity.SysDictData; |
| | | import com.ltkj.common.utils.DateUtils; |
| | | import com.ltkj.common.utils.PDFDocumentUtil; |
| | | import com.ltkj.common.utils.SecurityUtils; |
| | | import com.ltkj.common.utils.pdfutils.MergePdf; |
| | | import com.ltkj.common.utils.pdfutils.MyHeaderFooter; |
| | |
| | | import com.ltkj.common.utils.pdfutils.PdfUtils; |
| | | import com.ltkj.hosp.domain.*; |
| | | import com.ltkj.hosp.service.*; |
| | | import com.ltkj.mall.mallOrderUtils.TjConstants; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ltkj.hosp.mapper.TjReportMapper; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | |
| | | private ITjOrderRemarkService tjOrderRemarkService; |
| | | @Resource |
| | | private ITjStandardService tjStandardService; |
| | | @Autowired |
| | | private ITjReportPrintService printService; |
| | | |
| | | /** |
| | | * 查询体检报告存储 |
| | |
| | | return tjReportMapper.deleteTjReportByReId(reId); |
| | | } |
| | | |
| | | @Value("${path.filePath}") |
| | | private String value; |
| | | // @Value("${path.filePath}") |
| | | // private String value; |
| | | |
| | | @Override |
| | | /* @Override |
| | | public AjaxResult getTjReport(String tjNumber) { |
| | | //根据体检号 |
| | | //在order里查询体检状态 判断体检是否完成 |
| | |
| | | TjProject tjProject = projectService.selectTjProjectByProId(tjOrderDetail.getProId()); |
| | | tjOrderDetail.setProject(tjProject); |
| | | } |
| | | /* |
| | | *//* |
| | | * ====================第一部分 填充体检报告封面模板 |
| | | * */ |
| | | * *//* |
| | | //根据数据库中的模板二进制文件 转pdf 创建文件夹 将pdf放进文件夹 |
| | | LambdaQueryWrapper<TjReportTemplate> tjReportTemplateLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | tjReportTemplateLambdaQueryWrapper.eq(TjReportTemplate::getFlag, 1); |
| | |
| | | //当前登录的人工号 |
| | | String userId = SecurityUtils.getLoginUser().getUsername(); |
| | | //二进制转pdf 存储在临时文件夹中 |
| | | PDFBinaryUtil.base64StringToPDF(template, FileUtil.mkdir(value).getPath() + "\\" + userId + "体检报告封面模板.pdf"); |
| | | PDFBinaryUtil.base64StringToPDF(template, FileUtil.mkdir(value).getPath() + File.separator + userId + "体检报告封面模板.pdf"); |
| | | |
| | | // 模板文件路径 |
| | | String inputFileName = value + "\\" + userId + "体检报告封面模板.pdf"; |
| | | String inputFileName = value + File.separator + userId + "体检报告封面模板.pdf"; |
| | | // 生成的文件路径 |
| | | String outputFileName = value + "\\" + userId + "体检报告封面页.pdf"; |
| | | String outputFileName = value + File.separator + userId + "体检报告封面页.pdf"; |
| | | OutputStream os = null; |
| | | PdfStamper ps = null; |
| | | PdfReader reader = null; |
| | |
| | | ps.close(); |
| | | os.close(); |
| | | reader.close(); |
| | | /* |
| | | *//* |
| | | * ==========================第二部分 生成项目详情 |
| | | */ |
| | | *//* |
| | | //文档对象 实现A4纸页面 |
| | | Document document = new Document(PageSize.A4); |
| | | //document.setMarginMirroring(true); |
| | | //设置文档的页边距就是距离页面边上的距离,分别为:左边距,右边距,上边距,下边距 |
| | | document.setMargins(70, 70, 40, 40); |
| | | //这个是生成pdf的位置以及名称 |
| | | String fileName = value + "\\" + userId + "体检报告项目详情页.pdf"; |
| | | String fileName = value + File.separator + userId + "体检报告项目详情页.pdf"; |
| | | OutputStream outputStream = Files.newOutputStream(Paths.get(fileName)); |
| | | PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream); |
| | | |
| | |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document.add(objectName); |
| | | } |
| | | /* |
| | | *//* |
| | | * document关闭的其实是文件的监听状态,writer关闭的是io流,writer创建在document之后 |
| | | * */ |
| | | * *//* |
| | | document.close(); |
| | | pdfWriter.close(); |
| | | outputStream.close(); |
| | | |
| | | //=============================== 第三部分 合并体检报告封面页和体检报告项目详情页 |
| | | String[] files1 = {value + "\\" + userId + "体检报告封面页.pdf", value + "\\" + userId + "体检报告项目详情页.pdf"}; |
| | | String outputPath1 = value + "\\"; |
| | | String[] files1 = {value + File.separator + userId + "体检报告封面页.pdf", value + File.separator + userId + "体检报告项目详情页.pdf"}; |
| | | String outputPath1 = value + File.separator; |
| | | String outputFileName1 = tjNumber + "体检报告.pdf"; |
| | | |
| | | File file1 = new File(outputPath1 + outputFileName1); |
| | |
| | | |
| | | //将临时文件夹中的四个文件删除 |
| | | //FileUtil.del(value+"\\"+tjNumber + "体检报告.pdf"); |
| | | FileUtil.del(value + "\\" + userId + "体检报告封面模板.pdf"); |
| | | FileUtil.del(value + "\\" + userId + "体检报告项目详情页.pdf"); |
| | | FileUtil.del(value + "\\" + userId + "体检报告封面页.pdf"); |
| | | FileUtil.del(value + File.separator + userId + "体检报告封面模板.pdf"); |
| | | FileUtil.del(value + File.separator + userId + "体检报告项目详情页.pdf"); |
| | | FileUtil.del(value + File.separator + userId + "体检报告封面页.pdf"); |
| | | |
| | | //修改order表中的打印报告时间为当前时间 |
| | | LambdaUpdateWrapper<TjOrder> updateWrapper = new LambdaUpdateWrapper<>(); |
| | |
| | | } |
| | | } |
| | | return null; |
| | | }*/ |
| | | |
| | | @Override |
| | | public Integer getSelectCount(Wrapper<TjReport> queryWrapper) { |
| | | return tjReportMapper.selectCount(queryWrapper); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | return table; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public AjaxResult makeBatchReport(List<String> tjNumbers,String value) { |
| | | return sqlGetReportToMake(tjNumbers,value); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 通过sql 直接查报告base64进行整合返回 |
| | | * 如果sql数据量巨大 查询缓慢 可以试试 makeReport(List<String > tjNumbers)已注释 |
| | | * @param tjNumbers |
| | | * @return |
| | | */ |
| | | // private AjaxResult sqlGetReportToMake(List<String> tjNumbers) { |
| | | // LambdaQueryWrapper<TjReport> tjReportLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | // tjReportLambdaQueryWrapper.in(TjReport::getTjNumber, tjNumbers); |
| | | // List<TjReport> list = tjReportService.list(tjReportLambdaQueryWrapper); |
| | | // ArrayList<String> base64Pdfs = new ArrayList<>(); |
| | | // for (TjReport report : list) { |
| | | // if (report == null || report.getReport() == null) { |
| | | // // 没有该报告 直接跳过 |
| | | // continue; |
| | | // } |
| | | // base64Pdfs.add(report.getReport()); |
| | | // } |
| | | // tjNumbers.forEach(tjNumber ->{ |
| | | // LambdaUpdateWrapper<TjOrder> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | // updateWrapper.eq(TjOrder::getTjNumber, tjNumber); |
| | | // updateWrapper.set(TjOrder::getPrintLastTime, new Date()); |
| | | // updateWrapper.set(TjOrder::getDownloadLastTime, new Date()); |
| | | // updateWrapper.set(TjOrder::getStatus, TjConstants.TJ_END); |
| | | // tjOrderService.update(updateWrapper); |
| | | // }); |
| | | // try { |
| | | // byte[] mergePDF = PDFDocumentUtil.mergePDFs(base64Pdfs); |
| | | // String s = Base64.getEncoder().encodeToString(mergePDF); |
| | | // return AjaxResult.success().put("file",s); |
| | | // // 本地生成测试 |
| | | //// String PDF_FILE = "d:\\Users\\w\\Desktop\\test.pdf"; |
| | | //// BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(PDF_FILE)); |
| | | //// outputStream.write(mergePDF); |
| | | //// outputStream.flush(); |
| | | //// outputStream.close(); |
| | | // } catch (DocumentException | IOException e) { |
| | | // e.printStackTrace(); |
| | | // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | // return AjaxResult.error("批量生成失败"); |
| | | // } |
| | | // } |
| | | |
| | | private AjaxResult sqlGetReportToMake(List<String> tjNumbers, String value) { |
| | | // LambdaQueryWrapper<TjReport> tjReportLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | // tjReportLambdaQueryWrapper.in(TjReport::getTjNumber, tjNumbers); |
| | | // List<TjReport> list = tjReportService.list(tjReportLambdaQueryWrapper); |
| | | ArrayList<String> base64Pdfs = new ArrayList<>(); |
| | | // for (TjReport report : list) { |
| | | // if (report == null || report.getReport() == null) { |
| | | // // 没有该报告 直接跳过 |
| | | // continue; |
| | | // } |
| | | // base64Pdfs.add(report.getReport()); |
| | | // } |
| | | |
| | | //区域版体检添加院区编码 |
| | | // String key = DataSourceContextHolder.getDataSourceKey(); |
| | | // key = key.replace("ltkjpeis10_",""); |
| | | |
| | | if(null !=tjNumbers && !tjNumbers.isEmpty()){ |
| | | for (String number : tjNumbers) { |
| | | TjOrder order = tjOrderService.getOrderByTjNum(number); |
| | | TjCustomer tjCustomer = tjCustomerService.getById( order.getUserId()); |
| | | String filePath = value + File.separator + File.separator + tjCustomer.getCusId() + order.getTjNumber() + tjCustomer.getCusName() + "_报告.pdf"; |
| | | try { |
| | | // 读取文件为字节数组 |
| | | Path path = Paths.get(filePath); |
| | | byte[] fileBytes = Files.readAllBytes(path); |
| | | // 将字节数组转换为 Base64 字符串 |
| | | String base64String = Base64.getEncoder().encodeToString(fileBytes); |
| | | base64Pdfs.add(base64String); |
| | | |
| | | //保存打印数据记录 |
| | | TjReportPrint print=new TjReportPrint(); |
| | | print.setTjNumber(order.getTjNumber()); |
| | | print.setPrintBy(SecurityUtils.getLoginUser().getUser().getNickName()); |
| | | print.setPrintTime(new Date()); |
| | | print.setPrintStatus("已打印"); |
| | | if (printService.save(print)) { |
| | | order.setPrintLastTime(new Date()); |
| | | order.setStatus(TjConstants.TJ_END); |
| | | tjOrderService.updateById(order); |
| | | } |
| | | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | log.error(String.valueOf(e)); |
| | | } |
| | | } |
| | | try { |
| | | byte[] mergePDF = PDFDocumentUtil.mergePDFs(base64Pdfs); |
| | | String s = Base64.getEncoder().encodeToString(mergePDF); |
| | | return AjaxResult.success().put("file",s); |
| | | } catch (DocumentException | IOException e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | return AjaxResult.error("批量生成失败"); |
| | | } |
| | | } |
| | | return AjaxResult.error("批量生成失败"); |
| | | } |
| | | } |