From bf033b57eaa739061cd3ede60f1fdc3c79b7c787 Mon Sep 17 00:00:00 2001 From: shichongfu <shi_chongfu@163.com> Date: 星期五, 09 六月 2023 08:56:54 +0800 Subject: [PATCH] 打印转换 --- src/main/java/com/product/print/service/PrintRealizeService.java | 75 +++++++++++++++++++++++++++++++++++-- 1 files changed, 71 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/product/print/service/PrintRealizeService.java b/src/main/java/com/product/print/service/PrintRealizeService.java index 7ebb4a8..3744f9f 100644 --- a/src/main/java/com/product/print/service/PrintRealizeService.java +++ b/src/main/java/com/product/print/service/PrintRealizeService.java @@ -2,7 +2,10 @@ import com.deepoove.poi.XWPFTemplate; import com.deepoove.poi.config.Configure; +import com.deepoove.poi.data.TextRenderData; +import com.deepoove.poi.data.style.Style; import com.product.common.lang.StringUtils; +import com.product.core.cache.DataPoolCacheImpl; import com.product.core.config.Global; import com.product.core.entity.DataTableEntity; import com.product.core.entity.FieldSetEntity; @@ -80,6 +83,66 @@ } */ + /** + * word鎵撳嵃澶嶉�夋澶勭悊 + * @param fs + */ + 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)); + + //鑾峰彇琛ㄥ崟瀛楁 + Object[] fields = fse.getMeta().getFields(); + if (fields != null) { + for(int i = 0; i < fields.length; ++i) { + + //鑾峰彇淇濆瓨鐨勬暟鎹�� + String dataSaveValue = fse.getString(fields[i] + CmnConst._SAVE_VALUE); + if (!BaseUtil.strIsNull(dataSaveValue)) { + + //鑾峰彇姣忎釜瀛楁鐨刴eta淇℃伅 + FieldSetEntity meta = fse.getMeta().getFieldMeta(fields[i].toString()); + if (meta != null && meta.getString(CmnConst.FIELD_REFERECE) != null && meta.getString(CmnConst.FIELD_REFERECE).indexOf("銆�")>-1) { + + //鏁版嵁瀵瑰簲鍙傜収淇℃伅 + DataTableEntity dictInfos = getMetaAndCacheDictInfo(meta); + if (!BaseUtil.dataTableIsEmpty(dictInfos)) { + for (int j = 0; j < dictInfos.getRows(); j++) { + + //鑾峰彇姣忎釜鍙傜収瀵瑰簲鍊� + String dict_value = dictInfos.getFieldSetEntity(j).getString(CmnConst.DICT_VALUE); + + if (dataSaveValue.indexOf(dict_value)>-1) { + fse.setValue(fields[i]+"_" + dict_value, selSymbol); + }else { + fse.setValue(fields[i]+"_" + dict_value, unselSymbol); + } + } + } + } + } + } + } + } + + /** + * 鑾峰彇瀛楁瀵瑰簲鏁版嵁瀛楀吀淇℃伅 + * @param fieldMate + * @return + */ + public static DataTableEntity getMetaAndCacheDictInfo(FieldSetEntity fieldMate) { + if (fieldMate != null && fieldMate.getString(CmnConst.FIELD_REFERECE) != null) { + int a = fieldMate.getString(CmnConst.FIELD_REFERECE).indexOf("銆�"); + int b = fieldMate.getString(CmnConst.FIELD_REFERECE).indexOf("銆�"); + if (b > 1 && a == 0) { + return DataPoolCacheImpl.getInstance().getCacheData("鏁版嵁瀛楀吀閰嶇疆淇℃伅", new String[]{fieldMate.getString(CmnConst.FIELD_REFERECE).substring(a + 1, b)}); + } + } + return null; + } + + @Override public void printWord(FieldSetEntity fse, HttpServletResponse response) throws BaseException { // 鎵撳嵃閰嶇疆uuid @@ -129,6 +192,10 @@ configureBuilder.customPolicy(vv.getKey(), new HackLoopTableRenderPolicy()); } } + + //澶嶉�夋澶勭悊 + dataConvertCheckedData(fse); + XWPFTemplate render = XWPFTemplate.compile(file, configureBuilder == null ? Configure.createDefault() : configureBuilder.build()).render(fse.getValues()); render.write(is); render.close(); @@ -140,10 +207,10 @@ response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); String fileName = null; - if(!BaseUtil.strIsNull(fieldSetEntity.getString("print_file_name"))) { - fileName = SystemParamReplace.replaceParams(fieldSetEntity.getString("print_file_name"), fse); + if(!BaseUtil.strIsNull(fieldSetEntity.getString(CmnConst.PRINT_FILE_NAME))) { + fileName = SystemParamReplace.replaceParams(fieldSetEntity.getString(CmnConst.PRINT_FILE_NAME), fse); }else { - fileName = fieldSetEntity.getString("print_name"); + fileName = fieldSetEntity.getString(CmnConst.PRINT_NAME); } fileName+=".docx"; @@ -233,7 +300,7 @@ response.setContentType("multipart/form-data"); response.setHeader("Content-Disposition", "attachment;"); // 浣跨敤openOffice 杞崲涓簆df - pdfTemp = PdfConcurrenceUtil.convertToPdf(wordTemp.getPath(), localTempPathPdf); + pdfTemp = PdfConcurrenceUtil.convertToPdf(wordTemp.getPath(), localTempPathPdf,"docx"); InputStream isPdf = new FileInputStream(pdfTemp); int len; byte[] b = new byte[1024]; -- Gitblit v1.9.2