diff --git a/src/main/java/neatlogic/framework/form/dto/FormAttributeParentVo.java b/src/main/java/neatlogic/framework/form/dto/FormAttributeParentVo.java new file mode 100644 index 0000000000000000000000000000000000000000..43c9c74233c7d9e90631d5e2381beceb660d2131 --- /dev/null +++ b/src/main/java/neatlogic/framework/form/dto/FormAttributeParentVo.java @@ -0,0 +1,41 @@ +package neatlogic.framework.form.dto; + +public class FormAttributeParentVo { + private String uuid; + private String name; + private FormAttributeParentVo parent; + + public FormAttributeParentVo() { + + } + + public FormAttributeParentVo(String uuid, String name, FormAttributeParentVo parent) { + this.uuid = uuid; + this.name = name; + this.parent = parent; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public FormAttributeParentVo getParent() { + return parent; + } + + public void setParent(FormAttributeParentVo parent) { + this.parent = parent; + } +} diff --git a/src/main/java/neatlogic/framework/form/dto/FormAttributeVo.java b/src/main/java/neatlogic/framework/form/dto/FormAttributeVo.java index 0066c0e1e5cf996a10fc7077d409fc5209a34f30..5ff84a21a015675c82742cca9b3387ba25001420 100644 --- a/src/main/java/neatlogic/framework/form/dto/FormAttributeVo.java +++ b/src/main/java/neatlogic/framework/form/dto/FormAttributeVo.java @@ -78,6 +78,8 @@ public class FormAttributeVo implements Serializable { @JSONField(serialize = false) private Map> matrixUuidAttributeUuidSetMap; + private FormAttributeParentVo parent; + public FormAttributeVo() { } @@ -316,4 +318,12 @@ public class FormAttributeVo implements Serializable { public void setMatrixUuidAttributeUuidSetMap(Map> matrixUuidAttributeUuidSetMap) { this.matrixUuidAttributeUuidSetMap = matrixUuidAttributeUuidSetMap; } + + public FormAttributeParentVo getParent() { + return parent; + } + + public void setParent(FormAttributeParentVo parent) { + this.parent = parent; + } } diff --git a/src/main/java/neatlogic/module/framework/dependency/handler/Matrix2FormAttributeDependencyHandler.java b/src/main/java/neatlogic/module/framework/dependency/handler/Matrix2FormAttributeDependencyHandler.java index b31038c6929fd6f4a5a461639dc98658c8df6dcb..0f03de5416d52820274a7f108900104f4abee9cd 100644 --- a/src/main/java/neatlogic/module/framework/dependency/handler/Matrix2FormAttributeDependencyHandler.java +++ b/src/main/java/neatlogic/module/framework/dependency/handler/Matrix2FormAttributeDependencyHandler.java @@ -1,6 +1,5 @@ package neatlogic.module.framework.dependency.handler; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.asynchronization.threadlocal.TenantContext; import neatlogic.framework.dependency.constvalue.FrameworkFromType; @@ -9,11 +8,11 @@ import neatlogic.framework.dependency.core.IFromType; import neatlogic.framework.dependency.dto.DependencyInfoVo; import neatlogic.framework.dependency.dto.DependencyVo; import neatlogic.framework.form.dao.mapper.FormMapper; +import neatlogic.framework.form.dto.FormAttributeParentVo; import neatlogic.framework.form.dto.FormAttributeVo; import neatlogic.framework.form.dto.FormVersionVo; import neatlogic.framework.form.dto.FormVo; import neatlogic.module.framework.form.service.FormService; -import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; @@ -21,7 +20,6 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; -import java.util.Objects; @Component public class Matrix2FormAttributeDependencyHandler extends FixedTableDependencyHandlerBase { @@ -57,48 +55,23 @@ public class Matrix2FormAttributeDependencyHandler extends FixedTableDependencyH pathList.add("表单管理"); pathList.add(formVo.getName()); pathList.add(formVersionVo.getVersion().toString()); - String sceneName = getSceneName(formVersionVo, config.getString("sceneUuid")); - if (StringUtils.isNotBlank(sceneName)) { - pathList.add(sceneName); - } - String lastName = getFormAttributeLabel(formVersionVo, dependencyVo.getTo()); - String urlFormat = "/" + TenantContext.get().getTenantUuid() + "/framework.html#/form-edit?uuid=${DATA.formUuid}¤tVersionUuid=${DATA.formVersionUuid}"; - return new DependencyInfoVo(dependencyVo.getTo(), dependencyInfoConfig, lastName, pathList, urlFormat, this.getGroupName()); - } - - private String getSceneName(FormVersionVo formVersion, String sceneUuid) { - JSONObject formConfig = formVersion.getFormConfig(); - String uuid = formConfig.getString("uuid"); - if (Objects.equals(uuid, sceneUuid)) { -// String name = formConfig.getString("name"); -// return name; + String sceneUuid = config.getString("sceneUuid"); + FormAttributeVo formAttribute = formService.getFormAttribute(formVersionVo.getFormConfig(), dependencyVo.getTo(), sceneUuid); + if (formAttribute == null) { return null; } - JSONArray sceneList = formConfig.getJSONArray("sceneList"); - if (CollectionUtils.isNotEmpty(sceneList)) { - for (int i = 0; i < sceneList.size(); i++) { - JSONObject sceneObj = sceneList.getJSONObject(i); - if (MapUtils.isEmpty(sceneObj)) { - continue; - } - uuid = sceneObj.getString("uuid"); - if (Objects.equals(uuid, sceneUuid)) { - String name = sceneObj.getString("name"); - return name; - } - } + List parentNameList = new ArrayList<>(); + FormAttributeParentVo parent = formAttribute.getParent(); + while (parent != null) { + parentNameList.add(parent.getName()); + parent = parent.getParent(); } - return null; - } - - private String getFormAttributeLabel(FormVersionVo formVersion, String formAttributeUuid) { - List allFormAttributeList = formService.getAllFormAttributeList(formVersion.getFormConfig()); - for (FormAttributeVo formAttribute : allFormAttributeList) { - if (Objects.equals(formAttribute.getUuid(), formAttributeUuid)) { - return formAttribute.getLabel(); - } + for (int i = parentNameList.size() - 1; i >= 0; i--) { + pathList.add(parentNameList.get(i)); } - return ""; + String lastName = formAttribute.getLabel(); + String urlFormat = "/" + TenantContext.get().getTenantUuid() + "/framework.html#/form-edit?uuid=${DATA.formUuid}¤tVersionUuid=${DATA.formVersionUuid}"; + return new DependencyInfoVo(dependencyVo.getTo(), dependencyInfoConfig, lastName, pathList, urlFormat, this.getGroupName()); } @Override diff --git a/src/main/java/neatlogic/module/framework/form/service/FormService.java b/src/main/java/neatlogic/module/framework/form/service/FormService.java index e5b86033e3217ef62485d408b581d809fec739a4..cc44a615e97fb1c38143d3027c1dc36af3b9823f 100644 --- a/src/main/java/neatlogic/module/framework/form/service/FormService.java +++ b/src/main/java/neatlogic/module/framework/form/service/FormService.java @@ -81,6 +81,15 @@ public interface FormService { * @return */ List getAllFormAttributeList(String formConfig); + + /** + * 根据表单配置信息,表单组件uuid,场景uuid,获取表单组件信息 + * @param formConfig + * @param attributeUuid + * @param sceneUuid + * @return + */ + FormAttributeVo getFormAttribute(JSONObject formConfig, String attributeUuid, String sceneUuid); /** * 获取表单组件类型 * @param attributeUuid 属性唯一标识 diff --git a/src/main/java/neatlogic/module/framework/form/service/FormServiceImpl.java b/src/main/java/neatlogic/module/framework/form/service/FormServiceImpl.java index d1b0b63c82de8ca35cf256f79f700897736670db..ac4146ab12448a6237b4587357bea2c7d2170926 100644 --- a/src/main/java/neatlogic/module/framework/form/service/FormServiceImpl.java +++ b/src/main/java/neatlogic/module/framework/form/service/FormServiceImpl.java @@ -24,6 +24,7 @@ import neatlogic.framework.form.attribute.core.FormAttributeHandlerFactory; import neatlogic.framework.form.attribute.core.IFormAttributeHandler; import neatlogic.framework.form.constvalue.FormHandler; import neatlogic.framework.form.dto.AttributeDataVo; +import neatlogic.framework.form.dto.FormAttributeParentVo; import neatlogic.framework.form.dto.FormAttributeVo; import neatlogic.framework.form.dto.FormVersionVo; import neatlogic.framework.form.exception.AttributeValidException; @@ -735,7 +736,7 @@ public class FormServiceImpl implements FormService, IFormCrossoverService { @Override public List getAllFormAttributeList(JSONObject formConfig) { JSONArray tableList = formConfig.getJSONArray("tableList"); - return getAllFormAttributeList(tableList); + return getAllFormAttributeList(tableList, null); } @Override @@ -743,6 +744,33 @@ public class FormServiceImpl implements FormService, IFormCrossoverService { return getAllFormAttributeList(JSONObject.parseObject(formConfig)); } + @Override + public FormAttributeVo getFormAttribute(JSONObject formConfig, String attributeUuid, String sceneUuid) { + JSONArray tableList = null; + FormAttributeParentVo parent = null; + String uuid = formConfig.getString("uuid"); + if (sceneUuid == null || Objects.equals(sceneUuid, uuid)) { + tableList = formConfig.getJSONArray("tableList"); + } else { + JSONArray sceneList = formConfig.getJSONArray("sceneList"); + for (int i = 0; i < sceneList.size(); i++) { + JSONObject sceneObj = sceneList.getJSONObject(i); + uuid = sceneObj.getString("uuid"); + if (Objects.equals(uuid, sceneUuid)) { + tableList = sceneObj.getJSONArray("tableList"); + parent = new FormAttributeParentVo(uuid, sceneObj.getString("name"), null); + } + } + } + List formAttributeList = getAllFormAttributeList(tableList, parent); + for (FormAttributeVo formAttribute : formAttributeList) { + if (Objects.equals(formAttribute.getUuid(), attributeUuid)) { + return formAttribute; + } + } + return null; + } + @Override public String getFormAttributeHandler(String attributeUuid, JSONObject formConfig) { List formAttributeList = getAllFormAttributeList(formConfig); @@ -759,7 +787,7 @@ public class FormServiceImpl implements FormService, IFormCrossoverService { return getFormAttributeHandler(attributeUuid, JSONObject.parseObject(formConfig)); } - private List getAllFormAttributeList(JSONArray tableList) { + private List getAllFormAttributeList(JSONArray tableList, FormAttributeParentVo parent) { List resultList = new ArrayList<>(); if (CollectionUtils.isEmpty(tableList)) { return resultList; @@ -773,50 +801,65 @@ public class FormServiceImpl implements FormService, IFormCrossoverService { if (MapUtils.isEmpty(componentObj)) { continue; } - // 标签组件不能改变值,不放入组件列表里 - String handler = componentObj.getString("handler"); - if (Objects.equals(FormHandler.FORMLABEL.getHandler(), handler)) { - continue; - } - resultList.add(createFormAttribute(componentObj)); - if (Objects.equals(FormHandler.FORMTABLEINPUTER.getHandler(), handler)) { - JSONObject config = componentObj.getJSONObject("config"); - JSONArray dataConfigList = config.getJSONArray("dataConfig"); - for (int j = 0; j < dataConfigList.size(); j++) { - JSONObject dataObj = dataConfigList.getJSONObject(j); - resultList.add(createFormAttribute(dataObj)); - if (Objects.equals("formtable", dataObj.getString("handler"))) { - JSONObject config2 = dataObj.getJSONObject("config"); - JSONArray dataConfigList2 = config2.getJSONArray("dataConfig"); - for (int k = 0; k < dataConfigList2.size(); k++) { - JSONObject dataObj2 = dataConfigList2.getJSONObject(k); - resultList.add(createFormAttribute(dataObj2)); - } + resultList.addAll(getFormAttributeList(componentObj, parent)); + } + return resultList; + } + + private List getFormAttributeList(JSONObject componentObj, FormAttributeParentVo parent) { + List resultList = new ArrayList<>(); + // 标签组件不能改变值,不放入组件列表里 + String handler = componentObj.getString("handler"); + if (Objects.equals(FormHandler.FORMLABEL.getHandler(), handler)) { + return resultList; + } + FormAttributeVo formAttribute = createFormAttribute(componentObj, parent); + if (formAttribute != null) { + resultList.add(formAttribute); + } + if (Objects.equals(FormHandler.FORMTABLEINPUTER.getHandler(), handler)) { + FormAttributeParentVo parent2 = new FormAttributeParentVo(componentObj.getString("uuid"), componentObj.getString("label"), parent); + JSONObject config = componentObj.getJSONObject("config"); + JSONArray dataConfigList = config.getJSONArray("dataConfig"); + for (int i = 0; i < dataConfigList.size(); i++) { + JSONObject dataObj = dataConfigList.getJSONObject(i); + resultList.addAll(getFormAttributeList(dataObj, parent2)); + if (Objects.equals("formtable", dataObj.getString("handler"))) { + FormAttributeParentVo parent3 = new FormAttributeParentVo(dataObj.getString("uuid"), dataObj.getString("label"), parent2); + JSONObject config2 = dataObj.getJSONObject("config"); + JSONArray dataConfigList2 = config2.getJSONArray("dataConfig"); + for (int j = 0; j < dataConfigList2.size(); j++) { + JSONObject dataObj2 = dataConfigList2.getJSONObject(j); + resultList.addAll(getFormAttributeList(dataObj2, parent3)); } } - } else if (Objects.equals(FormHandler.FORMTABLESELECTOR.getHandler(), handler)) { - JSONObject config = componentObj.getJSONObject("config"); - JSONArray dataConfigList = config.getJSONArray("dataConfig"); - for (int j = 0; j < dataConfigList.size(); j++) { - JSONObject dataObj = dataConfigList.getJSONObject(j); - resultList.add(createFormAttribute(dataObj)); - } - } else if (Objects.equals(FormHandler.FORMSUBASSEMBLY.getHandler(), handler)) { - JSONObject formData = componentObj.getJSONObject("formData"); + } + } else if (Objects.equals(FormHandler.FORMTABLESELECTOR.getHandler(), handler)) { + FormAttributeParentVo parent2 = new FormAttributeParentVo(componentObj.getString("uuid"), componentObj.getString("label"), parent); + JSONObject config = componentObj.getJSONObject("config"); + JSONArray dataConfigList = config.getJSONArray("dataConfig"); + for (int i = 0; i < dataConfigList.size(); i++) { + JSONObject dataObj = dataConfigList.getJSONObject(i); + resultList.addAll(getFormAttributeList(dataObj, parent2)); + } + } else if (Objects.equals(FormHandler.FORMSUBASSEMBLY.getHandler(), handler)) { + FormAttributeParentVo parent2 = new FormAttributeParentVo(componentObj.getString("uuid"), componentObj.getString("label"), parent); + JSONObject formData = componentObj.getJSONObject("formData"); + if (MapUtils.isNotEmpty(formData)) { JSONObject formConfig = formData.getJSONObject("formConfig"); - JSONArray tableList2 = formConfig.getJSONArray("tableList"); - resultList.addAll(getAllFormAttributeList(tableList2)); - } else if (Objects.equals(FormHandler.FORMTAB.getHandler(), handler) || Objects.equals(FormHandler.FORMCOLLAPSE.getHandler(), handler)) { - JSONArray componentArray = componentObj.getJSONArray("component"); - if (CollectionUtils.isNotEmpty(componentArray)) { - for (int j = 0; j < componentArray.size(); j++) { - JSONObject component = componentArray.getJSONObject(j); - if (MapUtils.isNotEmpty(component)) { - FormAttributeVo formAttribute = createFormAttribute(component); - if (formAttribute != null) { - resultList.add(formAttribute); - } - } + if (MapUtils.isNotEmpty(formConfig)) { + JSONArray tableList2 = formConfig.getJSONArray("tableList"); + resultList.addAll(getAllFormAttributeList(tableList2, parent2)); + } + } + } else if (Objects.equals(FormHandler.FORMTAB.getHandler(), handler) || Objects.equals(FormHandler.FORMCOLLAPSE.getHandler(), handler)) { + JSONArray componentArray = componentObj.getJSONArray("component"); + if (CollectionUtils.isNotEmpty(componentArray)) { + FormAttributeParentVo parent2 = new FormAttributeParentVo(componentObj.getString("uuid"), componentObj.getString("label"), parent); + for (int i = 0; i < componentArray.size(); i++) { + JSONObject component = componentArray.getJSONObject(i); + if (MapUtils.isNotEmpty(component)) { + resultList.addAll(getFormAttributeList(component, parent2)); } } } @@ -824,7 +867,7 @@ public class FormServiceImpl implements FormService, IFormCrossoverService { return resultList; } - private FormAttributeVo createFormAttribute(JSONObject componentObj) { + private FormAttributeVo createFormAttribute(JSONObject componentObj, FormAttributeParentVo parent) { String uuid = componentObj.getString("uuid"); if (StringUtils.isBlank(uuid)) { return null; @@ -848,6 +891,7 @@ public class FormServiceImpl implements FormService, IFormCrossoverService { formAttributeVo.setData(defaultValue); formAttributeVo.setConfig(config.toJSONString()); } + formAttributeVo.setParent(parent); return formAttributeVo; } }