From b7103b4da9d05a5faa3c2eea81eff376380eb7dc Mon Sep 17 00:00:00 2001
From: zhaowenxuan <chacca165@163.com>
Date: 星期二, 10 十二月 2024 01:00:16 +0800
Subject: [PATCH] pdf调整

---
 ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisPDFUtil.java |  867 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 728 insertions(+), 139 deletions(-)

diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisPDFUtil.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisPDFUtil.java
index 2a6a257..3f2c630 100644
--- a/ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisPDFUtil.java
+++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisPDFUtil.java
@@ -3,11 +3,16 @@
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.itextpdf.text.*;
+import com.itextpdf.text.Font;
+import com.itextpdf.text.Image;
+import com.itextpdf.text.Rectangle;
 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.core.domain.entity.SysUser;
 import com.ltkj.common.utils.DateUtils;
 import com.ltkj.framework.config.MatchUtils;
@@ -17,22 +22,31 @@
 import com.ltkj.hosp.sqlDomain.LtkjExamJcbgd;
 import com.ltkj.hosp.sqlDomain.LtkjHybgd;
 import com.ltkj.hosp.sqlDomain.LtkjHysqd;
+import com.ltkj.hosp.vodomain.CsProVo;
 import com.ltkj.system.service.ISysConfigService;
+import com.ltkj.system.service.ISysDictDataService;
 import com.ltkj.system.service.ISysUserService;
 import com.ltkj.web.config.pdfutils.PdfUtils;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.awt.*;
 import java.io.*;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+
+import static com.ltkj.common.utils.pdfutils.PdfUtils.createTable;
 
 /**
  * 妫�鏌� 妫�楠屾姤鍛妏df鐢熸垚
@@ -80,6 +94,10 @@
     private LtkjExamJcbgdService jcbgdService;
     @Resource
     private LtkjExamJcsqdService jcsqdService;
+    @Autowired
+    private IDictHospService dictHospService;
+    @Autowired
+    private ISysDictDataService sysDictDataService;
 
     private List<Map<String, Object>> makePDFInfo(HashMap<String, Object> map, AjaxResult ajaxResult, String key) {
         List<Map<String, Object>> data = null;
@@ -103,7 +121,12 @@
     }
 
     public AjaxResult hisPDF(TjOrder tjOrder, TjCustomer customer, TjReportTemplate tjReportTemplate) throws Exception {
-        HashMap<String, Object> pdfChangGui = makePDFInfo(tjOrder, customer, tjReportTemplate);
+        DictHosp dictHosp = dictHospService.list().get(0);
+        String color = sysConfigService.selectConfigByKey("report_title_color");
+//        list.get(0).getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")
+        List<SysDictData> sysUserSex = sysDictDataService.list(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, "sys_user_sex"));
+        HashMap<String, Object> map = makeHisJianYan(tjOrder, customer);
+        HashMap<String, Object> pdfChangGui = makePDFInfo(tjOrder, customer, tjReportTemplate,dictHosp,map);
         if (pdfChangGui == null)
             return AjaxResult.error();
         Document document = (Document) pdfChangGui.get("document");
@@ -112,33 +135,72 @@
         ByteArrayOutputStream byteArrayOutputStream1 = new ByteArrayOutputStream();
         Document document1 = new Document(PageSize.A4);
         PdfWriter pdfWriter = null;
+        int pageSize = 0;
         try {
             pdfWriter = PdfWriter.getInstance(document1, byteArrayOutputStream1);
+            if (dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")){
+                String sex = "";
+                if (customer.getCusSex() != null) {
+                    for (SysDictData userSex : sysUserSex) {
+                        if (userSex.getDictValue().equals(String.valueOf(customer.getCusSex()))) {
+                            sex = userSex.getDictLabel();
+                        }
+                    }
+                }
+                if (StrUtil.isBlank(sex)) sex = "鏈煡";
+                pdfWriter.setPageEvent(new FooterHeaderPageEvent("婢勫悎鐭垮姟灞�涓績鍖婚櫌",customer.getCusName(),tjOrder.getTjNumber(),sex,String.valueOf(DateUtil.ageOfNow(customer.getCusBrithday()))));
+                pageSize = pdfWriter.getPageNumber();
+            }
         } catch (DocumentException e) {
-            e.printStackTrace();
+            log.error(String.valueOf(e));
             return AjaxResult.error();
         }
         document1.setMargins(70, 70, 40, 40);
         document1.open();
-        // 闈炲寲楠岄」鐩姤鍛�
-        Map<TjOrderRemark, List<TjPdfVO>> printReport = new HashMap<>();
-        notHuaYanData(tjOrder.getTjNumber(), printReport, tjOrder, customer);
-        try {
-            notHuaYanTable(document1, printReport);
-        } catch (DocumentException e) {
-            log.error("闈炲寲楠岄」鐩~鍏呰〃鏍煎紓甯�");
-            e.printStackTrace();
-            return AjaxResult.error();
+
+        if (dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")){
+            // 缁勮浣撴妫�鏌ラ」鐩姤鍛�
+            Map<TjOrderRemark, List<TjPdfVO>> printReport = new HashMap<>();
+            notHuaYanData(tjOrder.getTjNumber(), printReport, tjOrder, customer);
+            try {
+                notHuaYanTable(document1, printReport,dictHosp,color);
+            } catch (DocumentException e) {
+                log.error("闈炲寲楠岄」鐩~鍏呰〃鏍煎紓甯�");
+                log.error(String.valueOf(e));
+                return AjaxResult.error();
+            }
+            // 缁勮妫�楠屾暟鎹�
+            makeHisJianYanTable(document1, map,dictHosp,color);
+
+            // 缁勮pacs妫�鏌ユ暟鎹�
+            printReport = new HashMap<>();
+            pacsJianChaData(tjOrder.getTjNumber(), printReport, tjOrder, customer);
+            try {
+                notHuaYanTable(document1, printReport,dictHosp,color);
+            } catch (DocumentException e) {
+                log.error("闈炲寲楠岄」鐩~鍏呰〃鏍煎紓甯�");
+                log.error(String.valueOf(e));
+                return AjaxResult.error();
+            }
+        }else {
+            // 闈炲寲楠岄」鐩姤鍛�
+            Map<TjOrderRemark, List<TjPdfVO>> printReport = new HashMap<>();
+            notHuaYanData(tjOrder.getTjNumber(), printReport, tjOrder, customer);
+            try {
+                notHuaYanTable(document1, printReport,dictHosp,color);
+            } catch (DocumentException e) {
+                log.error("闈炲寲楠岄」鐩~鍏呰〃鏍煎紓甯�");
+                log.error(String.valueOf(e));
+                return AjaxResult.error();
+            }
+            // 缁勮妫�楠屾暟鎹�
+            makeHisJianYanTable(document1, map,dictHosp,color);
         }
-        // 缁勮妫�楠屾暟鎹�
-        HashMap<String, Object> map = makeHisJianYan(tjOrder, customer);
-        makeHisJianYanTable(document1, map);
 
 
-        List<ByteArrayOutputStream> jianchas = makeHisJianChaTable(tjOrder);
+        List<ByteArrayOutputStream> jianchas =  makeHisJianChaTable(tjOrder);
 //        List<ByteArrayOutputStream> jianchas = makeCcgcHisJianChaTable(tjOrder);
         document1.close();
-        pdfWriter.close();
         PdfReader reader = null;
         try {
             reader = new PdfReader(byteArrayOutputStream1.toByteArray());
@@ -162,7 +224,7 @@
             copy.close();
         } catch (IOException e) {
             log.error("鎷疯礉pdf寮傚父");
-            e.printStackTrace();
+            log.error(String.valueOf(e));
             return AjaxResult.error();
         }
         String outputFileName1 = customer.getCusId() + tjOrder.getTjNumber() + customer.getCusName() + "_鎶ュ憡.pdf";
@@ -171,25 +233,128 @@
             int pages = pdfReader.getNumberOfPages();
             ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
             PdfStamper pdfStamper = new PdfStamper(pdfReader, outputStream);
-            PdfContentByte contentByte;
-            BaseFont baseFont = PdfUtils.createBaseFont(null);
-            for (int i = 2; i <= pages; i++) {
-                contentByte = pdfStamper.getOverContent(i);
-                contentByte.beginText();
-                contentByte.setFontAndSize(baseFont, 11);
-                float x = contentByte.getPdfDocument().getPageSize().getWidth() / 2;
-                float y = 20;
-                contentByte.showTextAligned(PdfContentByte.ALIGN_CENTER, String.valueOf(i - 1), x, y, 0);
-                contentByte.endText();
+            if (!dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")){
+                PdfContentByte contentByte;
+                BaseFont baseFont = PdfUtils.createBaseFont(null);
+                for (int i = 2; i <= pages; i++) {
+                    contentByte = pdfStamper.getOverContent(i);
+                    contentByte.beginText();
+                    contentByte.setFontAndSize(baseFont, 11);
+                    float x = contentByte.getPdfDocument().getPageSize().getWidth() / 2;
+                    float y = 20;
+                    contentByte.showTextAligned(PdfContentByte.ALIGN_CENTER, String.valueOf(i - 1), x, y, 0);
+                    contentByte.endText();
+                }
             }
             pdfStamper.close();
             pdfReader.close();
             finalOutPut = outputStream;
         } catch (IOException e) {
-            e.printStackTrace();
+            log.error(String.valueOf(e));
             return AjaxResult.error();
         }
         savePDFFile(outputFileName1, tjOrder, customer, finalOutPut);
+        return AjaxResult.success();
+    }
+
+    public AjaxResult hisPDFNew(TjOrder tjOrder, TjCustomer customer, TjReportTemplate tjReportTemplate) throws Exception {
+        DictHosp dictHosp = dictHospService.list().get(0);
+        String color = sysConfigService.selectConfigByKey("report_title_color");
+        List<SysDictData> sysUserSex = sysDictDataService.list(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, "sys_user_sex"));
+
+        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+        Document document = new Document(PageSize.A4);
+        PdfWriter pdfWriter = null;
+        int pageSize = 0;
+        try {
+            pdfWriter = PdfWriter.getInstance(document, byteArrayOutputStream);
+                String sex = "";
+                if (customer.getCusSex() != null) {
+                    for (SysDictData userSex : sysUserSex) {
+                        if (userSex.getDictValue().equals(String.valueOf(customer.getCusSex()))) {
+                            sex = userSex.getDictLabel();
+                        }
+                    }
+                }
+                if (StrUtil.isBlank(sex)) sex = "鏈煡";
+                pdfWriter.setPageEvent(new FooterHeaderPageEvent(dictHosp.getHospName(),customer.getCusName(),tjOrder.getTjNumber(),sex,String.valueOf(DateUtil.ageOfNow(customer.getCusBrithday()))));
+                pageSize = pdfWriter.getPageNumber();
+        } catch (DocumentException e) {
+            log.error(String.valueOf(e));
+            return AjaxResult.error();
+        }
+
+        Map<TjOrderRemark, List<TjPdfVO>> printReport = new HashMap<>();
+        notHuaYanData(tjOrder.getTjNumber(), printReport, tjOrder, customer);
+        try {
+            notHuaYanTable(document, printReport,dictHosp,color);
+        } catch (DocumentException e) {
+            log.error("闈炲寲楠岄」鐩~鍏呰〃鏍煎紓甯�");
+            log.error(String.valueOf(e));
+            return AjaxResult.error();
+        }
+        PdfReader reader = null;
+
+        // 妫�楠屾暟鎹�
+        HashMap<String, Object> map = makeHisJianYan(tjOrder, customer);
+        makeHisJianYanTable(document, map,dictHosp,color);
+        List<ByteArrayOutputStream> jianchas =  makeHisJianChaTable(tjOrder);
+        document.close();
+
+        Document document1 = new Document(PageSize.A4);
+        ByteArrayOutputStream finalOutPut = new ByteArrayOutputStream();
+        PdfCopy copy = new PdfCopy(document1, finalOutPut);
+        byte[] bytes = byteArrayOutputStream.toByteArray();
+        document1.open();
+        reader = new PdfReader(bytes);
+
+        int numberOfPages = reader.getNumberOfPages();
+
+
+
+
+
+        try {
+            reader = new PdfReader(byteArrayOutputStream.toByteArray());
+            int numberOfPages1 = reader.getNumberOfPages();
+            for (int i = 1; i <= numberOfPages1; i++) {
+                PdfImportedPage page = copy.getImportedPage(reader, i);
+                copy.addPage(page);
+            }
+            for (ByteArrayOutputStream jiancha : jianchas) {
+                reader = new PdfReader(jiancha.toByteArray());
+                numberOfPages1 = reader.getNumberOfPages();
+                for (int i = 1; i <= numberOfPages1; i++) {
+                    PdfImportedPage page = copy.getImportedPage(reader, i);
+                    copy.addPage(page);
+                }
+                jiancha.close();
+            }
+            reader.close();
+            byteArrayOutputStream.close();
+            document.close();
+            copy.close();
+        } catch (IOException e) {
+            log.error("鎷疯礉pdf寮傚父");
+            log.error(String.valueOf(e));
+            return AjaxResult.error();
+        }
+
+
+
+
+        /*
+        * 绗簩椤垫鏌ョ姸鎬佷俊鎭� 妫�鏌ョ瀹や笌妫�鏌ラ」鐩�
+        * <span v-if="scope.row.type == '0'">鏈</span>
+        * <span v-if="scope.row.type == '1'">宸叉</span>
+        * <span v-if="scope.row.type == '2'">寮冩</span>
+        * <span v-if="scope.row.type == '3'">寤舵湡</span>
+        * */
+        List<CsProVo> list = tjOrderRemarkService.cSWebGetProByTjNumAndOrderId(tjOrder.getTjNumber(),false);
+
+
+
+
         return AjaxResult.success();
     }
 
