From 5e4d1aa4b27cfbcf1c4c8beb2ac05f3c7a0cf1bb Mon Sep 17 00:00:00 2001 From: zjh <1084500556@qq.com> Date: 星期二, 18 二月 2025 16:55:45 +0800 Subject: [PATCH] zjh20250218 --- ltkj-hosp/src/main/java/com/ltkj/hosp/service/impl/TjReportServiceImpl.java | 90 +++++++++++++++++++++++++++++---------------- 1 files changed, 58 insertions(+), 32 deletions(-) diff --git a/ltkj-hosp/src/main/java/com/ltkj/hosp/service/impl/TjReportServiceImpl.java b/ltkj-hosp/src/main/java/com/ltkj/hosp/service/impl/TjReportServiceImpl.java index c77c09b..337ad2d 100644 --- a/ltkj-hosp/src/main/java/com/ltkj/hosp/service/impl/TjReportServiceImpl.java +++ b/ltkj-hosp/src/main/java/com/ltkj/hosp/service/impl/TjReportServiceImpl.java @@ -2,6 +2,7 @@ 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; @@ -26,6 +27,7 @@ import com.ltkj.common.utils.pdfutils.MyHeaderFooter; import com.ltkj.common.utils.pdfutils.PDFBinaryUtil; import com.ltkj.common.utils.pdfutils.PdfUtils; +import com.ltkj.db.DataSourceContextHolder; import com.ltkj.hosp.domain.*; import com.ltkj.hosp.service.*; import com.ltkj.mall.mallOrderUtils.TjConstants; @@ -75,7 +77,8 @@ private ITjOrderRemarkService tjOrderRemarkService; @Resource private ITjStandardService tjStandardService; - + @Autowired + private ITjReportPrintService printService; /** * 鏌ヨ浣撴鎶ュ憡瀛樺偍 * @@ -529,39 +532,62 @@ * @return */ private AjaxResult sqlGetReportToMake(List<String> tjNumbers) { - LambdaQueryWrapper<TjReport> tjReportLambdaQueryWrapper = new LambdaQueryWrapper<>(); - tjReportLambdaQueryWrapper.in(TjReport::getTjNumber, tjNumbers); - List<TjReport> list = tjReportService.list(tjReportLambdaQueryWrapper); +// 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; +// 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 + key + 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); + // 杈撳嚭 Base64 缂栫爜鐨勫瓧绗︿覆 +// System.out.println(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)); + } } - base64Pdfs.add(report.getReport()); + 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("鎵归噺鐢熸垚澶辫触"); + } } - 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("鎵归噺鐢熸垚澶辫触"); - } + return AjaxResult.error("鎵归噺鐢熸垚澶辫触"); } } -- Gitblit v1.8.0