From 1f35c75edfde8d204e788f304929b1fb01ddb765 Mon Sep 17 00:00:00 2001
From: zhijie <1003392067@qq.com>
Date: 星期日, 08 八月 2021 21:13:35 +0800
Subject: [PATCH] 1.PAQ简易版(中英泰)支持 2.支持完美水滴生成

---
 src/main/java/com/ots/common/utils/poi/WordUtil.java |  113 +++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 66 insertions(+), 47 deletions(-)

diff --git a/src/main/java/com/ots/common/utils/poi/WordUtil.java b/src/main/java/com/ots/common/utils/poi/WordUtil.java
index 7791cea..2f7182f 100644
--- a/src/main/java/com/ots/common/utils/poi/WordUtil.java
+++ b/src/main/java/com/ots/common/utils/poi/WordUtil.java
@@ -9,6 +9,7 @@
 import com.ots.project.exam.domain.TReportTemplate;
 import com.ots.project.exam.dto.JAQTableStyle;
 import com.ots.project.exam.dto.WordParam;
+import com.ots.project.tool.PdfUtil;
 import com.ots.project.tool.ShellTool;
 import com.ots.project.tool.exam.ExamUtil;
 import com.ots.project.tool.exam.ImageUtil;
@@ -17,6 +18,8 @@
 import com.ots.project.tool.report.JAQ.condition.Table2;
 import com.ots.project.tool.report.JAQ.condition.Table3;
 import com.ots.project.tool.report.JAQ.condition.Table4;
+import com.ots.project.tool.report.PAQ.chart.PAQChart;
+import com.ots.project.tool.report.SAQ.chart.SAQChart;
 import org.apache.commons.collections.map.HashedMap;
 import org.apache.poi.ooxml.POIXMLDocument;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@@ -40,6 +43,8 @@
 import java.awt.image.BufferedImage;
 import java.io.*;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 public class WordUtil {
     private static final Logger log = LoggerFactory.getLogger(WordUtil.class);
@@ -177,6 +182,9 @@
                 if (run.toString().indexOf("%TTime%") != -1) {
                     run.setText(textMap.get("reportGenerationDate").toString(), 0);
                 }
+                if (run.toString().indexOf("%LIBSAQGS0018%") != -1) {
+                    run.setText(textMap.get("LIBSAQGS0018").toString(), 0);
+                }
             }
         }
     }
@@ -254,7 +262,7 @@
     public static CTAnchor getAnchorWithGraphic(CTGraphicalObject ctGraphicalObject,
                                                 String deskFileName, int width, int height,
                                                 int leftOffset, int topOffset, boolean behind, int topPosition) {
-        long relativeHeight = 251649024l + topPosition;
+        long relativeHeight = 251649024L + topPosition;
         String anchorXML =
                 "<wp:anchor xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" "
                         + "simplePos=\"0\" relativeHeight=\"" + relativeHeight + "\" behindDoc=\"" + ((behind) ? 1 : 0) + "\" locked=\"0\" layoutInCell=\"1\" allowOverlap=\"1\">"
@@ -391,7 +399,7 @@
         }
     }
     private static void setTextValue(Map<String, Object> textMap, XWPFDocument document, XWPFParagraph paragraph, int runPosition, XWPFRun run) {
-        System.out.println("琛ㄦ牸鐨勶細" + run.toString());
+        log.info("琛ㄦ牸鐨勶細{}", run.toString());
         try {
             run.setText(changeValue(run.toString(), textMap, run, paragraph, document, runPosition), 0);
         } catch (Exception e) {
@@ -421,16 +429,34 @@
             }
         }
     }
-    
+
+    //鏍¢獙鏂囨湰鏄惁闇�瑕佹浛鎹�
     public static boolean checkText(String text) {
+        //鏇挎崲鏂囨湰鍖呭惈%
         if (text.indexOf("%") != -1 || StringUtils.equals(text, "N/A NONE")) {
-            return true;
+            //鍙湁%澶т簬1 鎵嶉�氳繃
+            if(getCount(text) > 1){
+                return true;
+            }
+            return false;
         }
         return false;
     }
+
+    //鍒ゆ柇%鍑虹幇鐨勬鏁�
+    public static int getCount(String text){
+        //鏃ч暱搴�
+        int oldLength = text.length();
+        text = text.replace("%", "");
+        //鏂伴暱搴�
+        int newLength = text.length();
+        //鍑虹幇娆℃暟 = 鏃ч暱搴� - 鏂伴暱搴�
+        int count = oldLength - newLength;
+        return count;
+    }
     
     public static String changeValue(String runValue, Map<String, Object> textMap, XWPFRun run, XWPFParagraph paragraph, XWPFDocument document, int runPosition) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException {
-        
+        log.debug("changeText:{}",runValue);
         Set<Map.Entry<String, Object>> textSets = textMap.entrySet();
         for (Map.Entry<String, Object> textSet : textSets) {
             
@@ -448,7 +474,11 @@
                 if (runValue.indexOf("<BoldText>") != -1) {
                     return setOtherStyle(runValue, paragraph, runPosition, run);
                 }
-                break;
+                //鏈変簺琛ㄦ牸鍙兘瀛樺湪澶氫釜瀛楀吀 闇�鏇挎崲澶氭涓嶈兘杞绘槗break
+                //娌℃湁鍙浛鎹㈠唴瀹圭洿鎺reak
+                if(getTextSize(runValue) == 0){
+                    break;
+                }
             }
         }
         
