From 16385eb95623e47d1886872e6e4df0bda28c2187 Mon Sep 17 00:00:00 2001
From: zhaowenxuan <chacca165@163.com>
Date: 星期五, 19 七月 2024 18:15:38 +0800
Subject: [PATCH] 增加异常捕获 化验表格增加医师签名

---
 ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisPDFUtil.java |  656 ++++++++---------------------------------------------------
 1 files changed, 90 insertions(+), 566 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 4d867ee..98de276 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
@@ -6,20 +6,18 @@
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 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.SysUser;
 import com.ltkj.common.utils.DateUtils;
-import com.ltkj.common.utils.StringUtils;
 import com.ltkj.framework.config.MatchUtils;
 import com.ltkj.hosp.domain.*;
+import com.ltkj.hosp.mapper.DictUserInfoMapper;
 import com.ltkj.hosp.service.*;
 import com.ltkj.hosp.sqlDomain.LtkjHybgd;
 import com.ltkj.hosp.sqlDomain.LtkjHysqd;
-import com.ltkj.mall.mallOrderUtils.TjConstants;
+import com.ltkj.system.service.ISysConfigService;
 import com.ltkj.system.service.ISysUserService;
 import com.ltkj.web.config.pdfutils.PdfUtils;
 import lombok.extern.slf4j.Slf4j;
@@ -34,8 +32,6 @@
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.List;
-
-import static com.ltkj.web.config.pdfutils.PDFBinaryUtil.getPDFBinary;
 
 /**
  * 妫�鏌� 妫�楠屾姤鍛妏df鐢熸垚
@@ -71,82 +67,18 @@
     private LtkjHysqdService ltkjHysqdService;
     @Autowired
     private LtkjGetexamreportinfoService ltkjGetexamreportinfoService;
-    @Value ("${path.filePath}")
+    @Value("${path.filePath}")
     private String value;
-    @Value ("${path.reportServer}")
+    @Value("${path.reportServer}")
     private String urlValue;
+    @Autowired
+    private DictUserInfoMapper dictUserInfoMapper;
+    @Autowired
+    private ISysConfigService sysConfigService;
 
 //    private static final
-
-    /**
-     * 閫氳繃his API璇锋眰鑾峰彇鏁版嵁鐢熸垚PDF
-     *
-     * @param pdfInfoMap
-     * @param params
-     * @param tjOrder
-     * @param tjReportTemplate
-     * @return
-     * @deprecated 鏈夋暟鎹悓姝ヤ笉鍦ㄨ皟鐢ㄦ帴鍙h幏鍙栨暟鎹洿鎺ユ煡鏁版嵁搴撴嬁鏁版嵁鐢熸垚
-     */
-    @Deprecated
-    public AjaxResult execHisRequest(HashMap<String, Object> pdfInfoMap, Map<String, Object> params, TjOrder tjOrder, TjReportTemplate tjReportTemplate) {
-        List<Map<String, Object>> list;
-        String hisRegistrationId = params.get("his_registration_id").toString();
-        AjaxResult getlabreportinfo = apiGetMethodService.getHISDataNew("Getlabreportinfo", params);
-        list = makePDFInfo(pdfInfoMap, getlabreportinfo, "鑾峰彇妫�楠屾姤鍛婅褰曚俊鎭�");
-        JSONArray jsonArray = JSONUtil.createArray();
-        if (list != null) {
-            params.clear();
-            for (Map<String, Object> stringObjectMap : list) {
-                if (stringObjectMap == null)
-                    continue;
-                JSONObject obj = JSONUtil.createObj();
-                obj.putOpt("鎶ュ憡璁板綍", stringObjectMap);
-                String jybgid = stringObjectMap.get("JYBGID").toString();
-                params.put("jybgid", jybgid);
-                // 鑾峰彇妫�楠岀粨鏋滆褰曚俊鎭�
-                AjaxResult getlabdetailinfo = apiGetMethodService.getHISDataNew("Getlabdetailinfo", params);
-                putData(obj, getlabdetailinfo, "妫�楠岀粨鏋滆褰�");
-                // 鑾峰彇寰敓鐗╂姤鍛婅褰曚俊鎭�
-                AjaxResult getlabgermrepinfo = apiGetMethodService.getHISDataNew("Getlabgermrepinfo", params);
-                putData(obj, getlabgermrepinfo, "寰敓鐗╂姤鍛婅褰�");
-                // 鑾峰彇寰敓鐗╄嵂鏁忎俊鎭�
-                AjaxResult getlabgermdetailinfo = apiGetMethodService.getHISDataNew("Getlabgermdetailinfo", params);
-                putData(obj, getlabgermdetailinfo, "寰敓鐗╄嵂鏁忎俊鎭�");
-                // 鑾峰彇鍗辨�ュ�间俊鎭�
-                AjaxResult getlaburgentinfo = apiGetMethodService.getHISDataNew("Getlaburgentinfo", params);
-                putData(obj, getlaburgentinfo, "鍗辨満鍊间俊鎭�");
-                jsonArray.put(obj);
-            }
-            // 鑾峰彇妫�鏌ユ姤鍛婁俊鎭�
-            params.clear();
-            params.put("his_registration_id", hisRegistrationId);
-            params.put("ksmc", "");
-            params.put("pationid", "");
-            params.put("ksrq", "");
-            params.put("jsrq", "");
-            params.put("pagecount", 100);
-            params.put("page", 1);
-            params.put("status", "");
-            AjaxResult getexamreportinfo = apiGetMethodService.getHISDataNew("Getexamreportinfo", params);
-            JSONObject object = JSONUtil.parseObj(getexamreportinfo.get("result"));
-            JSONObject response = JSONUtil.parseObj(object.get("Response"));
-            if (!response.getStr("ResultCode").equals("0")) {
-                if (!response.getStr("ResultContent").contains("鏌ヨ澶辫触"))
-                    return AjaxResult.error("鐢熸垚瓒呮椂锛岃閲嶈瘯");
-            }
-            JSONObject obj = JSONUtil.createObj();
-            putData(obj, getexamreportinfo, "妫�鏌ユ姤鍛�");
-            jsonArray.put(obj);
-//            System.out.println(JSONUtil.toJsonStr(jsonArray));
-            if (makePDF(hisRegistrationId, jsonArray, tjOrder, tjReportTemplate)) {
-                log.info("宸茬敓鎴愭姤鍛�");
-                return AjaxResult.success("宸茬敓鎴愭姤鍛婏紒鍙洿鎺ョ偣鍑婚瑙堬紒");
-            } else return AjaxResult.error();
-        } else {
-            return AjaxResult.error("鏈幏鍙栧埌妫�楠屾姤鍛婅褰曚俊鎭�");
-        }
-    }
+    // TODO PDF鎵�鏈夊尰甯堝悕瀛楁樉绀� 鏍规嵁閰嶇疆is_report_pdf_use_ysqm鍐冲畾鏄惁浣跨敤绛惧悕鍥剧墖
+    // TODO 鏈夌鍚嶅浘鐗囧垯浣跨敤绛惧悕鍥剧墖 娌℃湁鍒欎娇鐢ㄦ枃瀛楁樉绀�
 
     private List<Map<String, Object>> makePDFInfo(HashMap<String, Object> map, AjaxResult ajaxResult, String key) {
         List<Map<String, Object>> data = null;
@@ -169,8 +101,10 @@
         }
     }
 
