354798ggg
2023-05-17 c022558c4ab5ec68a06aa82f27d61a0d1b544046
打印word优化,新增勾选框处理
已修改2个文件
85 ■■■■■ 文件已修改
src/main/java/com/product/print/config/CmnConst.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/print/service/PrintRealizeService.java 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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="□";
}
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)) {
                    //获取每个字段的meta信息
                    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";