@@ -594,38 +624,6 @@
     }
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     private static void changOtherPicture(XWPFParagraph paragraph) {
         
         String paragraphText = paragraph.getText();
@@ -755,7 +753,12 @@
             setChageWord(fileName, out, textMap, tReportTemplate.getReportType(), templateType, autoTableMap);
             out.flush();
             changColorIfJAQ(textMap, out, reportName, tReportTemplate.getReportType());
-            ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/");
+            //PAQ閲囩敤鏂扮殑doc杞琾df
+            if(!ReportTypeEnum.PAQ.getCode().equals(reportType)){
+                ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/");
+            }else{
+                PdfUtil.convertPDF(EssConfig.getProfile() + "/" + reportName);
+            }
             zipFilePath = getPdfPath(reportName);
             
             deleteFileStrList.add(EssConfig.getProfile() + "/" + reportName);
@@ -841,14 +844,12 @@
         //璁剧疆鏂囨湰
         changeText(document, textMap);
 
-        //鏇存敼鏂囨湰妗�
-        if (Objects.equals(reportType, ReportTypeEnum.MAQV2.getCode())) {
-            changeTextBox(document, textMap);
-        }
+        //璁剧疆鏂囨湰妗�
+        changeTextBox(document, textMap);
 
-        //CAQ鏇存敼鏂囨湰妗嗭紝wzp娴嬭瘯.2021.4.27
-        if (Objects.equals(reportType, ReportTypeEnum.CAQ.getCode())) {
-            changeTextBox(document, textMap);
+        //璁剧疆鍥捐〃
+        if (Objects.equals(reportType, ReportTypeEnum.PAQ.getCode())) {
+            PAQChart.changeChart(document, textMap);
         }
 
         //鎻掑叆琛ㄦ牸
@@ -858,7 +859,7 @@
         changeTable(document, textMap);
 
         //璁剧疆鍥捐〃鎺т欢
-        changChar(textMap, document, reportType, templateType);
+        //changChar(textMap, document, reportType, templateType);
         document.write(out);
     }
     private static void changeTextBox(XWPFDocument document, Map<String, Object> textMap) throws DocumentException {
@@ -886,6 +887,7 @@
         }
     }
     private static String getValByKey(String text, Map<String, Object> textMap) {
+        log.debug("changeTextBox:{}",text);
         if (!checkText(text)) {
             return text;
         }
@@ -1278,4 +1280,21 @@
             textMap.put("JAQTableStyle", jaqTableStyleList);
         }
     }
+
+    public static int getTextSize(String runValue){
+        Pattern pattern = Pattern.compile("%\\w+%");
+        Matcher matcher = pattern.matcher(runValue);
+        List<String> result = new ArrayList<>();
+        while(matcher.find()){
+            result.add(matcher.group());
+        }
+        return result.size();
+    }
+
+
+    public static void main(String[] args) {
+        if (!checkText("浜烘墠閫夋嫈鐨勭洰鐨勫氨鏄壘鍒拌兘澶熻儨浠诲伐浣溿�佹効鎰忔壙鎷呭伐浣滐紝涓斾笌缁勭粐鐨勯渶姹傘�佹枃鍖栥�佷环鍊艰鐩稿尮閰嶇殑浜恒�侾AQ鎶ュ憡鏄牴鎹�欓�変汉瀵筆AQ闂嵎涓鐩殑浣滅瓟淇℃伅鑰岀敓鎴愮殑锛屾祴閲忕殑鏄�欓�変汉鍦ㄥ伐浣滀腑鍋忓ソ鐨勮涓洪鏍笺�侾AQ涔熷寘鎷簡瀵逛綔绛旂湡瀹炴�х殑娴嬮噺锛屽悓鏃朵篃瑁呭叆浜員AI涓撴湁鐨勪綔鍋囬槻鑼冪▼搴忥紝鍙互鏈夋晥闄嶄綆鍊欓�変汉鐨勪吉瑁呭ソ鍊惧悜锛堝叏鐞�30%鐨勮嚜璇勯棶鍗蜂腑閮藉嚭鐜颁簡浼濂界幇璞★級銆�")) {
+            System.out.println("11");
+        }
+    }
 }

--
Gitblit v1.9.1