From 77f6cf1868777a27c033af7d6d4f2fe9d2afc30d Mon Sep 17 00:00:00 2001
From: 林致杰 <1003392067@qq.com>
Date: 星期四, 19 十月 2023 18:26:43 +0800
Subject: [PATCH] LAQ支持,新增python转换

---
 src/main/java/com/ots/project/tool/report/LAQ/LAQTemplate.java                      |    5 ++++-
 src/main/java/com/ots/common/utils/poi/WordUtil.java                                |    4 ++++
 src/main/java/com/ots/framework/config/EssConfig.java                               |    9 +++++++++
 src/main/java/com/ots/project/tool/PdfUtil.java                                     |   33 ++++++++++++++++++++++++++++++---
 src/main/java/com/ots/project/tool/report/LAQ/chart/LAQChart.java                   |    4 ++--
 src/main/java/com/ots/project/tool/report/LAQ/condition/ScoreInterpretationBLA.java |    2 +-
 6 files changed, 50 insertions(+), 7 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 4d7ec5d..18156be 100644
--- a/src/main/java/com/ots/common/utils/poi/WordUtil.java
+++ b/src/main/java/com/ots/common/utils/poi/WordUtil.java
@@ -24,6 +24,7 @@
 import org.apache.commons.collections.map.HashedMap;
 import org.apache.poi.ooxml.POIXMLDocument;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.util.ZipSecureFile;
 import org.apache.poi.util.Units;
 import org.apache.poi.xwpf.usermodel.*;
 import org.apache.xmlbeans.XmlCursor;
@@ -1183,6 +1184,8 @@
             if(ReportTypeEnum.PAQ.getCode().equals(reportType) || ReportTypeEnum.MAQTR.getCode().equals(reportType)
                     || ReportTypeEnum.CIAQ.getCode().equals(reportType)){
                 PdfUtil.convertPDF(EssConfig.getProfile() + "/" + reportName);
+            }else if(ReportTypeEnum.LAQ.getCode().equals(reportType)){
+                PdfUtil.convertPythonPDF(EssConfig.getDocx2pdf(),EssConfig.getProfile() + "/" + reportName);
             }else{
                 ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/");
                 // ShellTool shellTool = ShellTool.builder();
@@ -1282,6 +1285,7 @@
      */
     private static void setChageWord(String fileName, OutputStream out, Map<String, Object> textMap, String reportType,String dataPath, Map<Integer, Map<Integer, List<String[]>>> autoTableMap) throws IOException, InvalidFormatException, DocumentException {
         //String filePath = getTemplateDownLoadPathByUpLoad(fileName);
+        ZipSecureFile.setMinInflateRatio(0.001);
 
         XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(getTemplateDownLoadPathByUpLoad(fileName)));
 
diff --git a/src/main/java/com/ots/framework/config/EssConfig.java b/src/main/java/com/ots/framework/config/EssConfig.java
index e1d7d4c..ba4f449 100644
--- a/src/main/java/com/ots/framework/config/EssConfig.java
+++ b/src/main/java/com/ots/framework/config/EssConfig.java
@@ -15,6 +15,7 @@
     private boolean demoEnabled;
     
     private static String profile;
+    private static String docx2pdf;
     
     private static boolean addressEnabled;
     private static String imagePath;
@@ -91,4 +92,12 @@
     public static String getUploadImagePath() {
         return getProfile() + "/images";
     }
+
+    public static String getDocx2pdf() {
+        return docx2pdf;
+    }
+
+    public static void setDocx2pdf(String docx2pdf) {
+        EssConfig.docx2pdf = docx2pdf;
+    }
 }