-    public AjaxResult hisPDF(TjOrder tjOrder, TjCustomer customer, TjReportTemplate tjReportTemplate) throws DocumentException {
+    public AjaxResult hisPDF(TjOrder tjOrder, TjCustomer customer, TjReportTemplate tjReportTemplate) throws Exception {
         HashMap<String, Object> pdfChangGui = makePDFInfo(tjOrder, customer, tjReportTemplate);
+        if (pdfChangGui == null)
+            return AjaxResult.error();
         Document document = (Document) pdfChangGui.get("document");
         PdfCopy copy = (PdfCopy) pdfChangGui.get("copy");
         ByteArrayOutputStream finalOutPut = (ByteArrayOutputStream) pdfChangGui.get("stream");
@@ -238,10 +172,10 @@
             for (int i = 2; i <= pages; i++) {
                 contentByte = pdfStamper.getOverContent(i);
                 contentByte.beginText();
-                contentByte.setFontAndSize(baseFont,11);
+                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.showTextAligned(PdfContentByte.ALIGN_CENTER, String.valueOf(i - 1), x, y, 0);
                 contentByte.endText();
             }
             pdfStamper.close();
@@ -249,27 +183,9 @@
             finalOutPut = outputStream;
         } catch (IOException e) {
             e.printStackTrace();
+            return AjaxResult.error();
         }
         savePDFFile(outputFileName1, tjOrder, customer, finalOutPut);
-        TjReport tjReport = new TjReport();
-        String tjNumber = tjOrder.getTjNumber();
-        tjReport.setTjNumber(String.valueOf(tjNumber));
-        tjReport.setPath(urlValue + outputFileName1);
-        // 鏂囦欢閰嶇疆
-//        String outputPath1 = "/Users/chacca/寮�鍙戠浉鍏�/浠g爜/";
-        String outputPath1 = value + "\\";
-        String pdfBinary = getPDFBinary(outputPath1 + outputFileName1);
-        tjReport.setReport(pdfBinary);
-        tjReport.setType("浣撴鎶ュ憡");
-        tjReport.setPrint("pdf");
-        tjReportService.save(tjReport);
-        LambdaUpdateWrapper<TjOrder> updateWrapper = new LambdaUpdateWrapper<>();
-        updateWrapper.eq(TjOrder::getTjNumber, tjNumber);
-        updateWrapper.set(TjOrder::getReportTime, new Date());
-        updateWrapper.set(TjOrder::getPrintLastTime, new Date());
-        updateWrapper.set(TjOrder::getDownloadLastTime, new Date());
-        updateWrapper.set(TjOrder::getStatus, TjConstants.TJ_END);
-        tjOrderService.update(updateWrapper);
         return AjaxResult.success();
     }
 
