| | |
| | | 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.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.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; |
| | | |
| | |
| | | } |
| | | return table; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public AjaxResult makeBatchReport(List<String> tjNumbers) { |
| | | return sqlGetReportToMake(tjNumbers); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 通过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("批量生成失败"); |
| | | } |
| | | } |
| | | } |