From e4b5fef59ea127c76f46ba785c19e9da46c9514d Mon Sep 17 00:00:00 2001
From: zjh <1084500556@qq.com>
Date: 星期一, 16 十二月 2024 18:12:13 +0800
Subject: [PATCH] zjh202412016

---
 ltkj-hosp/src/main/java/com/ltkj/hosp/service/impl/TjReportServiceImpl.java |   84 ++++++++++++++++++++++++++++++++++++-----
 1 files changed, 73 insertions(+), 11 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 37563a3..c77c09b 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
@@ -1,22 +1,26 @@
 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.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;
@@ -24,10 +28,13 @@
 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;
 
@@ -183,12 +190,12 @@
                 //褰撳墠鐧诲綍鐨勪汉宸ュ彿
                 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;
@@ -253,7 +260,7 @@
                     //璁剧疆鏂囨。鐨勯〉杈硅窛灏辨槸璺濈椤甸潰杈逛笂鐨勮窛绂伙紝鍒嗗埆涓猴細宸﹁竟璺濓紝鍙宠竟璺濓紝涓婅竟璺濓紝涓嬭竟璺�
                     document.setMargins(70, 70, 40, 40);
                     //杩欎釜鏄敓鎴恜df鐨勪綅缃互鍙婂悕绉�
-                    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);
 
@@ -321,8 +328,8 @@
                     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);
@@ -342,9 +349,9 @@
 
                     //灏嗕复鏃舵枃浠跺す涓殑鍥涗釜鏂囦欢鍒犻櫎
                     //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<>();
@@ -362,6 +369,11 @@
             }
         }
         return null;
+    }
+
+    @Override
+    public Integer getSelectCount(Wrapper<TjReport> queryWrapper) {
+        return tjReportMapper.selectCount(queryWrapper);
     }
 
 
@@ -502,4 +514,54 @@
         }
         return table;
     }
+
+
+    @Override
+    public AjaxResult makeBatchReport(List<String> tjNumbers) {
+        return sqlGetReportToMake(tjNumbers);
+
+    }
+
+    /**
+     * 閫氳繃sql 鐩存帴鏌ユ姤鍛奲ase64杩涜鏁村悎杩斿洖
+     * 濡傛灉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("鎵归噺鐢熸垚澶辫触");
+        }
+    }
 }

--
Gitblit v1.8.0