From a2cfd417f673603633c6d46713d320bb1501f88c Mon Sep 17 00:00:00 2001 From: 许鹏程 <1821349743@qq.com> Date: 星期二, 08 八月 2023 16:03:30 +0800 Subject: [PATCH] xn commit --- src/main/java/com/product/print/service/PrintRealizeService.java | 77 +++++++++++++++++++++++++++++++++++++- 1 files changed, 74 insertions(+), 3 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..4687f24 100644 --- a/src/main/java/com/product/print/service/PrintRealizeService.java +++ b/src/main/java/com/product/print/service/PrintRealizeService.java @@ -3,11 +3,15 @@ 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; import com.deepoove.poi.data.TextRenderData; import com.deepoove.poi.data.style.Style; +import com.deepoove.poi.render.RenderContext; +import com.deepoove.poi.util.RegexUtils; import com.product.common.lang.StringUtils; import com.product.core.cache.DataPoolCacheImpl; import com.product.core.config.Global; @@ -21,14 +25,21 @@ import com.product.print.config.CmnConst; import com.product.print.service.ide.IPrintRealizeService; import com.product.print.util.DynamicTableRenderPolicy; +import com.product.print.util.FlowOpinionRenderPolicy; +import com.product.print.util.TableEmptyHandler; +import com.product.tool.flow.service.FlowDetailService; import com.product.util.BaseUtil; +import com.product.util.SystemParamReplace; +import org.apache.poi.xwpf.usermodel.XWPFTable; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -53,7 +64,7 @@ public static void dataConvertCheckedData(FieldSetEntity fse) { TextRenderData selSymbol = new TextRenderData(CmnConst.PRINT_CHECKED_CHAR, new Style(CmnConst.PRINT_FONT, 14)); - TextRenderData unselSymbol = new TextRenderData(CmnConst.PRINT_UNCHECKED_CHAR, new Style(CmnConst.PRINT_FONT, 14)); + TextRenderData unselSymbol = new TextRenderData(CmnConst.PRINT_UNCHECKED_CHAR, new Style(CmnConst.PRINT_FONT, 18)); //鑾峰彇琛ㄥ崟瀛楁 Object[] fields = fse.getMeta().getFields(); @@ -142,8 +153,10 @@ e.printStackTrace(); throw new BaseException(CmnCode.PRINT_CONTENT_FAIL, e); } finally { - //鍒犻櫎pdf涓存椂鏂囦欢 - FileUtil.del(tempPdfFilePath); + File file = new File(tempPdfFilePath); + String absolutePath = file.getAbsolutePath(); + System.out.println(absolutePath); + file.delete(); } } @@ -161,6 +174,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 +188,32 @@ * @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); + if (metaEntity == null) { + continue; + } + 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 +226,9 @@ String localTempPathWord = Global.getSystemConfig("temp.dir", "") + File.separator + "temp_print_" + tempKey + ".docx"; replaceWord(localTempPathWord, file.getPath(), fse); file.delete(); + + String replaceParams = SystemParamReplace.replaceParams(Optional.ofNullable(printConf.getString(CmnConst.PRINT_FILE_NAME)).orElse(printConf.getString(CmnConst.PRINT_NAME)), fse); + printConf.setValue(CmnConst.PRINT_FILE_NAME, replaceParams); if (isConvertPdf) { try { // 鏇挎崲鍚庣殑pdf涓存椂璺緞 @@ -217,6 +260,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 @@ -224,12 +271,36 @@ //鑾峰彇瀛愯〃鏁版嵁 Map<String, DataTableEntity> subDataMap = dataFse.getSubData(); ConfigureBuilder config = Configure.createDefault().builder(); + config.addPlugin('@', new FlowOpinionRenderPolicy(flowOpinion)); + config.addPlugin('$', new com.deepoove.poi.policy.DynamicTableRenderPolicy() { + @Override + public void doRender(RenderContext<Object> context) throws Exception { + return; + } + + @Override + public void render(XWPFTable table, Object data) throws Exception { + return; + } + }); + config.buildGrammerRegex("(#)?([\\w\\u4e00-\\u9fa5]+)(\\.?[\\w\\u4e00-\\u9fa5\\|]*)*(#)?"); + TableEmptyHandler tableEmptyHandler = new TableEmptyHandler(); if (!CollectionUtil.isEmpty(subDataMap)) { for (Map.Entry<String, DataTableEntity> entry : subDataMap.entrySet()) { cloneValues.put(entry.getKey(), entry.getValue().getData().stream().map(item -> (Map<String, Object>) ((Map) item.getValues())).collect(Collectors.toList())); config.bind(entry.getKey(), new DynamicTableRenderPolicy(entry.getKey())); + tableEmptyHandler.addTag(entry.getKey()); } } + if (flowOpinion != null) { + if (!CollectionUtil.isEmpty(flowOpinion)) { + cloneValues.put("lx_flow_opinion", flowOpinion); + config.bind("lx_flow_opinion", new DynamicTableRenderPolicy("lx_flow_opinion")); + } + tableEmptyHandler.addTag("lx_flow_opinion"); + } + config.setValidErrorHandler(tableEmptyHandler); + try { //妫�鏌ヨ緭鍑烘枃浠舵槸鍚﹀瓨鍦紝涓嶅瓨鍦ㄥ垯鍒涘缓 FileUtil.touch(outPath); -- Gitblit v1.9.2