jinlin
2023-12-18 e4db7d4a3e03ec4767a57743aef01e54461bbe9a
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,35 @@
                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-MM-dd");
                        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();
                                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);
        }
    }
}