| | |
| | | |
| | | 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; |
| | |
| | | } |
| | | */ |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | 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(); |
| | |
| | | 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"; |
| | | |