From a26fbe729817216bcf53b13945fe6300caa89997 Mon Sep 17 00:00:00 2001
From: 许鹏程 <1821349743@qq.com>
Date: 星期五, 04 八月 2023 15:12:21 +0800
Subject: [PATCH] 打印模板 打印流程审批意见
---
src/main/java/com/product/print/util/DynamicTableRenderPolicy.java | 21 ++++++++--
pom.xml | 4 ++
src/main/java/com/product/print/service/PrintRealizeService.java | 39 +++++++++++++++++++
3 files changed, 60 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 98feb5c..5652391 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,6 +34,10 @@
<artifactId>product-server-admin</artifactId>
</dependency>
<dependency>
+ <groupId>com.lx</groupId>
+ <artifactId>product-server-tool-flow</artifactId>
+ </dependency>
+ <dependency>
<groupId>com.deepoove</groupId>
<artifactId>poi-tl</artifactId>
<version>1.10.5</version>
diff --git a/src/main/java/com/product/print/service/PrintRealizeService.java b/src/main/java/com/product/print/service/PrintRealizeService.java
index 9e6b741..2a9fb63 100644
--- a/src/main/java/com/product/print/service/PrintRealizeService.java
+++ b/src/main/java/com/product/print/service/PrintRealizeService.java
@@ -3,6 +3,8 @@
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.net.URLEncodeUtil;
+import cn.hutool.extra.spring.SpringUtil;
+import com.alibaba.fastjson.JSONArray;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.config.ConfigureBuilder;
@@ -21,8 +23,10 @@
import com.product.print.config.CmnConst;
import com.product.print.service.ide.IPrintRealizeService;
import com.product.print.util.DynamicTableRenderPolicy;
+import com.product.tool.flow.service.FlowDetailService;
import com.product.util.BaseUtil;
+import com.product.util.SystemParamReplace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -161,6 +165,7 @@
if (fieldSetEntity == null || StringUtils.isEmpty(fieldSetEntity.getString(CmnConst.PRINT_TEMPLATE))) {
throw new BaseException(CmnCode.PRINT_CONFIG_NOT_EXIST.getValue(), CmnCode.PRINT_CONFIG_NOT_EXIST.getText());
}
+
return fieldSetEntity;
}
@@ -174,6 +179,29 @@
* @throws BaseException 寮傚父
*/
private String replaceTemplateFileOut(FieldSetEntity printConf, FieldSetEntity fse, boolean isConvertPdf) throws BaseException {
+
+ Object[] fields = fse.getFields();
+ for (int i = 0; i < fields.length; i++) {
+ String field = fields[i].toString();
+ FieldSetEntity metaEntity = fse.getMeta().getFieldMeta(field);
+ String fieldType = metaEntity.getString("field_type");
+ //鍒ゆ柇鏄惁鎷ユ湁娴佺▼鏍囪瘑
+ if ("flowsign".equals(fieldType)) {
+ if (StringUtils.equalsAny(fse.getString(field), "1", "2")) {
+ //娴佺▼鍔炵悊涓垨鍔炵粨 鑾峰彇娴佺▼鎰忚
+ FieldSetEntity flowTask = getBaseDao().getFieldSetByFilter("product_sys_flow_task", "table_name=? and record_uuid=?", new Object[]{fse.getTableName(), fse.getUUID()}, false);
+ if (flowTask != null) {
+ String taskUuid = flowTask.getString(CmnConst.UUID);
+ //鑾峰彇娴佺▼鎰忚
+ FlowDetailService flowDetailService = SpringUtil.getBean(FlowDetailService.class);
+ JSONArray opinion = flowDetailService.getHistoryInfo(taskUuid);
+ fse.setValue("~flow_opinion~", opinion);
+ }
+ }
+ break;
+ }
+ }
+
// 鎵撳嵃妯℃澘闄勪欢uuid
String template_uuid = printConf.getString(CmnConst.PRINT_TEMPLATE);
// 鑾峰彇鎵撳嵃妯℃澘
@@ -186,6 +214,9 @@
String localTempPathWord = Global.getSystemConfig("temp.dir", "") + File.separator + "temp_print_" + tempKey + ".docx";
replaceWord(localTempPathWord, file.getPath(), fse);
file.delete();
+
+ String replaceParams = SystemParamReplace.replaceParams(printConf.getString(CmnConst.PRINT_FILE_NAME), fse);
+ printConf.setValue(CmnConst.PRINT_FILE_NAME, replaceParams);
if (isConvertPdf) {
try {
// 鏇挎崲鍚庣殑pdf涓存椂璺緞
@@ -217,6 +248,10 @@
* @param dataFse 鏇挎崲鏁版嵁
*/
public static void replaceWord(String outPath, String templatePath, FieldSetEntity dataFse) {
+ JSONArray flowOpinion = (JSONArray) dataFse.getObject("~flow_opinion~");
+ if (flowOpinion != null) {
+ dataFse.remove("~flow_opinion~");
+ }
//杞崲鏁版嵁涓哄閫夋
dataConvertCheckedData(dataFse);
//鍏嬮殕涓�浠絭alues
@@ -230,6 +265,10 @@
config.bind(entry.getKey(), new DynamicTableRenderPolicy(entry.getKey()));
}
}
+ if(flowOpinion!=null && flowOpinion.size()>0){
+ cloneValues.put("lx_flow_opinion", flowOpinion);
+ config.bind("lx_flow_opinion", new DynamicTableRenderPolicy("lx_flow_opinion"));
+ }
try {
//妫�鏌ヨ緭鍑烘枃浠舵槸鍚﹀瓨鍦紝涓嶅瓨鍦ㄥ垯鍒涘缓
FileUtil.touch(outPath);
diff --git a/src/main/java/com/product/print/util/DynamicTableRenderPolicy.java b/src/main/java/com/product/print/util/DynamicTableRenderPolicy.java
index a8179d1..b7f20e3 100644
--- a/src/main/java/com/product/print/util/DynamicTableRenderPolicy.java
+++ b/src/main/java/com/product/print/util/DynamicTableRenderPolicy.java
@@ -9,6 +9,7 @@
import com.product.print.config.CmnCode;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xwpf.usermodel.*;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -133,9 +134,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 +148,21 @@
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());
+
}
}
//鍒犻櫎璧峰琛�
@@ -248,6 +260,7 @@
}
copyTableCell(cell1, cell2);
}
+
}
/**
--
Gitblit v1.9.2