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 fbda551ead854f0dbaf427927d257b686ae7448c..47b47937901596b08f6237238bcbd8383198cb67 100644 --- a/src/main/java/neatlogic/framework/form/attribute/core/IFormAttributeDataConversionHandler.java +++ b/src/main/java/neatlogic/framework/form/attribute/core/IFormAttributeDataConversionHandler.java @@ -124,4 +124,14 @@ public interface IFormAttributeDataConversionHandler { return source; } + /** + * 密码解密 + * @param source 属性原始数据 + * @param configObj 属性配置信息 + * @return 返回解密后的数据 + */ + default String passwordDecryption(Object source, JSONObject configObj, String attributeUuid, JSONObject otherParamConfig) { + return null; + } + } diff --git a/src/main/java/neatlogic/framework/form/dto/FormVersionVo.java b/src/main/java/neatlogic/framework/form/dto/FormVersionVo.java index b5e61b0371fa6c39d68a8f87ef40539f540efd6d..0dfe884180a3048b1c05fd83646a61f97474740f 100644 --- a/src/main/java/neatlogic/framework/form/dto/FormVersionVo.java +++ b/src/main/java/neatlogic/framework/form/dto/FormVersionVo.java @@ -19,6 +19,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.annotation.JSONField; import neatlogic.framework.common.dto.BaseEditorVo; +import neatlogic.framework.form.constvalue.FormHandler; import neatlogic.framework.util.UuidUtil; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; @@ -255,6 +256,10 @@ public class FormVersionVo extends BaseEditorVo { String label = componentObj.getString("label"); String type = componentObj.getString("type"); String handler = componentObj.getString("handler"); + if (Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) { + JSONObject formData = componentObj.getJSONObject("formData"); + config.put("formData", formData); + } boolean isRequired = config.getBooleanValue("isRequired"); String defaultValue = config.getString("defaultValue"); return new FormAttributeVo(this.getFormUuid(), this.getUuid(), uuid, key, label, type, handler, isRequired, config, defaultValue); diff --git a/src/main/java/neatlogic/framework/form/exception/FormAttributeNotFoundException.java b/src/main/java/neatlogic/framework/form/exception/FormAttributeNotFoundException.java index 49e201e4c458b2b132f9ab72a7c9cd572272af72..2b1fc353df1a082cde60b962fc09a3d28131d8bc 100644 --- a/src/main/java/neatlogic/framework/form/exception/FormAttributeNotFoundException.java +++ b/src/main/java/neatlogic/framework/form/exception/FormAttributeNotFoundException.java @@ -22,10 +22,10 @@ public class FormAttributeNotFoundException extends ApiRuntimeException { private static final long serialVersionUID = -2778517020600259453L; public FormAttributeNotFoundException(String attributeUuid) { - super("表单属性:“{0}”不存在", attributeUuid); + super("nffe.formattributenotfoundexception.formattributenotfoundexception_a", attributeUuid); } public FormAttributeNotFoundException(String formName, String attributeUuid) { - super("表单”{0}“中找不到“{1}”属性", formName, attributeUuid); + super("nffe.formattributenotfoundexception.formattributenotfoundexception_b", formName, attributeUuid); } } diff --git a/src/main/java/neatlogic/framework/util/FormUtil.java b/src/main/java/neatlogic/framework/util/FormUtil.java index 6625fcab5d1ebee2df2f302a0bfb3faa88df2e95..fb4c2cc5c4fa67b84b4c997472d3c5e1634cc0e2 100644 --- a/src/main/java/neatlogic/framework/util/FormUtil.java +++ b/src/main/java/neatlogic/framework/util/FormUtil.java @@ -514,6 +514,10 @@ public class FormUtil { formAttributeVo.setType(type); JSONObject config = componentObj.getJSONObject("config"); if (MapUtils.isNotEmpty(config)) { + if (Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) { + JSONObject formData = componentObj.getJSONObject("formData"); + config.put("formData", formData); + } boolean isRequired = config.getBooleanValue("isRequired"); formAttributeVo.setRequired(isRequired); String defaultValue = config.getString("defaultValue"); diff --git a/src/main/java/neatlogic/module/framework/form/attribute/handler/PasswordHandler.java b/src/main/java/neatlogic/module/framework/form/attribute/handler/PasswordHandler.java index b445d40e5980792e6a7a050560ab512470d8bb3e..92b3b4148be8466a1ed365d9c59f566305423184 100644 --- a/src/main/java/neatlogic/module/framework/form/attribute/handler/PasswordHandler.java +++ b/src/main/java/neatlogic/module/framework/form/attribute/handler/PasswordHandler.java @@ -162,4 +162,15 @@ public class PasswordHandler extends FormHandlerBase { } return source; } + + @Override + public String passwordDecryption(Object source, JSONObject configObj, String attributeUuid, JSONObject otherParamConfig) { + if (source == null) { + return null; + } + if (source instanceof String) { + return RC4Util.decrypt((String) source); + } + return null; + } } 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 a5e6f780b94959ba361ebb5a45763f58be5cb549..b8cf55b83d79c4fcf25a85cf19c3a9b3c6dcd9c8 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 @@ -1,15 +1,22 @@ package neatlogic.module.framework.form.attribute.handler; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.common.constvalue.ParamType; +import neatlogic.framework.form.attribute.core.FormAttributeDataConversionHandlerFactory; import neatlogic.framework.form.attribute.core.FormHandlerBase; +import neatlogic.framework.form.attribute.core.IFormAttributeDataConversionHandler; import neatlogic.framework.form.constvalue.FormConditionModel; 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 org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Component; +import java.util.Objects; + @Component public class SubassemblyHandler extends FormHandlerBase { @Override @@ -95,4 +102,107 @@ public class SubassemblyHandler extends FormHandlerBase { public void makeupFormAttribute(FormAttributeVo formAttributeVo) { super.makeupFormAttribute(formAttributeVo); } + + @Override + public Object passwordEncryption(Object source, JSONObject configObj) { + JSONArray dataArray = null; + if (source instanceof JSONArray) { + dataArray = (JSONArray) source; + } + if (CollectionUtils.isEmpty(dataArray)) { + return source; + } + JSONObject formData = configObj.getJSONObject("formData"); + if (MapUtils.isNotEmpty(formData)) { + JSONObject formConfig = formData.getJSONObject("formConfig"); + if (MapUtils.isNotEmpty(formConfig)) { + JSONArray tableList = formConfig.getJSONArray("tableList"); + if (CollectionUtils.isNotEmpty(tableList)) { + for (int i = 0; i < tableList.size(); i++) { + JSONObject tableObj = tableList.getJSONObject(i); + if (MapUtils.isNotEmpty(tableObj)) { + JSONObject component = tableObj.getJSONObject("component"); + if (MapUtils.isNotEmpty(component)) { + String handler = component.getString("handler"); + if (Objects.equals(handler, FormHandler.FORMPASSWORD.getHandler()) + || Objects.equals(handler, FormHandler.FORMTABLEINPUTER.getHandler()) + || Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) { + String uuid = component.getString("uuid"); + JSONObject config = component.getJSONObject("config"); + IFormAttributeDataConversionHandler formAttributeDataConversionHandler = FormAttributeDataConversionHandlerFactory.getHandler(handler); + if (Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) { + JSONObject formData1 = component.getJSONObject("formData"); + config.put("formData", formData1); + } + for (int j = 0; j < dataArray.size(); j++) { + JSONObject dataObj = dataArray.getJSONObject(j); + if (MapUtils.isNotEmpty(dataObj)) { + Object data = dataObj.get(uuid); + if (data != null) { + dataObj.put(uuid, formAttributeDataConversionHandler.passwordEncryption(data, config)); + } + } + } + } + } + } + } + } + } + } + return dataArray; + } + + @Override + public String passwordDecryption(Object source, JSONObject configObj, String attributeUuid, JSONObject otherParamConfig) { + JSONArray dataArray = null; + if (source instanceof JSONArray) { + dataArray = (JSONArray) source; + } + if (CollectionUtils.isEmpty(dataArray)) { + return null; + } + JSONObject formData = configObj.getJSONObject("formData"); + if (MapUtils.isNotEmpty(formData)) { + JSONObject formConfig = formData.getJSONObject("formConfig"); + if (MapUtils.isNotEmpty(formConfig)) { + JSONArray tableList = formConfig.getJSONArray("tableList"); + if (CollectionUtils.isNotEmpty(tableList)) { + for (int i = 0; i < tableList.size(); i++) { + JSONObject tableObj = tableList.getJSONObject(i); + if (MapUtils.isNotEmpty(tableObj)) { + JSONObject component = tableObj.getJSONObject("component"); + if (MapUtils.isNotEmpty(component)) { + String handler = component.getString("handler"); + if (Objects.equals(handler, FormHandler.FORMPASSWORD.getHandler()) + || Objects.equals(handler, FormHandler.FORMTABLEINPUTER.getHandler()) + || Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) { + String uuid = component.getString("uuid"); + JSONObject config = component.getJSONObject("config"); + IFormAttributeDataConversionHandler formAttributeDataConversionHandler = FormAttributeDataConversionHandlerFactory.getHandler(handler); + if (Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) { + JSONObject formData1 = component.getJSONObject("formData"); + config.put("formData", formData1); + } + for (int j = 0; j < dataArray.size(); j++) { + JSONObject dataObj = dataArray.getJSONObject(j); + if (MapUtils.isNotEmpty(dataObj)) { + Object data = dataObj.get(uuid); + if (data != null) { + String result = formAttributeDataConversionHandler.passwordDecryption(data, config, attributeUuid, otherParamConfig); + if (result != null) { + return result; + } + } + } + } + } + } + } + } + } + } + } + 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 f5eff8e919592080c40652d687e817118ef5309b..ad0b25b4d9b5014eee6618ebbce5e6a01ac7c52e 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 @@ -898,4 +898,59 @@ public class TableInputerHandler extends FormHandlerBase { } return dataArray; } + + @Override + public String passwordDecryption(Object source, JSONObject configObj, String attributeUuid, JSONObject otherParamConfig) { + JSONArray dataArray = null; + if (source instanceof JSONArray) { + dataArray = (JSONArray) source; + } + if (CollectionUtils.isEmpty(dataArray)) { + return null; + } + String rowUuid = otherParamConfig.getString("rowUuid"); + JSONArray dataConfig = configObj.getJSONArray("dataConfig"); + if (CollectionUtils.isNotEmpty(dataConfig)) { + for (int i = 0; i < dataConfig.size(); i++) { + JSONObject attr = dataConfig.getJSONObject(i); + String handler = attr.getString("handler"); + if (Objects.equals(handler, FormHandler.FORMPASSWORD.getHandler())) { + String uuid = attr.getString("uuid"); + if (Objects.equals(uuid, attributeUuid)) { + for (int j = 0; j < dataArray.size(); j++) { + JSONObject dataObj = dataArray.getJSONObject(j); + if (MapUtils.isNotEmpty(dataObj)) { + if (Objects.equals(dataObj.getString("uuid"), rowUuid)) { + String data = dataObj.getString(uuid); + if (StringUtils.isNotBlank(data)) { +// dataObj.put(uuid, RC4Util.encrypt(data)); + return RC4Util.decrypt(data); + } + } + } + } + } + } else if (Objects.equals(handler, "formtable")) { + JSONObject config = attr.getJSONObject("config"); + if (MapUtils.isEmpty(config)) { + continue; + } + String uuid = attr.getString("uuid"); + for (int j = 0; j < dataArray.size(); j++) { + JSONObject dataObj = dataArray.getJSONObject(j); + if (MapUtils.isNotEmpty(dataObj)) { + JSONArray data = dataObj.getJSONArray(uuid); + if (CollectionUtils.isNotEmpty(data)) { + String result = this.passwordDecryption(data, config, attributeUuid, otherParamConfig); + if (result != null) { + return result; + } + } + } + } + } + } + } + return null; + } }