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/service/PrintRealizeService.java |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)

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);

--
Gitblit v1.9.2