From 1dd74654647974f8faa7d96463126d517eca0140 Mon Sep 17 00:00:00 2001
From: 许鹏程 <1821349743@qq.com>
Date: 星期五, 04 八月 2023 15:53:55 +0800
Subject: [PATCH] 打印流程意见时将 用户签名输出到意见框右下角 修复打印时一些临时文件未删除感觉

---
 src/main/java/com/product/print/util/DynamicTableRenderPolicy.java |   47 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/product/print/util/DynamicTableRenderPolicy.java b/src/main/java/com/product/print/util/DynamicTableRenderPolicy.java
index a8179d1..731c237 100644
--- a/src/main/java/com/product/print/util/DynamicTableRenderPolicy.java
+++ b/src/main/java/com/product/print/util/DynamicTableRenderPolicy.java
@@ -1,5 +1,6 @@
 package com.product.print.util;
 
+import cn.hutool.core.io.IoUtil;
 import com.deepoove.poi.exception.RenderException;
 import com.deepoove.poi.render.RenderContext;
 import com.deepoove.poi.template.run.RunTemplate;
@@ -8,12 +9,18 @@
 import com.product.core.exception.BaseException;
 import com.product.print.config.CmnCode;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.util.Units;
 import org.apache.poi.xwpf.usermodel.*;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Base64;
 import java.util.List;
 import java.util.Map;
 import java.util.regex.Matcher;
@@ -133,9 +140,7 @@
 				XWPFTableCell cell;
 				//鍒ゆ柇row涓j涓崟鍏冩牸鏄惁瀛樺湪
 				if (row.getTableCells().size() > j) {
-					cell = row.getTableCells().get(j);
-					//娓呯┖鍗曞厓鏍煎唴瀹�
-					cell.removeParagraph(0);
+					cell = row.getCell(j);
 				} else {
 					cell = row.createCell();
 				}
@@ -149,8 +154,41 @@
 				if (value == null) {
 					value = "";
 				}
-				//璁剧疆鍗曞厓鏍肩殑鍊�
+				String text = cell.getText();
+				//鍒犻櫎鍗曞厓鏍间腑鐨勬棫鍐呭
+				if (!StringUtils.isEmpty(text)) {
+					List<XWPFParagraph> paragraphs = cell.getParagraphs();
+					if (paragraphs.size() > 1) {
+						cell.removeParagraph(1);
+					}
+					List<XWPFRun> runs = paragraphs.get(0).getRuns();
+					//娓呯┖鏂囧瓧
+					for (int k = 0; k < runs.size(); k++) {
+						runs.get(k).setText("", 0);
+					}
+				}
 				cell.setText(value.toString());
+				if ("lx_flow_opinion".equals(this.replaceKey) && "opinion".equals(fieldNames[j]) && !StringUtils.isEmpty(map.get("sign_attachment_uuid"))) {
+					//鎰忚妗� 鎻掑叆绛惧悕鍥剧墖鍒板崟鍏冩牸鍙充笅瑙掍綅缃�
+					XWPFParagraph xwpfParagraph = cell.addParagraph();
+					xwpfParagraph.setAlignment(ParagraphAlignment.RIGHT);
+					XWPFRun run = xwpfParagraph.createRun();
+					String signAttachmentBase64 = map.get("sign_attachment_uuid").toString();
+					//灏哹ase64杞崲瀛楄妭娴�
+					byte[] bytes = Base64.getDecoder().decode(signAttachmentBase64.split(",")[1]);
+					//灏嗗瓧鑺傛祦杞崲涓鸿緭鍏ユ祦
+					InputStream inputStream = new ByteArrayInputStream(bytes);
+					try {
+						//鎹㈣鎻掑叆鍥剧墖
+						run.addPicture(inputStream, XWPFDocument.PICTURE_TYPE_PNG, "sign.png", Units.toEMU(50), Units.toEMU(20));
+						inputStream.close();
+					} catch (InvalidFormatException e) {
+						e.printStackTrace();
+					} catch (IOException e) {
+						e.printStackTrace();
+					}
+				}
+
 			}
 		}
 		//鍒犻櫎璧峰琛�
@@ -248,6 +286,7 @@
 			}
 			copyTableCell(cell1, cell2);
 		}
+
 	}
 
 	/**

--
Gitblit v1.9.2