@@ -279,7 +195,7 @@
      * @param tjOrder
      * @return
      */
-    private List<ByteArrayOutputStream> makeHisJianChaTable(TjOrder tjOrder) {
+    private List<ByteArrayOutputStream> makeHisJianChaTable(TjOrder tjOrder) throws Exception {
         LambdaQueryWrapper<LtkjGetexamreportinfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
         lambdaQueryWrapper.eq(LtkjGetexamreportinfo::getRequestParamsHisRegistrationId, tjOrder.getCardId());
         lambdaQueryWrapper.groupBy(LtkjGetexamreportinfo::getJcbgid);
@@ -309,6 +225,8 @@
             String ch = "";
             String footer = "鐢宠浜猴細" + sqrxm + "     瀹℃牳鍖诲笀锛�" + shysqm + "     鍖诲笀绛惧悕锛�" + bgysqm;
             ByteArrayOutputStream outputStream = makeJcPDFByteArrayStream(xm, xb, nl, jcks, zyh, ch, sjks, jcsb, jch, jcxm, ms, ts, null, footer);
+            if (outputStream == null)
+                throw new Exception();
             jianchas.add(outputStream);
         }
         return jianchas;
@@ -321,22 +239,17 @@
      * @param customer
      * @param finalOutPut
      */
-    private void savePDFFile(String outputFileName1, TjOrder tjOrder, TjCustomer customer, ByteArrayOutputStream finalOutPut) {
+    private void savePDFFile(String outputFileName1, TjOrder tjOrder, TjCustomer customer, ByteArrayOutputStream finalOutPut) throws IOException {
         // 鏂囦欢閰嶇疆
 //        String outputPath1 = "/Users/chacca/寮�鍙戠浉鍏�/浠g爜/";
         String outputPath1 = value + "\\";
         File file = new File(outputPath1 + outputFileName1);
         BufferedOutputStream outputStream = null;
-        try {
-            outputStream = new BufferedOutputStream(new FileOutputStream(file));
-            outputStream.write(finalOutPut.toByteArray());
-            outputStream.flush();
-            outputStream.close();
-            finalOutPut.close();
-        } catch (IOException e) {
-            log.error("鏈湴瀛樺偍pdf寮傚父");
-            e.printStackTrace();
-        }
+        outputStream = new BufferedOutputStream(new FileOutputStream(file));
+        outputStream.write(finalOutPut.toByteArray());
+        outputStream.flush();
+        outputStream.close();
+        finalOutPut.close();
     }
 
     /**
@@ -346,7 +259,7 @@
      * @param map
      * @throws DocumentException
      */
-    private static void makeHisJianYanTable(Document document1, HashMap<String, Object> map) throws DocumentException {
+    private void makeHisJianYanTable(Document document1, HashMap<String, Object> map) throws DocumentException, IOException {
         if (!map.isEmpty()) {
             String[] titles = new String[]{"浣撴椤圭洰", "浣撴缁撴灉", "鍗曚綅", "鍙傝�冭寖鍥�"};
             float[] titlesWidth = new float[]{120, 120, 120, 120};
@@ -356,17 +269,48 @@
                 HashSet<String> jyys = (HashSet<String>) entryValue.get("jyys");
                 ArrayList<List<String>> lists = (ArrayList<List<String>>) entryValue.get("data");
                 addJianYanTable(document1, titleName, titles, titlesWidth, lists);
-                Font doctorFonts = PdfUtils.setFont(9);
-                String doctors = "";
-                for (String s : jyys) {
-                    doctors += s.trim() + "銆�";
+                if (!jyys.isEmpty()) {
+                    Font doctorFonts = PdfUtils.setFont(9);
+                    String doctors = "";
+                    Paragraph elements = new Paragraph();
+                    elements.setLeading(5f);
+                    elements.setSpacingBefore(10f);
+                    elements.setSpacingAfter(10f);
+                    elements.setAlignment(Element.ALIGN_RIGHT);
+                    Phrase phrase = new Phrase();
+                    phrase.add(new Chunk("瀹℃牳鍖诲笀锛�",doctorFonts));
+                    boolean flag = false;
+                    for (String s : jyys) {
+                        if (s.contains("|")) {
+                            flag = true;
+                            String[] split = s.split("\\|");
+                            String qmImg = dictUserInfoMapper.selectQmImgInnerJoinUserByHisDictCode(split[1]);
+                            if (null != qmImg && StrUtil.isNotBlank(qmImg)) {
+                                ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(Base64.getDecoder().decode(qmImg));
+                                byte[] decode = Base64.getDecoder().decode(qmImg);
+                                Image image = Image.getInstance(decode);
+                                image.scaleToFit(60, 25);
+                                phrase.add(new Chunk(image,0,-10,true));
+                            } else {
+                                phrase.add(new Chunk(split[0].trim(),doctorFonts));
+                            }
+                        } else {
+                            doctors += s.trim() + "銆�";
+                        }
+                    }
+                    if (!flag) {
+                        String substring = doctors.substring(0, doctors.length() - 1).trim();
+                        Paragraph df = PdfUtils.setParagraph(doctorFonts, "瀹℃牳鍖诲笀锛�" + substring);
+                        df.setAlignment(Element.ALIGN_RIGHT);
+                        document1.add(df);
+                    } else {
+                        elements.add(phrase);
+                        document1.add(elements);
+                    }
                 }
-                String substring = doctors.substring(0, doctors.length() - 1).trim();
-                Paragraph df = PdfUtils.setParagraph(doctorFonts, "妫�楠屽尰甯堬細" + substring);
-                df.setAlignment(Element.ALIGN_RIGHT);
-                document1.add(df);
                 //鍒嗗壊绾�
                 LineSeparator objectName = new LineSeparator();
+                objectName.setOffset(-5);
                 document1.add(objectName);
             }
         }
@@ -529,17 +473,19 @@
             HashSet<String> hashSet = new HashSet<>();
             for (LtkjHybgd hybgd : hybgds) {
                 // 妫�鏌ラ」鐩�
-                String jcxm = hybgd.getJcxm();
+                String jcxm = hybgd.getJcxm() != null ? hybgd.getJcxm().trim() : null;
                 // 妫�楠岀粨鏋�
-                String jyjg = hybgd.getJyjg();
+                String jyjg = hybgd.getJyjg() != null ? hybgd.getJyjg().trim() : null;
                 // 缁撴灉鍗曚綅
-                String jgdw = hybgd.getJgdw();
+                String jgdw = hybgd.getJgdw() != null ? hybgd.getJgdw().trim() : null;
                 // 鑼冨洿鍊�
-                String fwz = hybgd.getFwz();
+                String fwz = hybgd.getFwz() != null ? hybgd.getFwz().trim() : null;
                 // 妫�楠屽尰甯�
 //                String jyys = hybgd.getJyys();
                 //瀹℃牳鍖荤敓
-                String shysmc = hybgd.getShysmc();
+                String shysmc = hybgd.getShysmc() != null ? hybgd.getShysmc().trim() : null;
+                // 瀹℃牳鍖诲笀缂栫爜
+                String shys = hybgd.getShys() != null ? hybgd.getShys().trim() : null;
                 if (jyjg != null && StrUtil.isNotBlank(jyjg) && fwz != null && StrUtil.isNotBlank(fwz)) {
                     try {
                         String[] fwzs = fwz.split("-");
@@ -562,7 +508,12 @@
 //                List<SysUser> sysUsers = userService.list(queryWrapper);
 //                if (!sysUsers.isEmpty())
 //                    hashSet.add(sysUsers.get(0).getNickName());
-                if (null != shysmc) hashSet.add(shysmc);
+                String key = sysConfigService.selectConfigByKey("is_report_pdf_use_ysqm");
+                if (null != shys && null != shysmc && key.equals("Y")) {
+                    hashSet.add(shysmc + "|" + shys);
+                } else {
+                    if (null != shysmc) hashSet.add(shysmc);
+                }
                 ArrayList<String> strings = new ArrayList<>();
                 strings.add(jcxm);
                 strings.add(jyjg);
@@ -694,433 +645,6 @@
         }
     }
 
-    public Boolean makePDF(String cardId, JSONArray jsonArray, TjOrder tjOrder, TjReportTemplate reportTemplate) {
-        String tjNumber = tjOrder.getTjNumber();
-        String template = reportTemplate.getTemplate();
-        LambdaQueryWrapper<TjCustomer> wq1 = new LambdaQueryWrapper<>();
-        wq1.eq(TjCustomer::getCusId, tjOrder.getUserId());
-        TjCustomer tjCustomer = tjCustomerService.getOne(wq1);
-        Long userId = tjCustomer.getCusId();
-        LambdaQueryWrapper<DictComp> wq111 = new LambdaQueryWrapper<>();
-        wq111.eq(DictComp::getDrugManufacturerId, tjOrder.getFirmId());
-        DictComp dictComp = dictCompService.getOne(wq111);
-        LambdaQueryWrapper<TjOrderDetail> wq2 = new LambdaQueryWrapper<>();
-        wq2.eq(TjOrderDetail::getOrderId, tjOrder.getOrderId());
-        //20230306鍒ゆ柇璇ラ」鐩槸鍚﹂��璐�/缂磋垂
-        wq2.isNotNull(TjOrderDetail::getFlowingWaterId);
-        //20230323鍒ゆ柇璇ラ」鐩槸鍚﹀純妫�/鏈
-//                wq2.eq(TjOrderDetail::getTjStatus,1);
-        List<TjOrderDetail> list = tjOrderDetailService.list(wq2);
-        for (TjOrderDetail tjOrderDetail : list) {
-            TjProject tjProject = projectService.selectTjProjectByProId(tjOrderDetail.getProId());
-            tjOrderDetail.setProject(tjProject);
-        }
-        // 鐢熸垚pdf
-        try {
-            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-            PdfReader reader = new PdfReader(new ByteArrayInputStream(Base64.getDecoder().decode(template)));
-            PdfStamper pdfStamper = new PdfStamper(reader, byteArrayOutputStream);
-            // 鑾峰彇pdf琛ㄥ崟
-            AcroFields acroFields = pdfStamper.getAcroFields();
-            BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
-            acroFields.addSubstitutionFont(bf);
-            HashMap<String, Object> data = new HashMap<>();
-            // 璁剧疆鐢ㄦ埛淇℃伅
-            setUserInfo(tjNumber, tjOrder, tjCustomer, data);
-            //寮傚父椤圭洰
-            if (dictComp == null) {
-                data.put("work", "鏃�");
-            } else {
-                data.put("work", dictComp.getCnName());
-            }
-            //灏侀潰椤典笅闈㈢殑鎬绘寤鸿鏄剧ず
-            if (tjOrder.getCheckAdvice() == null) {
-                data.put("remark", "鏃�");
-            } else {
-                data.put("remark", tjOrder.getCheckAdvice());
-            }
-            //灏侀潰椤典笅闈㈢殑鎬绘寤鸿鏄剧ず
-            if (tjOrder.getCheckDoctor() == null) {
-                data.put("docname", "鏃�");
-            } else {
-                data.put("docname", tjOrder.getCheckDoctor());
-            }
-            //鎷兼帴閲嶅ぇ闃虫�х粨鏋�
-            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");
-                }
-            } 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");
-                    }
-                }
-            } else {
-                str.append("    鏃狅紱\n");
-            }
-
-            //寮傚父椤圭洰
-            data.put("yichang", str.toString());
-            // 閬嶅巻data 缁檖df琛ㄥ崟琛ㄦ牸璧嬪��
-            for (String key : data.keySet()) {
-                acroFields.setField(key, data.get(key).toString());
-            }
-            //璁剧疆涓烘棤娉曠紪杈�
-            pdfStamper.setFormFlattening(true);
-            pdfStamper.close();
-            reader.close();
-            // 灏嗕慨鏀瑰悗鐨凱DF鍐呭鍐欏叆
-            byte[] bytes = byteArrayOutputStream.toByteArray();
-            // 鍒涘缓鏂扮殑PDF鏂囨。
-            Document document = new Document(PageSize.A4);
-            ByteArrayOutputStream finalOutPut = new ByteArrayOutputStream();
-            PdfCopy copy = new PdfCopy(document, finalOutPut);
-            document.open();
-            reader = new PdfReader(bytes);
-            int numberOfPages = reader.getNumberOfPages();
-            for (int i = 1; i <= numberOfPages; i++) {
-                PdfImportedPage page = copy.getImportedPage(reader, i);
-                copy.addPage(page);
-            }
-            // 娣诲姞璇︽儏椤�
-            document.newPage();
-            ByteArrayOutputStream byteArrayOutputStream1 = new ByteArrayOutputStream();
-            Document document1 = new Document(PageSize.A4);
-            PdfWriter pdfWriter = PdfWriter.getInstance(document1, byteArrayOutputStream1);
-            document1.setMargins(70, 70, 40, 40);
-            document1.open();
-            // 闈炲寲楠岄」鐩姤鍛�
-            Map<TjOrderRemark, List<TjPdfVO>> printReport = new HashMap<>();
-            notHuaYanData(tjNumber, printReport, tjOrder, tjCustomer);
-            for (Map.Entry<TjOrderRemark, List<TjPdfVO>> entry : printReport.entrySet()) {
-                List<TjPdfVO> value = entry.getValue();
-                LambdaQueryWrapper<TjProject> wqqq = new LambdaQueryWrapper<>();
-                wqqq.eq(TjProject::getProId, entry.getKey().getProId());
-                TjProject one11 = projectService.getOne(wqqq);
-                //鍒ゆ柇璇ラ」鐩槸鍚﹂渶瑕佹墦鍗版姤鍛�
-                if (null != one11 && "N".equals(one11.getNeedReport())) {
-                    continue;
-                }
-                String titleName = null;
-                if (null != one11 && "1".equals(one11.getResultType())) {
-                    titleName = one11.getProName();
-                    // 璁剧疆鏍囬瀛椾綋鏍峰紡
-                    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);
-                    //鍒ゆ柇澶囨敞鏄惁涓虹┖  绌轰笉鑳芥樉绀簄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);
-                            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, remark);
-                        document1.add(pp);
-                    }
-                    //鍒ゆ柇涓绘鍖诲笀鏄惁涓虹┖  绌轰笉鑳芥樉绀簄ull
-                    if (null != entry.getKey().getDoctorName() && null != userService.getById(entry.getKey().getDoctorName())) {
-                        //涓绘鍖诲笀
-                        String doctorName = "涓绘鍖诲笀锛�" + userService.getById(entry.getKey().getDoctorName()).getNickName();
-                        Font doctorFonts = PdfUtils.setFont(9);
-                        Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName);
-                        df.setAlignment(Element.ALIGN_RIGHT);
-                        document1.add(df);
-                    } else {
-                        String doctorName = "涓绘鍖诲笀锛�" + "鏃�";
-                        Font doctorFonts = PdfUtils.setFont(9);
-                        Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName);
-                        df.setAlignment(Element.ALIGN_RIGHT);
-                        document1.add(df);
-                    }
-                    //鍒嗗壊绾�
-                    LineSeparator objectName = new LineSeparator();
-                    document1.add(objectName);
-                } else {
-                    if (null != one11) {
-                        titleName = one11.getProName();
-                    } else {
-                        titleName = entry.getKey().getProName();
-                    }
-                    // 璁剧疆鏍囬瀛椾綋鏍峰紡
-                    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);
-                    //鍒ゆ柇澶囨敞鏄惁涓虹┖  绌轰笉鑳芥樉绀簄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);
-                            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, remark);
-                        document1.add(pp);
-                    }
-                    //鍒ゆ柇涓绘鍖诲笀鏄惁涓虹┖  绌轰笉鑳芥樉绀簄ull
-                    if (null != entry.getKey().getDoctorName() && null != userService.getById(entry.getKey().getDoctorName())) {
-                        //涓绘鍖诲笀
-                        String doctorName = "涓绘鍖诲笀锛�" + userService.getById(entry.getKey().getDoctorName()).getNickName();
-                        Font doctorFonts = PdfUtils.setFont(9);
-                        Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName);
-                        df.setAlignment(Element.ALIGN_RIGHT);
-                        document1.add(df);
-                    } else {
-                        String doctorName = "涓绘鍖诲笀锛�" + "鏃�";
-                        Font doctorFonts = PdfUtils.setFont(9);
-                        Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName);
-                        df.setAlignment(Element.ALIGN_RIGHT);
-                        document1.add(df);
-                    }
-                    //鍒嗗壊绾�
-                    LineSeparator objectName = new LineSeparator();
-                    document1.add(objectName);
-                }
-            }
-            List<ByteArrayOutputStream> jianchas = new ArrayList<>();
-            for (Object o : jsonArray) {
-                JSONObject jsonObject = (JSONObject) o;
-                // 妫�楠屾姤鍛婁互鍙婄粨鏋滀俊鎭�
-                JSONObject reportInfo = jsonObject.getJSONObject("鎶ュ憡璁板綍");
-                String titleName = "";
-                if (reportInfo != null) {
-                    titleName = reportInfo.getStr("JYXMMC").trim();
-                }
-                JSONArray reportDetails = jsonObject.getJSONArray("妫�楠岀粨鏋滆褰�");
-                ArrayList<TjPdfVO> listPdf = new ArrayList<>();
-                String[] titles = null;
-                float[] titlesWidth = null;
-                // 缁撴灉淇℃伅
-                if (reportDetails != null && reportDetails.size() > 0) {
-                    for (Object reportDetail : reportDetails) {
-                        JSONObject detail = (JSONObject) reportDetail;
-                        TjPdfVO tjPdfVO = new TjPdfVO();
-                        tjPdfVO.setProName(detail.getStr("JCZBMC"));
-                        tjPdfVO.setProResult(detail.getStr("JCZBJG"));
-                        tjPdfVO.setVal1(detail.getStr("JLDW"));
-                        tjPdfVO.setVal2(detail.getStr("CKZFW"));
-                        listPdf.add(tjPdfVO);
-                    }
-                    titles = new String[]{"浣撴椤圭洰", "浣撴缁撴灉", "鍗曚綅", "鍙傝�冭寖鍥�"};
-                    titlesWidth = new float[]{120, 120, 120, 120};
-                    addTable(document1, titleName, titles, titlesWidth, listPdf);
-                    // 涓绘鍖诲笀
-                    String bgysqm = reportInfo.getStr("BGYSQM");
-                    String doctorName = "涓绘鍖诲笀锛�" + bgysqm;
-                    Font doctorFonts = PdfUtils.setFont(9);
-                    Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName);
-                    df.setAlignment(Element.ALIGN_RIGHT);
-                    document1.add(df);
-                    //鍒嗗壊绾�
-                    LineSeparator objectName = new LineSeparator();
-                    document1.add(objectName);
-                }
-                // 寰敓鐗╂姤鍛婅褰曚俊鎭�
-                JSONArray labgermrepInfos = jsonObject.getJSONArray("寰敓鐗╂姤鍛婅褰�");
-                if (labgermrepInfos != null && labgermrepInfos.size() > 0) {
-                    listPdf = new ArrayList<>();
-                    for (Object info : labgermrepInfos) {
-                        JSONObject object = (JSONObject) info;
-                        TjPdfVO tjPdfVO = new TjPdfVO();
-                        tjPdfVO.setProName(object.getStr("XJMC"));
-                        tjPdfVO.setProResult(object.getStr("JCJG"));
-                        listPdf.add(tjPdfVO);
-                    }
-                    titles = new String[]{"浣撴椤圭洰", "浣撴缁撴灉"};
-                    titlesWidth = new float[]{120, 120};
-                    addTable(document1, titleName, titles, titlesWidth, listPdf);
-                    //鍒嗗壊绾�
-                    LineSeparator objectName = new LineSeparator();
-                    document1.add(objectName);
-                }
-                // 寰敓鐗╄嵂鏁忎俊鎭�
-                JSONArray labgermdetailinfos = jsonObject.getJSONArray("寰敓鐗╄嵂鏁忎俊鎭�");
-                if (labgermdetailinfos != null && labgermdetailinfos.size() > 0) {
-                    listPdf = new ArrayList<>();
-                    for (Object info : labgermdetailinfos) {
-                        JSONObject object = (JSONObject) info;
-                        TjPdfVO tjPdfVO = new TjPdfVO();
-                        tjPdfVO.setProName(object.getStr("YMMC"));
-                        tjPdfVO.setProResult(object.getStr("JCJG"));
-                        tjPdfVO.setVal1(object.getStr("ZPHYL"));
-                        tjPdfVO.setVal2(object.getStr("YJND"));
-                        tjPdfVO.setVal3(object.getStr("YJHZJ"));
-                        listPdf.add(tjPdfVO);
-                    }
-                    titles = new String[]{"鑽晱鍚嶇О", "妫�鏌ョ粨鏋�", "绾哥墖鍚嵂閲�", "鎶戣弻娴撳害", "鎶戣弻鐜洿寰�"};
-                    titlesWidth = new float[]{90, 90, 90, 90, 90};
-                    addTable(document1, titleName, titles, titlesWidth, listPdf);
-                    //鍒嗗壊绾�
-                    LineSeparator objectName = new LineSeparator();
-                    document1.add(objectName);
-                }
-                // 鍗辨�ュ�间俊鎭�
-                JSONArray laburgentinfos = jsonObject.getJSONArray("鍗辨満鍊间俊鎭�");
-                if (laburgentinfos != null && laburgentinfos.size() > 0) {
-                    listPdf = new ArrayList<>();
-                    for (Object info : laburgentinfos) {
-                        JSONObject object = (JSONObject) info;
-                        TjPdfVO tjPdfVO = new TjPdfVO();
-                        tjPdfVO.setProName(object.getStr("zbmc"));
-                        tjPdfVO.setProResult(object.getStr("jg"));
-                        tjPdfVO.setVal1(object.getStr("clfs"));
-                        tjPdfVO.setVal2(object.getStr("bgcljg"));
-                        listPdf.add(tjPdfVO);
-                    }
-                    titles = new String[]{"鎸囨爣鍚嶇О", "鍗辨�ュ�肩粨鏋�", "澶勭悊鏂瑰紡", "澶勭悊鎰忚"};
-                    titlesWidth = new float[]{120, 120, 120, 120};
-                    addTable(document1, titleName, titles, titlesWidth, listPdf);
-                    //鍒嗗壊绾�
-                    LineSeparator objectName = new LineSeparator();
-                    document1.add(objectName);
-                }
-                JSONArray object = jsonObject.getJSONArray("妫�鏌ユ姤鍛�");
-                if (object != null && object.size() > 0) {
-                    for (Object info : object) {
-                        JSONObject obj = (JSONObject) info;
-                        String xm = obj.getStr("HZXM");
-                        String xb = obj.getStr("HZXB").equals("2") ? "濂�" : "鐢�";
-                        String nl = obj.getStr("HZNL");
-                        if (StrUtil.isNotBlank(nl) && nl.contains(".")) {
-                            String[] split = nl.split("\\.");
-                            nl = split[0];
-                        }
-                        String jcks = obj.getStr("JCKSMC");
-                        String zyh = "";
-                        String sqks = obj.getStr("SQKSMC");
-                        String sjks = obj.getStr("ZDJGMC");
-                        String jcsb = obj.getStr("SBBM");
-                        String jch = obj.getStr("JCH");
-                        String jcxm = obj.getStr("JCXMMC");
-                        String ms = obj.getStr("YXBX");
-                        String ts = obj.getStr("YXZD");
-                        String ch = obj.getStr("BZBCH");
-                        // 鎶ュ憡鍖诲笀绛惧悕
-                        String bgysqm = obj.getStr("BGYSQM");
-                        // 瀹℃牳鍖诲笀绛惧悕
-                        String shysqm = obj.getStr("SHYSQM");
-                        // 鐢宠浜�
-                        String sqrxm = obj.getStr("SQRXM");
-                        String footer = "鐢宠浜猴細" + sqrxm + "     瀹℃牳鍖诲笀锛�" + shysqm + "     " + bgysqm;
-                        ByteArrayOutputStream outputStream = makeJcPDFByteArrayStream(xm, xb, nl, jcks, zyh, ch, sjks, jcsb, jch, jcxm, ms, ts, null, footer);
-                        jianchas.add(outputStream);
-                    }
-                }
-            }
-            document1.close();
-            pdfWriter.close();
-            reader = new PdfReader(byteArrayOutputStream1.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();
-            }
-            byteArrayOutputStream1.close();
-            document.close();
-            copy.close();
-            reader.close();
-            String outputFileName1 = userId + tjNumber + tjCustomer.getCusName() + "_鎶ュ憡.pdf";
-            // 鏂囦欢閰嶇疆
-//            String outputPath1 = "/Users/chacca/寮�鍙戠浉鍏�/浠g爜/";
-            String outputPath1 = value + "\\";
-            File file = new File(outputPath1 + outputFileName1);
-            BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
-            outputStream.write(finalOutPut.toByteArray());
-            outputStream.flush();
-            outputStream.close();
-            finalOutPut.close();
-            reader.close();
-            // 淇濆瓨鏁版嵁
-            TjReport tjReport = new TjReport();
-            tjReport.setTjNumber(String.valueOf(tjNumber));
-            tjReport.setPath(urlValue + outputFileName1);
-            String pdfBinary = getPDFBinary(outputPath1 + outputFileName1);
-            tjReport.setReport(pdfBinary);
-            tjReport.setType("浣撴鎶ュ憡");
-            tjReport.setPrint("pdf");
-            tjReportService.save(tjReport);
-            //淇敼order琛ㄤ腑鐨勬墦鍗版姤鍛婃椂闂翠负褰撳墠鏃堕棿
-            LambdaUpdateWrapper<TjOrder> updateWrapper = new LambdaUpdateWrapper<>();
-            updateWrapper.eq(TjOrder::getTjNumber, tjNumber);
-            updateWrapper.set(TjOrder::getReportTime, new Date());
-            updateWrapper.set(TjOrder::getPrintLastTime, new Date());
-            updateWrapper.set(TjOrder::getDownloadLastTime, new Date());
-            updateWrapper.set(TjOrder::getStatus, TjConstants.TJ_END);
-            tjOrderService.update(updateWrapper);
-        } catch (IOException | DocumentException e) {
-            e.printStackTrace();
-            return false;
-        }
-        return true;
-    }
-
     /**
      * 缁勫悎闈炲寲楠岄」鐩姤鍛婃暟鎹�
      *
@@ -1147,18 +671,18 @@
                 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("/");
+                    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("/");
+                        }
+                        tjPdfVOS.add(tjPdfVO);
                     }
-                    tjPdfVOS.add(tjPdfVO);
-                }
                 }
             }
             printReport.put(entry.getKey(), tjPdfVOS);
@@ -1604,8 +1128,8 @@
             return baos;
         } catch (DocumentException | IOException e) {
             e.printStackTrace();
+            return null;
         }
-        return null;
     }
 
     private static PdfPCell createImageCell(String path) throws IOException, BadElementException {

--
Gitblit v1.8.0