From bb9bf60cbd34d0638f1df89c69358533b2cc220c Mon Sep 17 00:00:00 2001
From: wente <329538422@qq.com>
Date: 星期二, 05 十二月 2023 15:48:40 +0800
Subject: [PATCH] 项目表

---
 core/src/main/java/com/zt/life/export/service/WordFileService.java |   33 +++++++++++++++++++++++++++------
 1 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/core/src/main/java/com/zt/life/export/service/WordFileService.java b/core/src/main/java/com/zt/life/export/service/WordFileService.java
index 2329e9e..3ef75f1 100644
--- a/core/src/main/java/com/zt/life/export/service/WordFileService.java
+++ b/core/src/main/java/com/zt/life/export/service/WordFileService.java
@@ -8,12 +8,16 @@
 import com.deepoove.poi.policy.HackLoopTableRenderPolicy;
 
 import com.zt.life.export.dto.WordFile;
+import com.zt.life.oss.OssEncryptService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 
+import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.awt.image.BufferedImage;
 import java.io.*;
 import java.lang.reflect.Field;
 import java.util.*;
@@ -22,6 +26,10 @@
 public class WordFileService {
     @Value("${zt.oss.local-path}")
     private String localPath;
+
+    @Autowired
+    private OssEncryptService ossEncryptService;
+
 
     public void exportWordFile(HttpServletRequest request, Object dataObj, WordFile wordFile, HttpServletResponse response) throws UnsupportedEncodingException, FileNotFoundException {
         // 鏁版嵁map闆嗗悎
@@ -32,7 +40,7 @@
         this.formatWordData(dataObj, wordData, builder);
 
         config = builder.build();
-        File fl = new File(localPath+"/template/"+wordFile.getModulePath());
+        File fl = new File(localPath + "/template/" + wordFile.getModulePath());
         FileInputStream fs = new FileInputStream(fl);
         XWPFTemplate template;
         if (config != null) {
@@ -55,13 +63,26 @@
                 formatWordData(staticFieldValue, wordData, builder);
             } else {
                 if (field.getType().getName().equals("java.util.List")) {
-                   builder.bind(fieldName, new HackLoopTableRenderPolicy());
+                    builder.bind(fieldName, new HackLoopTableRenderPolicy());
                 } else if (staticFieldValue != null) {
                     String valStr = staticFieldValue.toString();
-                    if (valStr.contains("绛惧悕鍥剧墖:")) {
-                        valStr = valStr.replace("绛惧悕鍥剧墖:", "");
-                        staticFieldValue = new PictureRenderData(80, 100, "d://" + valStr);
-                        /*put("localbyte", new PictureRenderData(80, 100, ".png", new FileInputStream("./logo.png")));*/
+                    if (valStr.contains("鏂囦欢鍥剧墖:")) {
+                        valStr = localPath + valStr.replace("鏂囦欢鍥剧墖:", "");
+                        File file = new File(valStr);
+                        if (file.exists()) {
+                            try (InputStream in = ossEncryptService.decrypt(file)) {
+                                InputStream in2 = ossEncryptService.decrypt(file);
+                                BufferedImage bufferedImage = ImageIO.read(in2);
+                                int width = bufferedImage.getWidth();
+                                int height = bufferedImage.getHeight();
+                                staticFieldValue = new PictureRenderData(width, height, ".png", in);
+                                /*staticFieldValue = new PictureRenderData(80, 100, "d://" + valStr);*/
+                            } catch (IOException e) {
+                                e.printStackTrace();
+                            }
+                        } else {
+                            staticFieldValue = new PictureRenderData(100, 30, "template/noSign.png");
+                        }
                     }
                 }
                 if (wordData.get(fieldName) == null)

--
Gitblit v1.9.1