diff --git a/src/main/java/neatlogic/framework/form/attribute/core/IFormAttributeDataConversionHandler.java b/src/main/java/neatlogic/framework/form/attribute/core/IFormAttributeDataConversionHandler.java index 606353d10d59a72db674dc904fd13f485cb12008..dcac8da5f696923c5382853368df34570991c9d6 100644 --- a/src/main/java/neatlogic/framework/form/attribute/core/IFormAttributeDataConversionHandler.java +++ b/src/main/java/neatlogic/framework/form/attribute/core/IFormAttributeDataConversionHandler.java @@ -17,6 +17,7 @@ package neatlogic.framework.form.attribute.core; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.form.dto.AttributeDataVo; +import neatlogic.framework.form.dto.FormAttributeVo; /** * @Author:laiwt @@ -51,6 +52,16 @@ public interface IFormAttributeDataConversionHandler { return originalValue; } + /** + * 获取增强可读性值,注意用于表格选择组件、表格输入组件、表单子组件 + * @param originalValue + * @param formAttributeVo + * @return + */ + default Object getEnhanceReadabilityValue(Object originalValue, FormAttributeVo formAttributeVo) { + return originalValue; + } + /** * 通过简单值获取标准值,例如下拉框的简单值为a或A,返回标准值为{"value":"a", "text":"A"} * @param simpleValue diff --git a/src/main/java/neatlogic/framework/logback/converter/RequestUrlConverter.java b/src/main/java/neatlogic/framework/logback/converter/RequestUrlConverter.java index 9724a25a070dd26bc6db7161fc726e9023c35adb..1c022a31357dda7ea1838ee959c8816eef9cbc19 100644 --- a/src/main/java/neatlogic/framework/logback/converter/RequestUrlConverter.java +++ b/src/main/java/neatlogic/framework/logback/converter/RequestUrlConverter.java @@ -40,7 +40,6 @@ public class RequestUrlConverter extends ClassicConverter implements Serializabl public String convert(ILoggingEvent event) { RequestContext requestContext = RequestContext.get(); if (requestContext != null) { - System.out.println("RequestUrlConverter requestContext.getUrl() = " + requestContext.getUrl()); return requestContext.getUrl(); } else { Map map = event.getMDCPropertyMap(); diff --git a/src/main/java/neatlogic/framework/util/FormUtil.java b/src/main/java/neatlogic/framework/util/FormUtil.java index 335a5440939c8d5d84439dfa7942f7c1d3457a63..d54a499ea6b9aae55c5a4a62aa8b5544b923a171 100644 --- a/src/main/java/neatlogic/framework/util/FormUtil.java +++ b/src/main/java/neatlogic/framework/util/FormUtil.java @@ -21,7 +21,9 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.dependency.core.DependencyManager; +import neatlogic.framework.form.attribute.core.FormAttributeDataConversionHandlerFactory; import neatlogic.framework.form.attribute.core.FormAttributeHandlerFactory; +import neatlogic.framework.form.attribute.core.IFormAttributeDataConversionHandler; import neatlogic.framework.form.attribute.core.IFormAttributeHandler; import neatlogic.framework.form.constvalue.FormHandler; import neatlogic.framework.form.dto.AttributeDataVo; @@ -35,10 +37,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; public class FormUtil { @@ -323,6 +322,48 @@ public class FormUtil { return originalValue; } + public static Object getEnhanceReadabilityValue(Object originalValue, FormAttributeVo formAttributeVo) { + if (originalValue == null) { + return originalValue; + } + Map downwardFormAttributeMap = new HashMap<>(); + JSONObject componentObj = new JSONObject(); + componentObj.put("handler", formAttributeVo.getHandler()); + componentObj.put("uuid", formAttributeVo.getUuid()); + componentObj.put("label", formAttributeVo.getLabel()); + componentObj.put("config", formAttributeVo.getConfig()); + componentObj.put("type", formAttributeVo.getType()); + List downwardFormAttributeList = FormUtil.getFormAttributeList(componentObj, null); + if (CollectionUtils.isNotEmpty(downwardFormAttributeList)) { + for (FormAttributeVo downwardFormAttributeVo : downwardFormAttributeList) { + if (!downwardFormAttributeMap.containsKey(downwardFormAttributeVo.getUuid())) { + downwardFormAttributeMap.put(downwardFormAttributeVo.getUuid(), downwardFormAttributeVo); + } + } + } + JSONArray dataList = new JSONArray(); + JSONArray dataArray = JSONArray.parseArray(((JSONArray) originalValue).toJSONString()); + for (int i = 0; i < dataArray.size(); i++) { + JSONObject rowObj = dataArray.getJSONObject(i); + if (MapUtils.isNotEmpty(rowObj)) { + JSONObject newRowObj = new JSONObject(); + for (Map.Entry entry : rowObj.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + newRowObj.put(key, value); + FormAttributeVo downwardFormAttributeVo = downwardFormAttributeMap.get(key); + if (downwardFormAttributeVo != null) { + IFormAttributeDataConversionHandler handler = FormAttributeDataConversionHandlerFactory.getHandler(downwardFormAttributeVo.getHandler()); + Object enhanceReadabilityValue = handler.getEnhanceReadabilityValue(value, downwardFormAttributeVo); + newRowObj.put(downwardFormAttributeVo.getKey(), enhanceReadabilityValue); + newRowObj.put(downwardFormAttributeVo.getLabel(), enhanceReadabilityValue); + } + } + dataList.add(newRowObj); + } + } + return dataList; + } /** * 根据表单配置信息解析出表单的所有组件列表,包括子表单中的组件 * @param formConfig @@ -479,6 +520,16 @@ public class FormUtil { JSONArray tableList2 = formConfig.getJSONArray("tableList"); resultList.addAll(getAllFormAttributeList(tableList2, parent2)); } + } else { + JSONObject config = componentObj.getJSONObject("config"); + JSONObject formData2 = config.getJSONObject("formData"); + if (MapUtils.isNotEmpty(formData2)) { + JSONObject formConfig = formData2.getJSONObject("formConfig"); + if (MapUtils.isNotEmpty(formConfig)) { + JSONArray tableList2 = formConfig.getJSONArray("tableList"); + resultList.addAll(getAllFormAttributeList(tableList2, parent2)); + } + } } } else { JSONArray componentArray = componentObj.getJSONArray("component"); @@ -517,7 +568,9 @@ public class FormUtil { if (MapUtils.isNotEmpty(config)) { if (Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) { JSONObject formData = componentObj.getJSONObject("formData"); - config.put("formData", formData); + if (MapUtils.isNotEmpty(formData)) { + config.put("formData", formData); + } } boolean isRequired = config.getBooleanValue("isRequired"); formAttributeVo.setRequired(isRequired); diff --git a/src/main/java/neatlogic/module/framework/form/attribute/handler/CheckboxHandler.java b/src/main/java/neatlogic/module/framework/form/attribute/handler/CheckboxHandler.java index 5b02ed6b4c2359e4d576459ae01fa5b56c41da36..e1fe1adcdf2ba085319bdd42eca73ee09248268b 100644 --- a/src/main/java/neatlogic/module/framework/form/attribute/handler/CheckboxHandler.java +++ b/src/main/java/neatlogic/module/framework/form/attribute/handler/CheckboxHandler.java @@ -89,6 +89,11 @@ public class CheckboxHandler extends FormHandlerBase { return formService.getSelectStandardValueBySimpleValue(simpleValue, configObj); } + @Override + public Object getEnhanceReadabilityValue(Object originalValue, FormAttributeVo formAttributeVo) { + return FormUtil.getFormSelectAttributeValueByOriginalValue(originalValue); + } + @Override public Object dataTransformationForEmail(AttributeDataVo attributeDataVo, JSONObject configObj) { JSONObject resultObj = getMyDetailedData(attributeDataVo, configObj); diff --git a/src/main/java/neatlogic/module/framework/form/attribute/handler/RadioHandler.java b/src/main/java/neatlogic/module/framework/form/attribute/handler/RadioHandler.java index 6cb46bc0905cdd33fafb03c868b9ecea801afe2e..8c4993d0bbb831ab1844972f28ab4f80051eb766 100644 --- a/src/main/java/neatlogic/module/framework/form/attribute/handler/RadioHandler.java +++ b/src/main/java/neatlogic/module/framework/form/attribute/handler/RadioHandler.java @@ -106,6 +106,11 @@ public class RadioHandler extends FormHandlerBase { return formService.getSelectStandardValueBySimpleValue(simpleValue, configObj); } + @Override + public Object getEnhanceReadabilityValue(Object originalValue, FormAttributeVo formAttributeVo) { + return FormUtil.getFormSelectAttributeValueByOriginalValue(originalValue); + } + @Override public Object dataTransformationForEmail(AttributeDataVo attributeDataVo, JSONObject configObj) { JSONObject resultObj = getMyDetailedData(attributeDataVo, configObj); diff --git a/src/main/java/neatlogic/module/framework/form/attribute/handler/SelectHandler.java b/src/main/java/neatlogic/module/framework/form/attribute/handler/SelectHandler.java index ebdb8f60b1145fdeffd1601b529f229ccb27bcbf..3bfadb972e4003efbb4193c72996fa72e8d5d87a 100644 --- a/src/main/java/neatlogic/module/framework/form/attribute/handler/SelectHandler.java +++ b/src/main/java/neatlogic/module/framework/form/attribute/handler/SelectHandler.java @@ -201,6 +201,11 @@ public class SelectHandler extends FormHandlerBase { return formService.getSelectStandardValueBySimpleValue(simpleValue, configObj); } + @Override + public Object getEnhanceReadabilityValue(Object originalValue, FormAttributeVo formAttributeVo) { + return FormUtil.getFormSelectAttributeValueByOriginalValue(originalValue); + } + @Override public Object dataTransformationForEmail(AttributeDataVo attributeDataVo, JSONObject configObj) { JSONObject resultObj = getMyDetailedData(attributeDataVo, configObj); diff --git a/src/main/java/neatlogic/module/framework/form/attribute/handler/SubassemblyHandler.java b/src/main/java/neatlogic/module/framework/form/attribute/handler/SubassemblyHandler.java index 565dae65f60b284ca711b88a866f16126caab7b4..60c7994214ec56b5bd23728e9b4cf2aa4d5f3d22 100644 --- a/src/main/java/neatlogic/module/framework/form/attribute/handler/SubassemblyHandler.java +++ b/src/main/java/neatlogic/module/framework/form/attribute/handler/SubassemblyHandler.java @@ -11,6 +11,7 @@ import neatlogic.framework.form.constvalue.FormHandler; import neatlogic.framework.form.dto.AttributeDataVo; import neatlogic.framework.form.dto.FormAttributeVo; import neatlogic.framework.form.exception.AttributeValidException; +import neatlogic.framework.util.FormUtil; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Component; @@ -33,6 +34,11 @@ public class SubassemblyHandler extends FormHandlerBase { } } + @Override + public Object getEnhanceReadabilityValue(Object originalValue, FormAttributeVo formAttributeVo) { + return FormUtil.getEnhanceReadabilityValue(originalValue, formAttributeVo); + } + @Override public Object dataTransformationForEmail(AttributeDataVo attributeDataVo, JSONObject configObj) { return null; diff --git a/src/main/java/neatlogic/module/framework/form/attribute/handler/TableInputerHandler.java b/src/main/java/neatlogic/module/framework/form/attribute/handler/TableInputerHandler.java index b48e69cb66c0599a3e8a58784dbeeb0e8a6cbefc..7aaab6b2b7ac4dbadf4495d993a36c38fe7a3f24 100644 --- a/src/main/java/neatlogic/module/framework/form/attribute/handler/TableInputerHandler.java +++ b/src/main/java/neatlogic/module/framework/form/attribute/handler/TableInputerHandler.java @@ -26,6 +26,7 @@ import neatlogic.framework.form.dto.AttributeDataVo; import neatlogic.framework.form.dto.FormAttributeVo; import neatlogic.framework.form.exception.AttributeValidException; import neatlogic.framework.form.exception.FormExtendAttributeConfigIllegalException; +import neatlogic.framework.util.FormUtil; import neatlogic.framework.util.TableResultUtil; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; @@ -61,6 +62,11 @@ public class TableInputerHandler extends FormHandlerBase { } } + @Override + public Object getEnhanceReadabilityValue(Object originalValue, FormAttributeVo formAttributeVo) { + return FormUtil.getEnhanceReadabilityValue(originalValue, formAttributeVo); + } + @Override public Object dataTransformationForEmail(AttributeDataVo attributeDataVo, JSONObject configObj) { JSONObject resultObj = getMyDetailedData(attributeDataVo, configObj); diff --git a/src/main/java/neatlogic/module/framework/form/attribute/handler/TableSelectorHandler.java b/src/main/java/neatlogic/module/framework/form/attribute/handler/TableSelectorHandler.java index f99e54ac023530b5428d73d6adf7805b3699e936..5892e74e50e532b9fc20c49fdf7447c37828b457 100644 --- a/src/main/java/neatlogic/module/framework/form/attribute/handler/TableSelectorHandler.java +++ b/src/main/java/neatlogic/module/framework/form/attribute/handler/TableSelectorHandler.java @@ -25,6 +25,7 @@ import neatlogic.framework.form.dto.AttributeDataVo; import neatlogic.framework.form.dto.FormAttributeVo; import neatlogic.framework.form.exception.AttributeValidException; import neatlogic.framework.form.exception.FormExtendAttributeConfigIllegalException; +import neatlogic.framework.util.FormUtil; import neatlogic.framework.util.TableResultUtil; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; @@ -64,6 +65,11 @@ public class TableSelectorHandler extends FormHandlerBase { } } + @Override + public Object getEnhanceReadabilityValue(Object originalValue, FormAttributeVo formAttributeVo) { + return FormUtil.getEnhanceReadabilityValue(originalValue, formAttributeVo); + } + @Override public Object dataTransformationForEmail(AttributeDataVo attributeDataVo, JSONObject configObj) { JSONObject resultObj = getMyDetailedData(attributeDataVo, configObj);