@@ -212,7 +377,7 @@
         elements.setSpacingAfter(10f);
         elements.setAlignment(Element.ALIGN_RIGHT);
         Phrase phrase = new Phrase();
-        Font doctorFonts = PdfUtils.setFont(9);
+        Font doctorFonts = PdfUtils.setFont(11);
         for (LtkjGetexamreportinfo getexamreportinfo : list) {
             String xm = getexamreportinfo.getHzxm();
             String xb = getexamreportinfo.getHzxb().equals("2") ? "濂�" : "鐢�";
@@ -377,10 +542,9 @@
      * @param customer
      * @param finalOutPut
      */
-    private void savePDFFile(String outputFileName1, TjOrder tjOrder, TjCustomer customer, ByteArrayOutputStream finalOutPut) throws IOException {
-        // 鏂囦欢閰嶇疆
-//        String outputPath1 = "/Users/chacca/寮�鍙戠浉鍏�/浠g爜/";
-        String outputPath1 = value + "\\";
+    private void savePDFFile(String outputFileName1, TjOrder tjOrder, TjCustomer customer, ByteArrayOutputStream finalOutPut) throws IOException, DocumentException, InterruptedException {
+        // 绗竴姝ワ細鐢熸垚鏂囦欢骞朵繚瀛�
+        String outputPath1 = value + File.separator;
         File file = new File(outputPath1 + outputFileName1);
         BufferedOutputStream outputStream = null;
         outputStream = new BufferedOutputStream(new FileOutputStream(file));
@@ -388,7 +552,30 @@
         outputStream.flush();
         outputStream.close();
         finalOutPut.close();
+
+//        Thread.sleep(2000);
+//
+//        FileInputStream fileInputStream = new FileInputStream(file);
+//        FileOutputStream fileOutputStream = new FileOutputStream(file);
+//
+//        PdfReader pdfReader = new PdfReader(fileInputStream);
+//        PdfStamper pdfStamper = new PdfStamper(pdfReader, fileOutputStream);
+//        AcroFields form = pdfStamper.getAcroFields();
+//
+//        List<String> fieldNames = new ArrayList<>(form.getFields().keySet());
+//        if (fieldNames.contains("page")) {
+//            form.setField("page", "1111");
+//        }
+//
+//        pdfStamper.setFormFlattening(true);  // 璁剧疆涓� true 鍚庤〃鍗曞瓧娈典笉鍙紪杈�
+//
+//        pdfStamper.close();
+//        pdfReader.close();
+//        fileInputStream.close();
+//        fileOutputStream.close();
     }
+
+
 
     /**
      * 濉厖妫�楠岃〃鏍兼暟鎹�
@@ -397,18 +584,19 @@
      * @param map
      * @throws DocumentException
      */
-    private void makeHisJianYanTable(Document document1, HashMap<String, Object> map) throws DocumentException {
+    private void makeHisJianYanTable(Document document1, HashMap<String, Object> map,DictHosp dictHosp,String colorStr) throws DocumentException {
         if (!map.isEmpty()) {
-            String[] titles = new String[]{"浣撴椤圭洰", "浣撴缁撴灉", "鍗曚綅", "鍙傝�冭寖鍥�"};
-            float[] titlesWidth = new float[]{120, 120, 120, 120};
+            String[] titles = new String[]{"浣撴椤圭洰", "浣撴缁撴灉","鎻愮ず", "鍗曚綅", "鍙傝�冭寖鍥�"};
+            float[] titlesWidth = new float[]{280, 100, 40, 100, 120};
             for (Map.Entry<String, Object> entry : map.entrySet()) {
                 String titleName = entry.getKey().trim();
                 HashMap<String, Object> entryValue = (HashMap<String, Object>) entry.getValue();
                 HashSet<String> jyys = (HashSet<String>) entryValue.get("jyys");
                 ArrayList<List<String>> lists = (ArrayList<List<String>>) entryValue.get("data");
-                addJianYanTable(document1, titleName, titles, titlesWidth, lists);
+                String shsj = entryValue.get("shsj").toString();
+                addJianYanTable(document1, titleName, titles, titlesWidth, lists,dictHosp,colorStr);
                 if (!jyys.isEmpty()) {
-                    Font doctorFonts = PdfUtils.setFont(9);
+                    Font doctorFonts = PdfUtils.setFont(11);
                     String doctors = "";
                     Paragraph elements = new Paragraph();
                     elements.setLeading(5f);
@@ -416,7 +604,7 @@
                     elements.setSpacingAfter(10f);
                     elements.setAlignment(Element.ALIGN_RIGHT);
                     Phrase phrase = new Phrase();
-                    phrase.add(new Chunk("瀹℃牳鍖诲笀锛�",doctorFonts));
+                    phrase.add(new Chunk("妫�鏌ユ棩鏈燂細"+shsj+"         瀹℃牳鍖诲笀锛�",doctorFonts));
                     boolean flag = false;
                     for (String s : jyys) {
                         if (s.contains("|")) {
@@ -442,7 +630,7 @@
                     }
                     if (!flag) {
                         String substring = doctors.substring(0, doctors.length() - 1).trim();
-                        Paragraph df = PdfUtils.setParagraph(doctorFonts, "瀹℃牳鍖诲笀锛�" + substring);
+                        Paragraph df = PdfUtils.setParagraph(doctorFonts, "妫�鏌ユ棩鏈燂細"+shsj+"         瀹℃牳鍖诲笀锛�" + substring);
                         df.setAlignment(Element.ALIGN_RIGHT);
                         document1.add(df);
                     } else {
@@ -451,9 +639,11 @@
                     }
                 }
                 //鍒嗗壊绾�
-                LineSeparator objectName = new LineSeparator();
-                objectName.setOffset(-5);
-                document1.add(objectName);
+                if (!dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")) {
+                    LineSeparator objectName = new LineSeparator();
+                    objectName.setOffset(-5);
+                    document1.add(objectName);
+                }
             }
         }
     }
@@ -465,13 +655,15 @@
      * @param printReport
      * @throws DocumentException
      */
-    private void notHuaYanTable(Document document1, Map<TjOrderRemark, List<TjPdfVO>> printReport) throws DocumentException {
+    private void notHuaYanTable(Document document1, Map<TjOrderRemark, List<TjPdfVO>> printReport,DictHosp dictHosp,String colorStr) throws DocumentException {
         for (Map.Entry<TjOrderRemark, List<TjPdfVO>> entry : printReport.entrySet()) {
             LambdaQueryWrapper<TjProject> wqqq = new LambdaQueryWrapper<>();
             wqqq.eq(TjProject::getProId, entry.getKey().getProId());
             TjProject one11 = projectService.getOne(wqqq);
+            if (entry.getValue().isEmpty()) continue;
             //鍒ゆ柇璇ラ」鐩槸鍚﹂渶瑕佹墦鍗版姤鍛�
             if (null != one11 && "Y".equals(one11.getNeedReport())) {
+                TjOrderRemark orderRemark = entry.getKey();
                 List<TjPdfVO> value = entry.getValue();
                 String titleName = null;
                 if (null != one11 && "1".equals(one11.getResultType())) {
@@ -479,46 +671,94 @@
                     // 璁剧疆鏍囬瀛椾綋鏍峰紡
                     Font titleFonts = PdfUtils.setFont(9);
                     Paragraph paragraph = PdfUtils.setParagraph(titleFonts, titleName);
-                    String[] titles = {"浣撴椤圭洰", "浣撴缁撴灉", "鍗曚綅"};
-                    // 鑾峰彇鍒楄〃鏁版嵁
-                    //璁剧疆琛ㄥご瀛椾綋鏍峰紡
-                    Font headFont = PdfUtils.setFont(9);
-                    // 璁剧疆姝f枃瀛椾綋鏍峰紡锛�12鍙�
-                    Font textFont = PdfUtils.setFont(9);
-                    //鍒涘缓琛ㄦ牸  灏嗚〃澶村瓧浣撳拰姝f枃瀛椾綋鏀捐繘鍘�
-                    PdfPTable table = PdfUtils.setTable2(headFont, textFont, titles, value);
-                    document1.add(paragraph);
-                    document1.add(table);
+
+                    if (dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")) {
+                        Font titleFont = PdfUtils.setFont(11);
+                        titleFont.setStyle(Font.BOLD);
+                        PdfPCell cellTitle = new PdfPCell(PdfUtils.setParagraph(titleFont, titleName));
+                        cellTitle.setBorder(Rectangle.NO_BORDER);
+                        Color color = Color.decode(colorStr);
+                        cellTitle.setBackgroundColor(new BaseColor(color.getRed(), color.getGreen(), color.getBlue())); // 璁剧疆鑳屾櫙棰滆壊锛堝崄鍏繘鍒� RGB锛�
+                        // 鍒涘缓琛ㄦ牸骞舵坊鍔犲崟鍏冩牸
+                        PdfPTable tableTitle = new PdfPTable(1);
+                        tableTitle.setWidthPercentage(100);
+                        tableTitle.addCell(cellTitle);
+                        // 灏嗚〃鏍兼坊鍔犲埌鏂囨。涓�
+                        document1.add(tableTitle);
+                    }else {
+                        document1.add(paragraph);
+                    }
+
+
+//                    String[] titles = {"浣撴椤圭洰", "浣撴缁撴灉", "鍗曚綅"};
+//                    Font headFont = PdfUtils.setFont(9);
+//                    Font textFont = PdfUtils.setFont(9);
+//                    PdfPTable table = PdfUtils.setTable2(headFont, textFont, titles, value,dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌"));
+//                    document1.add(table);
+
+                    if (dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌") && !value.isEmpty()){
+                        if (value.size()>1){
+                            String[] titles = {"浣撴椤圭洰", "浣撴缁撴灉", "鍗曚綅"};
+                            Font headFont = PdfUtils.setFont(9);
+                            Font textFont = PdfUtils.setFont(9);
+                            PdfPTable table = PdfUtils.setTable2(headFont, textFont, titles, value,dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌"));
+                            document1.add(table);
+                        }else {
+                            Font remarkFonts = PdfUtils.setFont(9);
+                            Paragraph pp = PdfUtils.setParagraph(remarkFonts, "妫�鏌ユ墍瑙侊細");
+                            document1.add(pp);
+                            Paragraph ppp = new Paragraph(value.get(0).getSj(), remarkFonts);
+                            paragraph.setAlignment(Element.ALIGN_LEFT);
+                            paragraph.setLeading(5f);
+                            document1.add(ppp);
+                            pp = PdfUtils.setParagraph(remarkFonts, "缁撹锛�");
+                            document1.add(pp);
+                            ppp = new Paragraph(value.get(0).getTs(), remarkFonts);
+                            paragraph.setAlignment(Element.ALIGN_LEFT);
+                            paragraph.setLeading(5f);
+                            document1.add(ppp);
+                        }
+                    }else {
+                        String[] titles = {"浣撴椤圭洰", "浣撴缁撴灉", "鍗曚綅"};
+                        Font headFont = PdfUtils.setFont(9);
+                        Font textFont = PdfUtils.setFont(9);
+                        PdfPTable table = PdfUtils.setTable2(headFont, textFont, titles, value,dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌"));
+                        document1.add(table);
+                    }
                     //鍒ゆ柇澶囨敞鏄惁涓虹┖  绌轰笉鑳芥樉绀簄ull
                     if (entry.getKey().getRemark() == null) {
                         entry.getKey().setRemark("");
                     }
-                    String remark = "澶囨敞锛�" + entry.getKey().getRemark();
-                    if (entry.getKey().getRemark().length() > 50) {
-                        int j = 0;
-                        for (int i = 0; i < remark.length() / 50; i++) {
-                            String substring = remark.substring(j, j + 50);
+                    if (!dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")){
+                        String remark = "澶囨敞锛�" + entry.getKey().getRemark();
+                        if (entry.getKey().getRemark().length() > 50) {
+                            int j = 0;
+                            for (int i = 0; i < remark.length() / 50; i++) {
+                                String substring = remark.substring(j, j + 50);
+                                Font remarkFonts = PdfUtils.setFont(9);
+                                Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring);
+                                document1.add(pp);
+                                j = j + 50;
+                            }
+                            if (remark.length() % 50 != 0) {
+                                String substring = remark.substring((remark.length() / 50) * 50, remark.length() - 1);
+                                Font remarkFonts = PdfUtils.setFont(9);
+                                Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring);
+                                document1.add(pp);
+                            }
+                        } else {
                             Font remarkFonts = PdfUtils.setFont(9);
-                            Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring);
-                            document1.add(pp);
-                            j = j + 50;
-                        }
-                        if (remark.length() % 50 != 0) {
-                            String substring = remark.substring((remark.length() / 50) * 50, remark.length() - 1);
-                            Font remarkFonts = PdfUtils.setFont(9);
-                            Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring);
+                            Paragraph pp = PdfUtils.setParagraph(remarkFonts, remark);
                             document1.add(pp);
                         }
-                    } else {
-                        Font remarkFonts = PdfUtils.setFont(9);
-                        Paragraph pp = PdfUtils.setParagraph(remarkFonts, remark);
-                        document1.add(pp);
                     }
                     //鍒ゆ柇涓绘鍖诲笀鏄惁涓虹┖  绌轰笉鑳芥樉绀簄ull
-                    zhuJianYiShi(document1, entry);
+                    zhuJianYiShi(document1, entry,orderRemark.getCreateTime(),dictHosp);
                     //鍒嗗壊绾�
-                    LineSeparator objectName = new LineSeparator();
-                    document1.add(objectName);
+                    if (!dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")) {
+                        LineSeparator objectName = new LineSeparator();
+                        document1.add(objectName);
+                    }
                 } else {
                     if (null != one11) {
                         titleName = one11.getProName();
@@ -528,46 +768,96 @@
                     // 璁剧疆鏍囬瀛椾綋鏍峰紡
                     Font titleFonts = PdfUtils.setFont(9);
                     Paragraph paragraph = PdfUtils.setParagraph(titleFonts, titleName);
-                    String[] titles = {"浣撴椤圭洰", "浣撴缁撴灉", "鍗曚綅"};
-                    // 鑾峰彇鍒楄〃鏁版嵁
-                    //璁剧疆琛ㄥご瀛椾綋鏍峰紡
-                    Font headFont = PdfUtils.setFont(9);
-                    // 璁剧疆姝f枃瀛椾綋鏍峰紡锛�12鍙�
-                    Font textFont = PdfUtils.setFont(9);
-                    //鍒涘缓琛ㄦ牸  灏嗚〃澶村瓧浣撳拰姝f枃瀛椾綋鏀捐繘鍘�
-                    PdfPTable table = PdfUtils.setTable(headFont, textFont, titles, value);
-                    document1.add(paragraph);
-                    document1.add(table);
+
+                    if (dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")) {
+                        Font titleFont = PdfUtils.setFont(11);
+                        titleFont.setStyle(Font.BOLD);
+                        PdfPCell cellTitle = new PdfPCell(PdfUtils.setParagraph(titleFont, titleName));
+                        cellTitle.setBorder(Rectangle.NO_BORDER);
+                        Color color = Color.decode("#B4CDCD");
+                        cellTitle.setBackgroundColor(new BaseColor(color.getRed(), color.getGreen(), color.getBlue())); // 璁剧疆鑳屾櫙棰滆壊锛堝崄鍏繘鍒� RGB锛�
+                        // 鍒涘缓琛ㄦ牸骞舵坊鍔犲崟鍏冩牸
+                        PdfPTable tableTitle = new PdfPTable(1);
+                        tableTitle.setWidthPercentage(100);
+                        tableTitle.addCell(cellTitle);
+                        // 灏嗚〃鏍兼坊鍔犲埌鏂囨。涓�
+                        document1.add(tableTitle);
+                    }else {
+                        document1.add(paragraph);
+                    }
+
+//                    String[] titles = {"浣撴椤圭洰", "浣撴缁撴灉", "鍗曚綅"};
+//                    Font headFont = PdfUtils.setFont(9);
+//                    Font textFont = PdfUtils.setFont(9);
+//                    PdfPTable table = PdfUtils.setTable(headFont, textFont, titles, value,dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌"));
+//                    document1.add(table);
+
+                    if (dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌") && !value.isEmpty()){
+                        System.out.println("value = " + value);
+                        if (value.size()>1){
+                            String[] titles = {"浣撴椤圭洰", "浣撴缁撴灉", "鍗曚綅"};
+                            Font headFont = PdfUtils.setFont(9);
+                            Font textFont = PdfUtils.setFont(9);
+                            PdfPTable table = PdfUtils.setTable2(headFont, textFont, titles, value,dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌"));
+                            document1.add(table);
+                        }else {
+                            Font remarkFonts = PdfUtils.setFont(9);
+                            Paragraph pp = PdfUtils.setParagraph(remarkFonts, "妫�鏌ユ墍瑙侊細");
+                            document1.add(pp);
+                            Paragraph ppp = new Paragraph(value.get(0).getSj(), remarkFonts);
+                            paragraph.setAlignment(Element.ALIGN_LEFT);
+                            paragraph.setLeading(5f);
+                            document1.add(ppp);
+                            pp = PdfUtils.setParagraph(remarkFonts, "缁撹锛�");
+                            document1.add(pp);
+                            ppp = new Paragraph(value.get(0).getTs(), remarkFonts);
+                            paragraph.setAlignment(Element.ALIGN_LEFT);
+                            paragraph.setLeading(5f);
+                            document1.add(ppp);
+                        }
+                    }else {
+                        String[] titles = {"浣撴椤圭洰", "浣撴缁撴灉", "鍗曚綅"};
+                        Font headFont = PdfUtils.setFont(9);
+                        Font textFont = PdfUtils.setFont(9);
+                        PdfPTable table = PdfUtils.setTable(headFont, textFont, titles, value,dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌"));
+                        document1.add(table);
+                    }
+
+
                     //鍒ゆ柇澶囨敞鏄惁涓虹┖  绌轰笉鑳芥樉绀簄ull
                     if (entry.getKey().getRemark() == null) {
                         entry.getKey().setRemark("");
                     }
-                    String remark = "澶囨敞锛�" + entry.getKey().getRemark();
-                    if (entry.getKey().getRemark().length() > 50) {
-                        int j = 0;
-                        for (int i = 0; i < remark.length() / 50; i++) {
-                            String substring = remark.substring(j, j + 50);
+                    if (!dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")){
+                        String remark = "澶囨敞锛�" + entry.getKey().getRemark();
+                        if (entry.getKey().getRemark().length() > 50) {
+                            int j = 0;
+                            for (int i = 0; i < remark.length() / 50; i++) {
+                                String substring = remark.substring(j, j + 50);
+                                Font remarkFonts = PdfUtils.setFont(9);
+                                Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring);
+                                document1.add(pp);
+                                j = j + 50;
+                            }
+                            if (remark.length() % 50 != 0) {
+                                String substring = remark.substring((remark.length() / 50) * 50, remark.length() - 1);
+                                Font remarkFonts = PdfUtils.setFont(9);
+                                Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring);
+                                document1.add(pp);
+                            }
+                        } else {
                             Font remarkFonts = PdfUtils.setFont(9);
-                            Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring);
-                            document1.add(pp);
-                            j = j + 50;
-                        }
-                        if (remark.length() % 50 != 0) {
-                            String substring = remark.substring((remark.length() / 50) * 50, remark.length() - 1);
-                            Font remarkFonts = PdfUtils.setFont(9);
-                            Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring);
+                            Paragraph pp = PdfUtils.setParagraph(remarkFonts, remark);
                             document1.add(pp);
                         }
-                    } else {
-                        Font remarkFonts = PdfUtils.setFont(9);
-                        Paragraph pp = PdfUtils.setParagraph(remarkFonts, remark);
-                        document1.add(pp);
                     }
                     //鍒ゆ柇涓绘鍖诲笀鏄惁涓虹┖  绌轰笉鑳芥樉绀簄ull
-                    zhuJianYiShi(document1, entry);
-                    //鍒嗗壊绾�
-                    LineSeparator objectName = new LineSeparator();
-                    document1.add(objectName);
+                    zhuJianYiShi(document1, entry,orderRemark.getCreateTime(),dictHosp);
+                    if (!dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")) {
+                        //鍒嗗壊绾�
+                        LineSeparator objectName = new LineSeparator();
+                        document1.add(objectName);
+                    }
                 }
             }
         }
@@ -579,11 +869,16 @@
      * @param entry
      * @throws DocumentException
      */
-    private void zhuJianYiShi(Document document1, Map.Entry<TjOrderRemark, List<TjPdfVO>> entry) throws DocumentException {
-        if (null != entry.getKey().getDoctorName() && null != userService.getById(entry.getKey().getDoctorName())) {
+    private void zhuJianYiShi(Document document1, Map.Entry<TjOrderRemark, List<TjPdfVO>> entry,Date createTime,DictHosp dictHosp) throws DocumentException {
+        if ((null != entry.getKey().getDoctorName() && null != userService.getById(entry.getKey().getDoctorName())) || dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌") ) {
             //涓绘鍖诲笀
             String key = sysConfigService.selectConfigByKey("is_report_pdf_use_ysqm");
             SysUser sysUser = userService.getById(entry.getKey().getDoctorName());
+            String doctorNameDefault = "鏃�";
+            if (sysUser != null)doctorNameDefault = sysUser.getNickName();
+            if (!entry.getValue().isEmpty() && StrUtil.isNotBlank(entry.getValue().get(0).getShys()) && dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")){
+                doctorNameDefault = entry.getValue().get(0).getShys();
+            }
             Font doctorFonts = PdfUtils.setFont(9);
             if (key.equals("Y")){
                 String qmImg = dictUserInfoMapper.selectQmImgInnerJoinUserByUserId(String.valueOf(sysUser.getUserId()));
@@ -594,7 +889,11 @@
                     elements.setSpacingAfter(10f);
                     elements.setAlignment(Element.ALIGN_RIGHT);
                     Phrase phrase = new Phrase();
-                    phrase.add(new Chunk("涓绘鍖诲笀锛�",doctorFonts));
+                    if (createTime != null) {
+                        phrase.add(new Chunk("妫�鏌ユ椂闂达細"+new SimpleDateFormat("yyyy-MM-dd").format(createTime)+"             涓绘鍖诲笀锛�", doctorFonts));
+                    }else {
+                        phrase.add(new Chunk("涓绘鍖诲笀锛�", doctorFonts));
+                    }
                     byte[] decode = Base64.getDecoder().decode(qmImg);
                     Image image = null;
                     try {
@@ -604,25 +903,29 @@
                         elements.add(phrase);
                         document1.add(elements);
                     } catch (IOException e) {
-                        String doctorName = "涓绘鍖诲笀锛�" + sysUser.getNickName();
+                        String doctorName = "涓绘鍖诲笀锛�" + doctorNameDefault;
+                        if (createTime != null) doctorName = "妫�鏌ユ椂闂达細"+new SimpleDateFormat("yyyy-MM-dd").format(createTime)+"             涓绘鍖诲笀锛�" + doctorNameDefault;
                         Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName);
                         df.setAlignment(Element.ALIGN_RIGHT);
                         document1.add(df);
                     }
                 }else {
-                    String doctorName = "涓绘鍖诲笀锛�" + sysUser.getNickName();
+                    String doctorName = "涓绘鍖诲笀锛�" + doctorNameDefault;
+                    if (createTime != null) doctorName = "妫�鏌ユ椂闂达細"+new SimpleDateFormat("yyyy-MM-dd").format(createTime)+"             涓绘鍖诲笀锛�" + doctorNameDefault;
                     Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName);
                     df.setAlignment(Element.ALIGN_RIGHT);
                     document1.add(df);
                 }
             }else {
-                String doctorName = "涓绘鍖诲笀锛�" + sysUser.getNickName();
+                String doctorName = "涓绘鍖诲笀锛�" + doctorNameDefault;
+                if (createTime != null) doctorName = "妫�鏌ユ椂闂达細"+new SimpleDateFormat("yyyy-MM-dd").format(createTime)+"             涓绘鍖诲笀锛�" + doctorNameDefault;
                 Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName);
                 df.setAlignment(Element.ALIGN_RIGHT);
                 document1.add(df);
             }
         } else {
             String doctorName = "涓绘鍖诲笀锛�" + "鏃�";
+            if (createTime != null) doctorName = "妫�鏌ユ椂闂达細"+new SimpleDateFormat("yyyy-MM-dd").format(createTime)+"             涓绘鍖诲笀锛�" + "鏃�";
             Font doctorFonts = PdfUtils.setFont(9);
             Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName);
             df.setAlignment(Element.ALIGN_RIGHT);
@@ -634,7 +937,6 @@
         LambdaQueryWrapper<LtkjHysqd> ltkjHysqdLambdaQueryWrapper = new LambdaQueryWrapper<>();
         ltkjHysqdLambdaQueryWrapper.eq(LtkjHysqd::getTjh, tjOrder.getCardId());
         List<LtkjHysqd> list = ltkjHysqdService.list(ltkjHysqdLambdaQueryWrapper);
-//        List<LtkjHysqd> list = ltkjHysqdService.list();
         HashMap<String, Object> data = new HashMap<>();
         for (LtkjHysqd hysqd : list) {
             LambdaQueryWrapper<LtkjHybgd> ltkjHybgdLambdaQueryWrapper = new LambdaQueryWrapper<>();
@@ -644,7 +946,9 @@
             String xmmc = hysqd.getXmmc();
             ArrayList<List<String>> lists = new ArrayList<>();
             HashSet<String> hashSet = new HashSet<>();
+            String shsj = "";
             for (LtkjHybgd hybgd : hybgds) {
+                shsj = hybgd.getShsj();
                 // 妫�鏌ラ」鐩�
                 String jcxm = hybgd.getJcxm() != null ? hybgd.getJcxm().trim() : null;
                 // 妫�楠岀粨鏋�
@@ -659,6 +963,8 @@
                 String shysmc = hybgd.getShysmc() != null ? hybgd.getShysmc().trim() : null;
                 // 瀹℃牳鍖诲笀缂栫爜
                 String shys = hybgd.getShys() != null ? hybgd.getShys().trim() : null;
+                String ycbz = "";
+
                 if (jyjg != null && StrUtil.isNotBlank(jyjg) && fwz != null && StrUtil.isNotBlank(fwz)) {
                     try {
                         String[] fwzs = fwz.split("-");
@@ -668,10 +974,12 @@
                         // 姣旇緝妫�楠岀粨鏋滃拰鑼冨洿鍊�
                         if (jyjgval.compareTo(min) < 0) {
                             // jyjg 灏忎簬鑼冨洿鏈�灏忓�硷紝娣诲姞涓嬬澶�
-                            jyjg = jyjg + "   鈫�";
+//                            jyjg = jyjg + "   鈫�";
+                            ycbz = "鈫�";
                         } else if (jyjgval.compareTo(max) > 0) {
                             // jyjg 澶т簬鑼冨洿鏈�澶у�硷紝娣诲姞涓婄澶�
-                            jyjg = jyjg + "   鈫�";
+//                            jyjg = jyjg + "   鈫�";
+                            ycbz = "鈫�";
                         }
                     } catch (Exception ignored) {
                     }
@@ -690,6 +998,7 @@
                 ArrayList<String> strings = new ArrayList<>();
                 strings.add(jcxm);
                 strings.add(jyjg);
+                strings.add(ycbz);
                 strings.add(jgdw);
                 strings.add(fwz);
                 lists.add(strings);
@@ -698,6 +1007,10 @@
                 HashMap<String, Object> map = new HashMap<>();
                 map.put("data", lists);
                 map.put("jyys", hashSet);
+                if (StrUtil.isNotBlank(shsj)){
+                    shsj = shsj.split(" ")[0];
+                }
+                map.put("shsj",shsj);
                 data.put(xmmc, map);
             }
         }
@@ -710,7 +1023,7 @@
      * @param tjOrder
      * @param reportTemplate
      */
-    public HashMap<String, Object> makePDFInfo(TjOrder tjOrder, TjCustomer tjCustomer, TjReportTemplate reportTemplate) {
+    public HashMap<String, Object> makePDFInfo(TjOrder tjOrder, TjCustomer tjCustomer, TjReportTemplate reportTemplate,DictHosp dictHosp,HashMap<String, Object> jianYanMap) {
         String tjNumber = tjOrder.getTjNumber();
         String template = reportTemplate.getTemplate();
         LambdaQueryWrapper<DictComp> wq111 = new LambdaQueryWrapper<>();
@@ -760,30 +1073,70 @@
             }
             //鎷兼帴閲嶅ぇ闃虫�х粨鏋�
             StringBuffer str = new StringBuffer();
-            str.append("銆愰噸澶ч槼鎬ч」鐩�慭n");
-            LambdaQueryWrapper<TjBigPositive> bigPositiveLambdaQueryWrapper = new LambdaQueryWrapper<>();
-            bigPositiveLambdaQueryWrapper.eq(TjBigPositive::getTjNumber, tjNumber);
-            List<TjBigPositive> list1 = tjBigPositiveService.list(bigPositiveLambdaQueryWrapper);
-            if (list1 != null && list1.size() > 0) {
-                for (int i = 0; i < list1.size(); i++) {
-                    str.append((i + 1) + "銆�" + list1.get(i).getProName() + ";\n");
+            if (!dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")) {
+                str.append("銆愰噸澶ч槼鎬ч」鐩�慭n");
+                LambdaQueryWrapper<TjBigPositive> bigPositiveLambdaQueryWrapper = new LambdaQueryWrapper<>();
+                bigPositiveLambdaQueryWrapper.eq(TjBigPositive::getTjNumber, tjNumber);
+                List<TjBigPositive> list1 = tjBigPositiveService.list(bigPositiveLambdaQueryWrapper);
+                if (list1 != null && list1.size() > 0) {
+                    for (int i = 0; i < list1.size(); i++) {
+                        str.append((i + 1) + "銆�" + list1.get(i).getProName() + ";\n");
+                    }
+                } else {
+                    str.append("    鏃狅紱\n");
                 }
-            } else {
-                str.append("    鏃狅紱\n");
             }
             //鎷兼帴寮傚父椤圭洰
             str.append("銆愬紓甯告儏鍐甸」鐩�慭n");
-            if (list.size() > 0) {
-                for (int i = 0; i < list.size(); i++) {
-                    if (list.get(i).getExceptionDesc() == 1) {
-                        str.append((i + 1) + "銆�" + projectService.getById(list.get(i).getProId()).getProName() + ";\n");
+            if (!dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")) {
+                if (list.size() > 0) {
+                    for (int i = 0; i < list.size(); i++) {
+                        if (list.get(i).getExceptionDesc() == 1) {
+                            str.append((i + 1) + "銆�" + projectService.getById(list.get(i).getProId()).getProName() + ";\n");
+                        }
+                    }
+                } else {
+                    str.append("    鏃狅紱\n");
+                }
+            }else {
+                int maxProjectLength = 0;
+                for (Map.Entry<String, Object> item : jianYanMap.entrySet()) {
+                    HashMap<String, Object> entryValue = (HashMap<String, Object>) item.getValue();
+                    ArrayList<List<String>> lists = (ArrayList<List<String>>) entryValue.get("data");
+                    for (List<String> i : lists) {
+                        maxProjectLength = Math.max(maxProjectLength, i.get(0).length());
                     }
                 }
-            } else {
-                str.append("    鏃狅紱\n");
+                int projectWidth = maxProjectLength * 2;
+                int resultWidth = 8;
+                int flagWidth = 8;
+                int unitWidth = 8;
+                int rangeWidth = 15;
+                str.append(padRight("椤圭洰", projectWidth))
+                        .append(padRight("缁撴灉", resultWidth))
+                        .append(padRight("鏍囧織", flagWidth))
+                        .append(padRight("鍗曚綅", unitWidth))
+                        .append(padRight("鍙傝�冭寖鍥�", rangeWidth))
+                        .append("\n");
+                for (Map.Entry<String, Object> item : jianYanMap.entrySet()) {
+                    HashMap<String, Object> entryValue = (HashMap<String, Object>) item.getValue();
+                    ArrayList<List<String>> lists = (ArrayList<List<String>>) entryValue.get("data");
+                    for (List<String> i : lists) {
+                        if (i.contains("鈫�") || i.contains("鈫�")) {
+                            int currentProjectWidth = i.get(0).length() + (maxProjectLength - i.get(0).length()) * 2 + 2;
+                            str.append(padRight(i.get(0), currentProjectWidth));
+                            str.append(padRight(i.get(1), resultWidth));
+                            str.append(padRight(i.get(2), flagWidth));
+                            str.append(padRight(i.get(3), unitWidth));
+                            str.append(padRight(i.get(4), rangeWidth));
+                            str.append("\n");
+                        }
+                    }
+                }
             }
             //寮傚父椤圭洰
             data.put("yichang", str.toString());
+            data.put("zjrq",new SimpleDateFormat("yyyy-MM-dd").format(tjOrder.getCheckTime()));
             // 閬嶅巻data 缁檖df琛ㄥ崟琛ㄦ牸璧嬪��
             for (String key : data.keySet()) {
                 acroFields.setField(key, data.get(key).toString());
@@ -811,11 +1164,20 @@
             map.put("document", document);
             map.put("copy", copy);
             map.put("stream", finalOutPut);
+            map.put("form",pdfStamper);
             return map;
         } catch (IOException | DocumentException e) {
             e.printStackTrace();
             return null;
         }
+    }
+
+    public static String padRight(String str, int length) {
+        StringBuilder sb = new StringBuilder(str);
+        while (sb.length() < length) {
+            sb.append(" ");
+        }
+        return sb.toString();
     }
 
     /**
@@ -854,6 +1216,62 @@
                             tjPdfVO.setCompany(tjProject.getProMetering());
                         } else {
                             tjPdfVO.setCompany("/");
+                        }
+                        tjPdfVO.setProId(String.valueOf(tjOrderDetail.getProject().getProId()));
+                        LambdaQueryWrapper<LtkjExamJcbgd> wrapper = new LambdaQueryWrapper<>();
+                        wrapper.eq(LtkjExamJcbgd::getTjh,tjNumber);
+                        wrapper.eq(LtkjExamJcbgd::getXmdm,String.valueOf(tjOrderDetail.getProject().getProParentId()));
+//                        LtkjExamJcbgd jcbgd = jcbgdService.getOne(wrapper);
+//                        if (jcbgd != null){
+//                            tjPdfVO.setTs(jcbgd.getYxbx());
+//                            tjPdfVO.setSj(jcbgd.getBgNr());
+//                            tjPdfVO.setShys(jcbgd.getShysxm());
+//                        }
+                        tjPdfVOS.add(tjPdfVO);
+                    }
+                }
+            }
+            printReport.put(entry.getKey(), tjPdfVOS);
+        }
+    }
+    private void pacsJianChaData(String tjNumber, Map<TjOrderRemark, List<TjPdfVO>> printReport, TjOrder one, TjCustomer customer) {
+//        LambdaQueryWrapper<TjOrderRemark> wqq = new LambdaQueryWrapper<>();
+//        wqq.eq(TjOrderRemark::getTjNumber, tjNumber);
+//        wqq.ne(TjOrderRemark::getDeptId, "241");
+//        wqq.in(TjOrderRemark::getDeptId, "269", "270", "253", "254", "255", "257");
+//        wqq.notIn(TjOrderRemark::getProId, projectService.getNneedReprotProId());
+//        List<TjOrderRemark> tjOrderRemarks = tjOrderRemarkService.list(wqq);
+        List<TjOrderRemark> tjOrderRemarks = tjOrderRemarkService.pacsJianChaData(tjNumber);
+        for (TjOrderRemark tjOrderRemark : tjOrderRemarks) {
+            printReport.put(tjOrderRemark, null);
+        }
+        for (Map.Entry<TjOrderRemark, List<TjPdfVO>> entry : printReport.entrySet()) {
+            List<TjPdfVO> tjPdfVOS = new ArrayList<>();
+            List<TjOrderDetail> tjOrderDetails = tjOrderDetailService.getDetailByOrderIdAndParId(one.getOrderId(), entry.getKey().getProId());
+            for (TjOrderDetail tjOrderDetail : tjOrderDetails) {
+                TjProject tjProject = projectService.getById(tjOrderDetail.getProId());
+                if (null != tjProject && tjProject.getNeedReport().equals("Y")) {
+                    tjOrderDetail.setProject(tjProject);
+
+                    if (tjOrderDetail.getProject().getProParentId().equals(entry.getKey().getProId())) {
+                        TjPdfVO tjPdfVO = new TjPdfVO();
+                        tjPdfVO.setProName(tjOrderDetail.getProject().getProName());
+                        tjPdfVO.setProResult(tjOrderDetail.getProResult());
+                        tjPdfVO.setExc(tjOrderDetail.getExceptionDesc());
+                        if (null != tjProject.getProMetering()) {
+                            tjPdfVO.setCompany(tjProject.getProMetering());
+                        } else {
+                            tjPdfVO.setCompany("/");
+                        }
+                        tjPdfVO.setProId(String.valueOf(tjOrderDetail.getProject().getProId()));
+                        LambdaQueryWrapper<LtkjExamJcbgd> wrapper = new LambdaQueryWrapper<>();
+                        wrapper.eq(LtkjExamJcbgd::getTjh,tjNumber);
+                        wrapper.eq(LtkjExamJcbgd::getXmdm,String.valueOf(tjOrderDetail.getProject().getProParentId()));
+                        LtkjExamJcbgd jcbgd = jcbgdService.getOne(wrapper);
+                        if (jcbgd != null){
+                            tjPdfVO.setTs(jcbgd.getYxbx());
+                            tjPdfVO.setSj(jcbgd.getBgNr());
+                            tjPdfVO.setShys(jcbgd.getShysxm());
                         }
                         tjPdfVOS.add(tjPdfVO);
                     }
@@ -984,10 +1402,14 @@
         document.add(table);
     }
 
-    private static void addJianYanTable(Document document, String titleName, String[] titles, float[] titlesWidth, ArrayList<List<String>> lists) throws DocumentException {
-        Font titleFont = PdfUtils.setFont(9);
+    private static void addJianYanTable(Document document, String titleName, String[] titles, float[] titlesWidth, ArrayList<List<String>> lists,DictHosp dictHosp,String colorStr) throws DocumentException {
+        // 澶ч」鏍囬
+        Font titleFont = PdfUtils.setFont(10);
+        if (dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")) {
+            titleFont.setSize(11);
+            titleFont.setStyle(Font.BOLD);
+        }
         Paragraph paragraph = new Paragraph(titleName, titleFont);
-        // 璁剧疆鏂囧瓧灞呬腑
         paragraph.setAlignment(Element.ALIGN_LEFT);
         // 琛岄棿璺�
         paragraph.setLeading(5f);
@@ -995,13 +1417,34 @@
         paragraph.setSpacingBefore(10f);
         // 璁剧疆娈佃惤涓嬬┖鐧�
         paragraph.setSpacingAfter(10f);
-        document.add(paragraph);
+        if (dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")) {
+            // 琛岄棿璺�
+            paragraph.setLeading(7f);
+            // 璁剧疆娈佃惤涓婄┖鐧�
+            paragraph.setSpacingBefore(12f);
+            // 璁剧疆娈佃惤涓嬬┖鐧�
+            paragraph.setSpacingAfter(12f);
+            // 澶ч」
+            PdfPCell cellTitle = new PdfPCell(paragraph);
+            cellTitle.setBorder(Rectangle.NO_BORDER);
+            Color color = Color.decode(colorStr);
+            cellTitle.setBackgroundColor(new BaseColor(color.getRed(), color.getGreen(), color.getBlue())); // 璁剧疆鑳屾櫙棰滆壊锛堝崄鍏繘鍒� RGB锛�
+            // 鍒涘缓琛ㄦ牸骞舵坊鍔犲崟鍏冩牸
+            PdfPTable tableTitle = new PdfPTable(1);
+            tableTitle.setWidthPercentage(100);
+            tableTitle.addCell(cellTitle);
+
+            // 灏嗚〃鏍兼坊鍔犲埌鏂囨。涓�
+            document.add(tableTitle);
+        }else {
+            document.add(paragraph);
+        }
         // 鍒涘缓涓�涓〃鏍煎苟娣诲姞鍒版枃妗�
-        Font headFont = PdfUtils.setFont(9);
-        Font textFont = PdfUtils.setFont(9);
+        Font headFont = PdfUtils.setFont(10);
+        Font textFont = PdfUtils.setFont(10);
         PdfPTable table = new PdfPTable(titlesWidth);
-        table.setTotalWidth(PageSize.A4.getWidth() - 100); // 璁剧疆琛ㄦ牸鎬诲搴�
-        table.setLockedWidth(true); // 閿佸畾琛ㄦ牸瀹藉害
+        table.setTotalWidth(PageSize.A4.getWidth() - 10); // 璁剧疆琛ㄦ牸鎬诲搴�
+        //table.setLockedWidth(true); // 閿佸畾琛ㄦ牸瀹藉害
         table.setHorizontalAlignment(Element.ALIGN_LEFT);
         table.getDefaultCell().setBorder(0);
         table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
@@ -1010,15 +1453,36 @@
             cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
             cell.setHorizontalAlignment(Element.ALIGN_LEFT);
             cell.setBorder(Rectangle.NO_BORDER); // 绉婚櫎鍗曞厓鏍艰竟妗�
+
+//            Color color = Color.decode(colorStr);
+//            cell.setBackgroundColor(new BaseColor(color.getRed(), color.getGreen(), color.getBlue())); // 璁剧疆鑳屾櫙棰滆壊锛堝崄鍏繘鍒� RGB锛�
+
             table.addCell(cell);
         }
+
         for (List<String> list : lists) {
+            boolean isYc = false;
+            textFont = PdfUtils.setFont(10);
+            if (dictHosp.getHospName().equals("婢勫悎鐭垮姟灞�涓績鍖婚櫌")){
+                if (list.contains("鈫�") || list.contains("鈫�")){
+                    isYc = true;
+                }
+            }
             for (String s : list) {
                 PdfPCell nameCell = new PdfPCell();
                 nameCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                 nameCell.setHorizontalAlignment(Element.ALIGN_LEFT);
-                nameCell.setPhrase(new Paragraph(s, textFont));
+
                 nameCell.setBorder(Rectangle.NO_BORDER); // 绉婚櫎鍗曞厓鏍艰竟妗�
+                if (isYc){
+                    textFont.setStyle(Font.BOLD);
+                    nameCell.setPhrase(new Paragraph(s, textFont));
+                    nameCell.setBorder(Rectangle.NO_BORDER);
+//                    Color color = Color.decode("#0033cc");
+//                    nameCell.setBackgroundColor(new BaseColor(color.getRed(), color.getGreen(), color.getBlue())); // 璁剧疆鑳屾櫙棰滆壊锛堝崄鍏繘鍒� RGB锛�
+                }else {
+                    nameCell.setPhrase(new Paragraph(s, textFont));
+                }
                 table.addCell(nameCell);
             }
         }
@@ -1349,4 +1813,129 @@
             footer.writeSelectedRows(0, -1, 36, 50, writer.getDirectContent());
         }
     }
+
+    // 鑷畾涔夐〉鑴氬拰椤电湁鐨勭粯鍒�
+    static class FooterHeaderPageEvent extends PdfPageEventHelper {
+
+        private String name; // 椤电湁鐨勫悕瀛�
+        private String tjName;
+        private String tjNumber;
+        private String sex;
+        private String age;
+
+        public FooterHeaderPageEvent(String name,String tjName,String tjNumber,String sex,String age) {
+            this.name = name;
+            this.tjNumber = tjNumber;
+            this.tjName = tjName;
+            this.sex = sex;
+            this.age = age;
+        }
+
+        // 鍦ㄦ瘡涓�椤电殑椤堕儴缁樺埗椤电湁
+        @Override
+        public void onStartPage(PdfWriter writer, Document document) {
+            // 鑾峰彇椤甸潰瀹藉害鍜岄珮搴�
+            float width = document.getPageSize().getWidth();
+            float margin = document.leftMargin();
+
+            // 鍒涘缓椤电湁琛ㄦ牸锛�2琛岋紝绗竴琛屽寘鍚鍚嶃�佹�у埆銆佸勾榫勫拰浣撴鍙凤紝绗簩琛屾槸鍒嗗壊绾�
+            PdfPTable headerTable = new PdfPTable(2);  // 2鍒楋細绗竴鍒椾负濮撳悕銆佹�у埆銆佸勾榫勶紝绗簩鍒椾负浣撴鍙�
+            headerTable.setWidthPercentage(100); // 璁剧疆瀹藉害涓�100%
+            headerTable.setSpacingAfter(10); // 椤电湁涓庡唴瀹逛箣闂寸殑闂磋窛
+
+            // 璁剧疆鍒楀搴�
+            float[] columnWidths = {0.6f, 0.4f}; // 绗竴鍒楀崰 60%锛岀浜屽垪鍗� 40%
+            try {
+                headerTable.setWidths(columnWidths);
+            } catch (DocumentException e) {
+                e.printStackTrace();
+            }
+
+            // 绗竴琛岋細濮撳悕銆佹�у埆銆佸勾榫勪互鍙婁綋妫�鍙�
+            PdfPCell infoCell = new PdfPCell(new Phrase("濮撳悕锛�" + tjName + " 鎬у埆锛�" + sex + " 骞撮緞锛�" + age, PdfUtils.setFont(8)));
+            infoCell.setBorder(Rectangle.NO_BORDER);
+            infoCell.setHorizontalAlignment(Element.ALIGN_LEFT); // 绗竴鍒楀乏瀵归綈
+            infoCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 鍨傜洿灞呬腑
+            headerTable.addCell(infoCell);
+
+            PdfPCell idCell = new PdfPCell(new Phrase("浣撴鍙凤細" + tjNumber, PdfUtils.setFont(8)));
+            idCell.setBorder(Rectangle.NO_BORDER);
+            idCell.setHorizontalAlignment(Element.ALIGN_RIGHT); // 绗簩鍒楀彸瀵归綈
+            idCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 鍨傜洿灞呬腑
+            headerTable.addCell(idCell);
+
+            // 绗簩琛岋細娣$伆鑹插垎鍓茬嚎
+            PdfPCell separatorCell = new PdfPCell();
+            separatorCell.setBorder(Rectangle.TOP);  // 璁剧疆涓婅竟妗�
+            separatorCell.setBorderColor(BaseColor.LIGHT_GRAY); // 璁剧疆涓烘贰鐏拌壊
+            separatorCell.setBorderWidthTop(0.5f); // 璁剧疆涓婅竟妗嗙殑瀹藉害
+            separatorCell.setColspan(2); // 鍚堝苟涓ゅ垪
+            headerTable.addCell(separatorCell);
+
+            // 灏嗛〉鐪夎〃鏍兼坊鍔犲埌鏂囨。
+            try {
+                document.add(headerTable);
+            } catch (DocumentException e) {
+                e.printStackTrace();
+            }
+        }
+
+
+        // 鍦ㄦ瘡涓�椤电殑搴曢儴缁樺埗椤佃剼
+        @SneakyThrows
+        @Override
+        public void onEndPage(PdfWriter writer, Document document) {
+            // 鑾峰彇椤甸潰瀹藉害鍜岄珮搴�
+            float width = document.getPageSize().getWidth();
+            float height = document.getPageSize().getHeight();
+            float margin = document.leftMargin();
+
+            // 椤佃剼璺濈搴曢儴鐨勪綅缃紝纭繚鍏朵綅浜庨〉闈㈠簳閮� 澧炲姞鏄笂绉� 鍑忓皯鏄笅绉�
+            float footerPositionY = document.bottomMargin();
+
+            // 椤佃剼琛ㄦ牸锛�2琛�2鍒楋紝绗竴琛屽尰闄㈠悕鍜岄〉鐮侊紝绗簩琛岀绂忚
+            PdfPTable footerTable = new PdfPTable(2); // 2鍒楋紝绗竴鍒楀尰闄㈠悕锛岀浜屽垪椤电爜
+            footerTable.setWidthPercentage(100); // 璁剧疆瀹藉害涓�100%锛屼娇鍏舵按骞冲眳涓�
+            footerTable.setTotalWidth(width - margin * 2 + 10); // 璁剧疆鎬诲搴︼紝閬垮厤涓庨〉杈硅窛閲嶅彔
+            footerTable.setSpacingBefore(0); // 鍘婚櫎琛ㄦ牸椤堕儴鐨勯棿璺�
+            footerTable.setSpacingAfter(0); // 鍘婚櫎琛ㄦ牸搴曢儴鐨勯棿璺�
+            footerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); // 鍘婚櫎鎵�鏈夊崟鍏冩牸鐨勮竟妗�
+            float[] columnWidths = { 2.5f, 2f };  // 绗竴鍒楀崰 1锛岀浜屽垪鍗� 2
+            footerTable.setWidths(columnWidths); // 璁剧疆鍒楀姣斾緥
+
+            // 绗竴琛岋細鍖婚櫌鍚嶅拰椤电爜
+            PdfPCell hospitalNameCell = new PdfPCell(new Phrase(name, PdfUtils.setFont(8)));
+            hospitalNameCell.setHorizontalAlignment(Element.ALIGN_RIGHT); // 姘村钩灞呬腑
+            hospitalNameCell.setVerticalAlignment(Element.ALIGN_TOP); // 鍨傜洿瀵归綈鍒板簳閮�
+            hospitalNameCell.setMinimumHeight(12f); // 璁剧疆鏈�灏忛珮搴︼紝閬垮厤楂樺害杩囧ぇ
+            hospitalNameCell.setBorder(Rectangle.TOP); // 璁剧疆涓婅竟妗�
+            hospitalNameCell.setBorderColor(BaseColor.LIGHT_GRAY); // 璁剧疆涓婅竟妗嗕负娣$伆鑹�
+            hospitalNameCell.setBorderWidthTop(0.5f); // 璁剧疆涓婅竟妗嗗搴�
+            footerTable.addCell(hospitalNameCell);
+
+            // 鍒涘缓椤电爜鐨勫崟鍏冩牸锛氬彸瀵归綈
+//            String pageText = "绗� " + writer.getPageNumber() + 1 + " 椤碉紝鍏� " + writer.getPageNumber() + " 椤�"; // 椤电爜
+            String pageText = "绗� " + (writer.getPageNumber() + 1) + " 椤�"; // 椤电爜
+            PdfPCell pageCell = new PdfPCell(new Phrase(pageText, PdfUtils.setFont(8)));
+            pageCell.setHorizontalAlignment(Element.ALIGN_RIGHT); // 鍙冲榻�
+            pageCell.setVerticalAlignment(Element.ALIGN_TOP); // 鍨傜洿瀵归綈鍒板簳閮�
+            pageCell.setMinimumHeight(12f); // 璁剧疆鏈�灏忛珮搴︼紝閬垮厤楂樺害杩囧ぇ
+            pageCell.setBorder(Rectangle.TOP); // 璁剧疆涓婅竟妗�
+            pageCell.setBorderColor(BaseColor.LIGHT_GRAY); // 璁剧疆涓婅竟妗嗕负娣$伆鑹�
+            pageCell.setBorderWidthTop(0.5f); // 璁剧疆涓婅竟妗嗗搴�
+            footerTable.addCell(pageCell);
+
+            // 绗簩琛岋細绁濈璇紝鍚堝苟涓ゅ垪
+            PdfPCell footerTextCell = new PdfPCell(new Phrase("鏈綋妫�鎶ュ憡浠呬緵涓村簥鍙傝�冿紝涓嶄綔涓轰复搴婁緷鎹紝绁濇偍韬綋鍋ュ悍锛侊紒锛�", PdfUtils.setFont(8)));
+            footerTextCell.setColspan(2); // 鍚堝苟涓ゅ垪
+            footerTextCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 灞呬腑
+            footerTextCell.setVerticalAlignment(Element.ALIGN_TOP); // 鍨傜洿瀵归綈鍒板簳閮�
+            footerTextCell.setMinimumHeight(14f); // 璁剧疆鏈�灏忛珮搴︼紝閬垮厤楂樺害杩囧ぇ
+            footerTextCell.setBorder(Rectangle.NO_BORDER); // 鍘婚櫎鎵�鏈夎竟妗�
+            footerTable.addCell(footerTextCell);
+
+            // 椤佃剼琛ㄦ牸鐨勪綅缃細灏嗚〃鏍煎啓鍏ラ〉鑴氾紝Y 鍧愭爣闇�瑕佽缃负璺濈椤甸潰搴曢儴鎸囧畾鐨勪綅缃�
+            footerTable.writeSelectedRows(0, -1, margin, footerPositionY, writer.getDirectContent());
+        }
+    }
 }

--
Gitblit v1.8.0