From c022558c4ab5ec68a06aa82f27d61a0d1b544046 Mon Sep 17 00:00:00 2001
From: 354798ggg <1074825718@qq.com>
Date: 星期三, 17 五月 2023 14:11:01 +0800
Subject: [PATCH] 打印word优化,新增勾选框处理
---
src/main/java/com/product/print/config/CmnConst.java | 12 ++++++
src/main/java/com/product/print/service/PrintRealizeService.java | 73 +++++++++++++++++++++++++++++++++++-
2 files changed, 82 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/product/print/config/CmnConst.java b/src/main/java/com/product/print/config/CmnConst.java
index 8ae0e78..2391aae 100644
--- a/src/main/java/com/product/print/config/CmnConst.java
+++ b/src/main/java/com/product/print/config/CmnConst.java
@@ -17,4 +17,16 @@
public static final String PRINT_TEMPLATE = "print_template";
//鎵撳嵃閰嶇疆琛�
public static final String TABLE_PRINT_CONFIG = "product_sys_print_config";
+
+ public static final String PRINT_NAME="print_name";
+ public static final String PRINT_FILE_NAME="print_file_name";
+
+
+ public static final String DICT_VALUE="dict_value";
+ public static final String DICT_LABEL="dict_label";
+ public static final String FIELD_REFERECE="field_reference";
+ public static final String _SAVE_VALUE="_save_value";
+ public static final String PRINT_FONT="Wingdings 2";
+ public static final String PRINT_CHECKED_CHAR="鈽�";
+ public static final String PRINT_UNCHECKED_CHAR="鈻�";
}
diff --git a/src/main/java/com/product/print/service/PrintRealizeService.java b/src/main/java/com/product/print/service/PrintRealizeService.java
index 7ebb4a8..d77e16d 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";
--
Gitblit v1.9.2