diff --git a/src/main/java/com/ots/project/tool/PdfUtil.java b/src/main/java/com/ots/project/tool/PdfUtil.java
index 3c9ac24..1941a78 100644
--- a/src/main/java/com/ots/project/tool/PdfUtil.java
+++ b/src/main/java/com/ots/project/tool/PdfUtil.java
@@ -3,9 +3,7 @@
 import com.aspose.words.*;
 import lombok.extern.slf4j.Slf4j;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.*;
 import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -49,6 +47,35 @@
     }
 
     /**
+     * 鎵цpython鑴氭湰 docx杞琾df
+     * @param filePath
+     */
+    public static void convertPythonPDF(String pythonScript,String filePath){
+        try {
+            File file = new File(filePath);
+            if(!file.exists()){
+                file.mkdirs();
+            }
+            //鎵嬪姩鏇挎崲杈撳嚭pdf鍚嶇О
+            String output = filePath.replaceAll(".docx", ".pdf");
+            String[] args1 = new String[] { "python3", pythonScript, filePath, output };
+            // 鎵цpy鏂囦欢
+            Process proc = Runtime.getRuntime().exec(args1);
+            BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream(), "GBK"));
+            String line = null;
+            log.info("python鎵ц鍛戒护:{}", Arrays.toString(args1));
+            log.info("python鎵ц杩斿洖");
+            while ((line = in.readLine()) != null) {
+                log.info(line);
+            }
+            in.close();
+            proc.waitFor();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
      * aspose-words:jdk17:23.4 鐗堟湰
      */
     public static void registerWord() throws Exception {
diff --git a/src/main/java/com/ots/project/tool/report/LAQ/LAQTemplate.java b/src/main/java/com/ots/project/tool/report/LAQ/LAQTemplate.java
index eb1fd63..f363622 100644
--- a/src/main/java/com/ots/project/tool/report/LAQ/LAQTemplate.java
+++ b/src/main/java/com/ots/project/tool/report/LAQ/LAQTemplate.java
@@ -4,6 +4,7 @@
 import lombok.Data;
 
 import java.math.BigDecimal;
+import java.util.Date;
 
 /**
  * @description: LAQ瀵煎叆妯℃澘
@@ -20,7 +21,9 @@
     private String email;
 
     @Excel(name = "Scored on")
-    private String ScoredOn;
+    private Date scoredOn;
+
+    private String scoredOnStr;
 
     @Excel(name = "Company")
     private String company;
diff --git a/src/main/java/com/ots/project/tool/report/LAQ/chart/LAQChart.java b/src/main/java/com/ots/project/tool/report/LAQ/chart/LAQChart.java
index 96f6808..dd83ef3 100644
--- a/src/main/java/com/ots/project/tool/report/LAQ/chart/LAQChart.java
+++ b/src/main/java/com/ots/project/tool/report/LAQ/chart/LAQChart.java
@@ -66,12 +66,12 @@
             MapDataUtil.objectToMap(laqTemplate,textMap);
 
             LAQReport report = new LAQReport();
-            ReportResultData resultData = report.getTemplateParameters(textMap, ReportTypeEnum.LAQ, LangTypeEnum.codeOf("English"));
+//            ReportResultData resultData = report.getTemplateParameters(textMap, ReportTypeEnum.LAQ, LangTypeEnum.codeOf("English"));
 //            TReportTemplate template = null;
 //            String zipFileName = WordUtil.makeReportFile("D:\\娴嬭瘎绯荤粺\\闇�姹俓\LAQ\\report\\LAQ鑻辨枃鎶ュ憡-20230926.docx", template, textMap, new HashMap<>(), deleteStrList);
 //            fileNameList.add(zipFileName);
             ZipSecureFile.setMinInflateRatio(0.001);
-            try (OutputStream os = new FileOutputStream("D:\\娴嬭瘎绯荤粺\\闇�姹俓\2023\\5.棰嗗娼滃姏鎶ュ憡\\report\\LAQ.docx");XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage("D:\\娴嬭瘎绯荤粺\\闇�姹俓\2023\\5.棰嗗娼滃姏鎶ュ憡\\report\\LAQ鑻辨枃鎶ュ憡-20230926.docx"))){
+            try (OutputStream os = new FileOutputStream("D:\\娴嬭瘎绯荤粺\\闇�姹俓\2023\\5.棰嗗娼滃姏鎶ュ憡\\report\\LAQ缂栬瘧鎶ュ憡鑻辨枃.docx");XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage("D:\\娴嬭瘎绯荤粺\\闇�姹俓\2023\\5.棰嗗娼滃姏鎶ュ憡\\report\\LAQ鑻辨枃鐗�.docx"))){
                 Map<Integer,List<SeriesData>> seriesDatas = initData(textMap);
                 changeChart(document,seriesDatas,textMap);
                 document.write(os);
diff --git a/src/main/java/com/ots/project/tool/report/LAQ/condition/ScoreInterpretationBLA.java b/src/main/java/com/ots/project/tool/report/LAQ/condition/ScoreInterpretationBLA.java
index b04f768..f7d9982 100644
--- a/src/main/java/com/ots/project/tool/report/LAQ/condition/ScoreInterpretationBLA.java
+++ b/src/main/java/com/ots/project/tool/report/LAQ/condition/ScoreInterpretationBLA.java
@@ -14,7 +14,7 @@
 @Setter
 @Slf4j
 public class ScoreInterpretationBLA extends BaseCondition_V2 {
-    private String name = "BehaviorCharacteristicsV1";
+    private String name = "ScoreInterpretationBLA";
     private Double BLA;
 
     @Override

--
Gitblit v1.9.1