From d3767d594de66cb5f9d1294931acefea1866f783 Mon Sep 17 00:00:00 2001
From: renkang <8417338+k94314517@user.noreply.gitee.com>
Date: 星期五, 24 一月 2025 18:24:25 +0800
Subject: [PATCH] 客户资料 巡检任务业务

---
 server/visits/dmvisit_service/src/main/java/com/doumee/core/excel/ExcelReplaceCommon.java |   65 ++++++++++++++++++++++++++++++--
 1 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/core/excel/ExcelReplaceCommon.java b/server/visits/dmvisit_service/src/main/java/com/doumee/core/excel/ExcelReplaceCommon.java
index 9694405..e0c27a1 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/core/excel/ExcelReplaceCommon.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/core/excel/ExcelReplaceCommon.java
@@ -4,6 +4,11 @@
 import com.doumee.core.exception.BusinessException;
 import com.doumee.core.utils.Constants;
 import com.doumee.dao.business.model.YwTempConfig;
+import fr.opensagres.xdocreport.document.IXDocReport;
+import fr.opensagres.xdocreport.document.registry.XDocReportRegistry;
+import fr.opensagres.xdocreport.template.IContext;
+import fr.opensagres.xdocreport.template.TemplateEngineKind;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.apache.poi.xwpf.usermodel.XWPFParagraph;
 import org.apache.poi.xwpf.usermodel.XWPFRun;
@@ -33,7 +38,7 @@
 
 
 
-    public static String modifyWordTemplate(String templatePath, List<YwTempConfig> ywTempConfigList,String fileName) {
+    public static String modifyWordTemplate_old(String templatePath, List<YwTempConfig> ywTempConfigList,String fileName) {
         try (
              XWPFDocument document = new XWPFDocument(getFileInputStream(templatePath))) {
             // 姝ゅ杩炴帴鍒板悗缁浛鎹㈡楠�
@@ -42,10 +47,15 @@
                 for (XWPFRun run : paragraph.getRuns()) {
                     // 鏇挎崲鍗犱綅绗�
                     String text = run.getText(0);
+                    System.out.println(text);
                     if (text != null) {
-                        for (YwTempConfig ywTempConfig:ywTempConfigList
-                             ) {
-                            text = text.replace(ywTempConfig.getTitle(), ywTempConfig.getUrl());
+                        for (YwTempConfig ywTempConfig:ywTempConfigList) {
+                            if(StringUtils.isNotBlank(ywTempConfig.getUrl())){
+                                text = text.replace(ywTempConfig.getTitle(), ywTempConfig.getUrl());
+                            }else{
+                                text = text.replace(ywTempConfig.getTitle(), "");
+                            }
+
                         }
                         run.setText(text, 0); // 閲嶆柊璁剧疆鏂囨湰
                     }
@@ -67,6 +77,53 @@
         throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏂囦欢杞崲寮傚父!");
     }
 
+
+
+
+    public static String modifyWordTemplate(String templatePath, List<YwTempConfig> ywTempConfigList,String fileName,String zipFilePath) {
+        InputStream ins = null;
+        OutputStream out = null;
+        try{
+            //鑾峰彇Word妯℃澘锛屾ā鏉垮瓨鏀捐矾寰勫湪椤圭洰鐨剅esources鐩綍涓�
+            ins = getFileInputStream(templatePath) ;
+//            ins = new FileInputStream("D:\\3.docx");
+            //娉ㄥ唽xdocreport瀹炰緥骞跺姞杞紽reeMarker妯℃澘寮曟搸
+            IXDocReport report = XDocReportRegistry.getRegistry().loadReport(ins,
+                    TemplateEngineKind.Freemarker);
+            //鍒涘缓xdocreport涓婁笅鏂囧璞�
+            IContext context = report.createContext();
+            for (YwTempConfig ywTempConfig:ywTempConfigList) {
+                if(StringUtils.isBlank(ywTempConfig.getUrl())){
+                    ywTempConfig.setUrl("-");
+                }
+                context.put(ywTempConfig.getTitle().replace("${","").replace("}",""), ywTempConfig.getUrl());
+            }
+            String path = zipFilePath + fileName;
+            out = new FileOutputStream(new File(path));
+            report.process(context, out);
+            return path;
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (null != ins) {
+                try {
+                    ins.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return null;
+    }
+
+
+
+
+
+
+
+
+
     /*璇诲彇缃戠粶鏂囦欢*/
     public static InputStream getFileInputStream(String path) {
         URL url = null;

--
Gitblit v1.9.3