From 7a0c5479c363a10f573aa15a54dc8130eabd47ff Mon Sep 17 00:00:00 2001
From: jinlin <jinlin>
Date: 星期一, 29 一月 2024 11:47:53 +0800
Subject: [PATCH] 修改

---
 core/src/main/java/com/zt/life/export/service/WordFileService.java |   30 +++++++++++++++++++++++++-----
 1 files changed, 25 insertions(+), 5 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 0576d03..1abcfb8 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
@@ -14,10 +14,13 @@
 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.text.SimpleDateFormat;
 import java.util.*;
 
 @Service
@@ -63,23 +66,40 @@
                 if (field.getType().getName().equals("java.util.List")) {
                     builder.bind(fieldName, new HackLoopTableRenderPolicy());
                 } else if (staticFieldValue != null) {
+                    if (typeName.contains("java.util.Date") && fieldName.contains("Date")) {
+                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy骞碝M鏈坉d鏃�");
+                        staticFieldValue = sdf.format(staticFieldValue);
+                    }
                     String valStr = staticFieldValue.toString();
                     if (valStr.contains("鏂囦欢鍥剧墖:")) {
-                        valStr = valStr.replace("鏂囦欢鍥剧墖:", "");
+                        valStr = localPath + valStr.replace("鏂囦欢鍥剧墖:", "");
                         File file = new File(valStr);
-                        if (file.exists()) {
+                        if (file.exists() && !localPath.equals(valStr)) {
                             try (InputStream in = ossEncryptService.decrypt(file)) {
-                                staticFieldValue = new PictureRenderData(500, 500, ".png", in);
+                                InputStream in2 = ossEncryptService.decrypt(file);
+                                BufferedImage bufferedImage = ImageIO.read(in2);
+                                int width = bufferedImage.getWidth();
+                                int height = bufferedImage.getHeight();
+                                if (width > 900 ) {
+                                    height = (height * 900) / width;
+                                    staticFieldValue = new PictureRenderData(900, height, ".png", in);
+                                } else {
+                                    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, localPath + "template/noSign.png");
                         }
-                        if (wordData.get(fieldName) == null)
-                            wordData.put(fieldName, staticFieldValue);
                     }
                 }
+                if (wordData.get(fieldName) == null)
+                    wordData.put(fieldName, staticFieldValue);
             }
+            if (wordData.get(fieldName) == null)
+                wordData.put(fieldName, staticFieldValue);
         }
     }
 }

--
Gitblit v1.9.1