diff --git a/src/main/java/neatlogic/framework/form/service/IFormCrossoverService.java b/src/main/java/neatlogic/framework/form/service/IFormCrossoverService.java
index b6f8df4dfb60e49030f3a4f0418f3842fd576ef3..b15f3606c6b03050e143a651ba38807cb3b589f6 100644
--- a/src/main/java/neatlogic/framework/form/service/IFormCrossoverService.java
+++ b/src/main/java/neatlogic/framework/form/service/IFormCrossoverService.java
@@ -15,83 +15,17 @@ along with this program. If not, see .*/
package neatlogic.framework.form.service;
-import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import neatlogic.framework.crossover.ICrossoverService;
import neatlogic.framework.form.dto.AttributeDataVo;
import neatlogic.framework.form.dto.FormAttributeVo;
-import neatlogic.framework.form.dto.FormVersionVo;
-import neatlogic.framework.form.exception.AttributeValidException;
import java.util.List;
public interface IFormCrossoverService extends ICrossoverService {
- /**
- * 保存表单属性与其他功能的引用关系
- * @param formVersion
- */
- void saveDependency(FormVersionVo formVersion);
-
- /**
- * 删除表单属性与其他功能的引用关系
- * @param formVersion
- */
- void deleteDependency(FormVersionVo formVersion);
-
- /**
- * 表格输入组件密码类型加密
- * @param data
- */
- JSONArray staticListPasswordEncrypt(JSONArray data, JSONObject config);
-
- /**
- * 校验表单数据有效性,并针对特殊组件数据进行相应处理,如密码类型组件对数据进行加密处理
- * @param formVersionVo
- * @param formAttributeDataList
- * @throws AttributeValidException
- */
- void formAttributeValueValid(FormVersionVo formVersionVo, JSONArray formAttributeDataList) throws AttributeValidException;
JSONObject getMyDetailedDataForSelectHandler(AttributeDataVo attributeDataVo, JSONObject configObj);
- /**
- * 判断是否修改了表单数据
- * @param formAttributeList 表单属性列表
- * @param newFormAttributeDataList 新的表单属性数据列表
- * @param oldFormAttributeDataList 旧的表单属性数据列表
- * @return
- */
- boolean isModifiedFormData(List formAttributeList,
- List extends AttributeDataVo> newFormAttributeDataList,
- List extends AttributeDataVo> oldFormAttributeDataList);
-
- Object getFormSelectAttributeValueByOriginalValue(Object originalValue);
-
- Object getFormSelectAttributeValueByOriginalValue(Object originalValue, String hiddenField);
-
- /**
- * 根据表单配置信息解析出表单的所有组件列表,包括子表单中的组件
- * @param formConfig
- * @return
- */
- List getAllFormAttributeList(JSONObject formConfig);
-
- /**
- * 根据表单配置信息,表单组件uuid,场景uuid,获取表单组件信息
- * @param formConfig
- * @param attributeUuid
- * @return
- */
- FormAttributeVo getFormAttribute(String formConfig, String attributeUuid);
-
- /**
- * 获取表单组件类型
- * @param attributeUuid 属性唯一标识
- * @param formConfig 表单版本配置信息
- * @return
- */
- String getFormAttributeHandler(String attributeUuid, String formConfig);
-
/**
* 获取表单组件列表
* @param formUuid 表单UUID
diff --git a/src/main/java/neatlogic/framework/util/FormUtil.java b/src/main/java/neatlogic/framework/util/FormUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..59be77c6238ae36657451c963ea55c202cd2cadf
--- /dev/null
+++ b/src/main/java/neatlogic/framework/util/FormUtil.java
@@ -0,0 +1,516 @@
+/*
+ * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package neatlogic.framework.util;
+
+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.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;
+import neatlogic.module.framework.dependency.handler.Matrix2FormAttributeDependencyHandler;
+import neatlogic.module.framework.dependency.handler.MatrixAttr2FormAttrDependencyHandler;
+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.stream.Collectors;
+
+public class FormUtil {
+ /**
+ * 保存表单属性与其他功能的引用关系
+ * @param formVersion
+ */
+ public static void saveDependency(FormVersionVo formVersion) {
+ saveOrDeleteDependency(true, formVersion);
+ }
+
+ /**
+ * 删除表单属性与其他功能的引用关系
+ * @param formVersion
+ */
+ public static void deleteDependency(FormVersionVo formVersion) {
+ saveOrDeleteDependency(false, formVersion);
+ }
+
+ private static void saveOrDeleteDependency(boolean isSave, FormVersionVo formVersion) {
+ JSONObject formConfig = formVersion.getFormConfig();
+ if (MapUtils.isEmpty(formConfig)) {
+ return;
+ }
+ String sceneUuid = formConfig.getString("uuid");
+ doSaveOrDeleteDependency(isSave, formVersion.getFormUuid(), formVersion.getUuid(), sceneUuid, formConfig);
+ }
+
+ private static void doSaveOrDeleteDependency(boolean isSave, String formUuid, String formVersionUuid, String sceneUuid, JSONObject formConfig) {
+ if (MapUtils.isEmpty(formConfig)) {
+ return;
+ }
+ JSONArray tableList = formConfig.getJSONArray("tableList");
+ if (CollectionUtils.isNotEmpty(tableList)) {
+ for (int i = 0; i < tableList.size(); i++) {
+ JSONObject tableObj = tableList.getJSONObject(i);
+ if (MapUtils.isEmpty(tableObj)) {
+ continue;
+ }
+ JSONObject component = tableObj.getJSONObject("component");
+ doSaveOrDeleteComponentDependency(isSave, formUuid, formVersionUuid, sceneUuid, component);
+
+ }
+ }
+ JSONArray sceneList = formConfig.getJSONArray("sceneList");
+ if (CollectionUtils.isNotEmpty(sceneList)) {
+ for (int i = 0; i < sceneList.size(); i++) {
+ JSONObject sceneObj = sceneList.getJSONObject(i);
+ String sceneUuid2 = sceneObj.getString("uuid");
+ doSaveOrDeleteDependency(isSave, formUuid, formVersionUuid, sceneUuid2, sceneObj);
+ }
+ }
+ }
+
+ private static void doSaveOrDeleteComponentDependency(boolean isSave, String formUuid, String formVersionUuid, String sceneUuid, JSONObject component) {
+ if (MapUtils.isEmpty(component)) {
+ return;
+ }
+ Boolean inherit = component.getBoolean("inherit");
+ if (Objects.equals(inherit, true)) {
+ return;
+ }
+ List handlerList = new ArrayList<>();
+ handlerList.add(FormHandler.FORMSELECT.getHandler());
+ handlerList.add(FormHandler.FORMRADIO.getHandler());
+ handlerList.add(FormHandler.FORMCHECKBOX.getHandler());
+ handlerList.add(FormHandler.FORMTABLESELECTOR.getHandler());
+ String handler = component.getString("handler");
+ if (handlerList.contains(handler)) {
+ String uuid = component.getString("uuid");
+ // 单选框、复选框、下拉框、表格选择组件
+ JSONObject config = component.getJSONObject("config");
+ if (MapUtils.isEmpty(config)) {
+ return;
+ }
+ String dataSource = config.getString("dataSource");
+ if (!Objects.equals(dataSource, "matrix")) {
+ return;
+ }
+ String matrixUuid = config.getString("matrixUuid");
+ if (StringUtils.isBlank(matrixUuid)) {
+ return;
+ }
+ if (isSave) {
+ JSONObject dependencyConfig = new JSONObject();
+ dependencyConfig.put("formUuid", formUuid);
+ dependencyConfig.put("formVersionUuid", formVersionUuid);
+ dependencyConfig.put("sceneUuid", sceneUuid);
+ DependencyManager.insert(Matrix2FormAttributeDependencyHandler.class, matrixUuid, uuid, dependencyConfig);
+
+ dependencyConfig.put("matrixUuid", matrixUuid);
+ if (Objects.equals(handler, FormHandler.FORMTABLESELECTOR.getHandler())) {
+ JSONArray dataConfig = config.getJSONArray("dataConfig");
+ if (CollectionUtils.isEmpty(dataConfig)) {
+ return;
+ }
+ for (int i = 0; i < dataConfig.size(); i++) {
+ JSONObject dataObj = dataConfig.getJSONObject(i);
+ if (MapUtils.isEmpty(dataObj)) {
+ continue;
+ }
+ String columnUuid = dataObj.getString("uuid");
+ if (StringUtils.isBlank(columnUuid)) {
+ continue;
+ }
+ DependencyManager.insert(MatrixAttr2FormAttrDependencyHandler.class, columnUuid, uuid, dependencyConfig);
+ }
+ } else {
+ JSONObject mapping = config.getJSONObject("mapping");
+ if (MapUtils.isEmpty(mapping)) {
+ return;
+ }
+ String value = mapping.getString("value");
+ String text = mapping.getString("text");
+ if (StringUtils.isNotBlank(value)) {
+ DependencyManager.insert(MatrixAttr2FormAttrDependencyHandler.class, value, uuid, dependencyConfig);
+ }
+ if (StringUtils.isNotBlank(text)) {
+ DependencyManager.insert(MatrixAttr2FormAttrDependencyHandler.class, text, uuid, dependencyConfig);
+ }
+ }
+ } else {
+ DependencyManager.delete(Matrix2FormAttributeDependencyHandler.class, uuid);
+ DependencyManager.delete(MatrixAttr2FormAttrDependencyHandler.class, uuid);
+ }
+ } else if (Objects.equals(handler, FormHandler.FORMTABLEINPUTER.getHandler())) {
+ // 表格输入组件
+ JSONObject config = component.getJSONObject("config");
+ if (MapUtils.isEmpty(config)) {
+ return;
+ }
+ JSONArray dataConfig = config.getJSONArray("dataConfig");
+ for (int i = 0; i < dataConfig.size(); i++) {
+ JSONObject dataObj = dataConfig.getJSONObject(i);
+ if (Objects.equals(dataObj.getString("handler"), "formtable")) {
+ JSONObject config1 = dataObj.getJSONObject("config");
+ if (MapUtils.isEmpty(config1)) {
+ continue;
+ }
+ JSONArray dataConfig1 = config1.getJSONArray("dataConfig");
+ for (int j = 0; j < dataConfig1.size(); j++) {
+ JSONObject dataObj1 = dataConfig1.getJSONObject(j);
+ doSaveOrDeleteComponentDependency(isSave, formUuid, formVersionUuid, sceneUuid, dataObj1);
+ }
+ } else {
+ doSaveOrDeleteComponentDependency(isSave, formUuid, formVersionUuid, sceneUuid, dataObj);
+ }
+ }
+ } else if (Objects.equals(handler, FormHandler.FORMTAB.getHandler()) || Objects.equals(handler, FormHandler.FORMCOLLAPSE.getHandler())) {
+ // 选项卡、折叠面板
+ JSONArray componentArray = component.getJSONArray("component");
+ for (int i = 0; i < componentArray.size(); i++) {
+ JSONObject componentObj = componentArray.getJSONObject(i);
+ doSaveOrDeleteComponentDependency(isSave, formUuid, formVersionUuid, sceneUuid, componentObj);
+ }
+ } else if (Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) {
+ // 子表单
+ JSONObject formData = component.getJSONObject("formData");
+ if (MapUtils.isEmpty(formData)) {
+ return;
+ }
+ JSONObject formConfig = formData.getJSONObject("formConfig");
+ doSaveOrDeleteDependency(isSave, formUuid, formVersionUuid, sceneUuid, formConfig);
+ }
+ }
+
+ /**
+ * 校验表单数据有效性,并针对特殊组件数据进行相应处理,如密码类型组件对数据进行加密处理
+ * @param formVersionVo
+ * @param formAttributeDataList
+ * @throws AttributeValidException
+ */
+ public static void formAttributeValueValid(FormVersionVo formVersionVo, JSONArray formAttributeDataList) throws AttributeValidException {
+ if (formVersionVo == null) {
+ return;
+ }
+ List formAttributeList = formVersionVo.getFormAttributeList();
+ if (CollectionUtils.isEmpty(formAttributeList)) {
+ return;
+ }
+ Map formAttributeMap = formAttributeList.stream().collect(Collectors.toMap(FormAttributeVo::getUuid, e -> e));
+ for (int i = 0; i < formAttributeDataList.size(); i++) {
+ JSONObject formAttributeDataObj = formAttributeDataList.getJSONObject(i);
+ String attributeUuid = formAttributeDataObj.getString("attributeUuid");
+ FormAttributeVo formAttributeVo = formAttributeMap.get(attributeUuid);
+ if (formAttributeVo == null) {
+ continue;
+ }
+ IFormAttributeHandler formAttributeHandler = FormAttributeHandlerFactory.getHandler(formAttributeVo.getHandler());
+ if (formAttributeHandler == null) {
+ continue;
+ }
+ Object dataList = formAttributeHandler.conversionDataType(formAttributeDataObj.get("dataList"), formAttributeVo.getLabel());
+ formAttributeDataObj.put("dataList", dataList);
+ }
+ }
+
+ /**
+ * 判断是否修改了表单数据
+ * @param formAttributeList 表单属性列表
+ * @param newFormAttributeDataList 新的表单属性数据列表
+ * @param oldFormAttributeDataList 旧的表单属性数据列表
+ * @return
+ */
+ public static boolean isModifiedFormData(List formAttributeList,
+ List extends AttributeDataVo> newFormAttributeDataList,
+ List extends AttributeDataVo> oldFormAttributeDataList) {
+ boolean isModified = false;
+ Map newFormAttributeDataMap = newFormAttributeDataList.stream().collect(Collectors.toMap(AttributeDataVo::getAttributeUuid, e -> e));
+ Map oldFormAttributeDataMap = oldFormAttributeDataList.stream().collect(Collectors.toMap(AttributeDataVo::getAttributeUuid, e -> e));
+ for (FormAttributeVo formAttributeVo : formAttributeList) {
+ String attributeUuid = formAttributeVo.getUuid();
+ AttributeDataVo newProcessTaskFormAttributeDataVo = newFormAttributeDataMap.get(attributeUuid);
+ AttributeDataVo oldProcessTaskFormAttributeDataVo = oldFormAttributeDataMap.get(attributeUuid);
+ if (oldProcessTaskFormAttributeDataVo == null && newProcessTaskFormAttributeDataVo == null) {
+ continue;
+ }
+ // 在此之前如果该属性的值,在数据库中没有对应的旧数据
+ if (oldProcessTaskFormAttributeDataVo == null) {
+ if (newProcessTaskFormAttributeDataVo.getDataObj() != null) {
+ // 现在要保存该属性的值不为null,则将该属性值保存到数据库中,但标记为已修改
+ isModified = true;
+ }
+ } else if (newProcessTaskFormAttributeDataVo == null) {
+ // 如果现在接口参数中没有该属性值,则表示不修改该属性值
+ } else if (!Objects.equals(oldProcessTaskFormAttributeDataVo.getDataObj(), newProcessTaskFormAttributeDataVo.getDataObj())) {
+ isModified = true;
+ }
+ }
+ return isModified;
+ }
+
+ /**
+ * 获取表单下拉框组件value值
+ * @param originalValue 原始值,json对象
+ * @return
+ */
+ public static Object getFormSelectAttributeValueByOriginalValue(Object originalValue) {
+ return getFormSelectAttributeValueByOriginalValue(originalValue, "value");
+ }
+
+ /**
+ * 获取表单下拉框组件value或隐藏属性值
+ * @param originalValue 原始值,json对象
+ * @param hiddenField 隐藏属性key
+ * @return
+ */
+ public static Object getFormSelectAttributeValueByOriginalValue(Object originalValue, String hiddenField) {
+ if (originalValue == null) {
+ return null;
+ }
+ if (originalValue instanceof JSONArray) {
+ JSONArray valueList = new JSONArray();
+ JSONArray originalValueArray = (JSONArray) originalValue;
+ for (int i = 0; i < originalValueArray.size(); i++) {
+ Object originalValueObject = originalValueArray.get(i);
+ if (originalValueObject instanceof JSONObject) {
+ JSONObject originalValueObj = (JSONObject) originalValueObject;
+ Object value = originalValueObj.get(hiddenField);
+ if (value != null) {
+ valueList.add(value);
+ }
+ } else {
+ valueList.add(originalValueObject);
+ }
+ }
+ return valueList;
+ } else if (originalValue instanceof JSONObject) {
+ JSONObject originalValueObj = (JSONObject) originalValue;
+ return originalValueObj.get(hiddenField);
+ }
+ return originalValue;
+ }
+
+ /**
+ * 根据表单配置信息解析出表单的所有组件列表,包括子表单中的组件
+ * @param formConfig
+ * @return
+ */
+ public static List getAllFormAttributeList(JSONObject formConfig) {
+ JSONArray tableList = formConfig.getJSONArray("tableList");
+ return getAllFormAttributeList(tableList, null);
+ }
+
+ /**
+ * 根据表单配置信息解析出表单的所有组件列表,包括子表单中的组件
+ * @param formConfig
+ * @return
+ */
+ public static List getAllFormAttributeList(String formConfig) {
+ return getAllFormAttributeList(JSON.parseObject(formConfig));
+ }
+
+ /**
+ * 根据表单配置信息,表单组件uuid,场景uuid,获取表单组件信息
+ * @param formConfig
+ * @param attributeUuid
+ * @param sceneUuid
+ * @return
+ */
+ public static 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;
+ }
+
+ /**
+ * 根据表单配置信息,表单组件uuid,场景uuid,获取表单组件信息
+ * @param formConfig
+ * @param attributeUuid
+ * @return
+ */
+ public static FormAttributeVo getFormAttribute(String formConfig, String attributeUuid) {
+ return getFormAttribute(JSON.parseObject(formConfig), attributeUuid, null);
+ }
+
+ /**
+ * 获取表单组件类型
+ * @param attributeUuid 属性唯一标识
+ * @param formConfig 表单版本配置信息
+ * @return
+ */
+ public static String getFormAttributeHandler(String attributeUuid, JSONObject formConfig) {
+ List formAttributeList = getAllFormAttributeList(formConfig);
+ for (FormAttributeVo formAttributeVo : formAttributeList) {
+ if (Objects.equals(formAttributeVo.getUuid(), attributeUuid)) {
+ return formAttributeVo.getHandler();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 获取表单组件类型
+ * @param attributeUuid 属性唯一标识
+ * @param formConfig 表单版本配置信息
+ * @return
+ */
+ public static String getFormAttributeHandler(String attributeUuid, String formConfig) {
+ return getFormAttributeHandler(attributeUuid, JSON.parseObject(formConfig));
+ }
+
+ private static List getAllFormAttributeList(JSONArray tableList, FormAttributeParentVo parent) {
+ List resultList = new ArrayList<>();
+ if (CollectionUtils.isEmpty(tableList)) {
+ return resultList;
+ }
+ for (int i = 0; i < tableList.size(); i++) {
+ JSONObject cellObj = tableList.getJSONObject(i);
+ if (MapUtils.isEmpty(cellObj)) {
+ continue;
+ }
+ JSONObject componentObj = cellObj.getJSONObject("component");
+ if (MapUtils.isEmpty(componentObj)) {
+ continue;
+ }
+ resultList.addAll(getFormAttributeList(componentObj, parent));
+ }
+ return resultList;
+ }
+
+ private static 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");
+ if (MapUtils.isNotEmpty(config2)) {
+ JSONArray dataConfigList2 = config2.getJSONArray("dataConfig");
+ if (CollectionUtils.isNotEmpty(dataConfigList2)) {
+ 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)) {
+ 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");
+ if (MapUtils.isNotEmpty(formConfig)) {
+ JSONArray tableList2 = formConfig.getJSONArray("tableList");
+ resultList.addAll(getAllFormAttributeList(tableList2, parent2));
+ }
+ }
+ } else {
+ 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));
+ }
+ }
+ }
+ }
+ return resultList;
+ }
+
+ private static FormAttributeVo createFormAttribute(JSONObject componentObj, FormAttributeParentVo parent) {
+ String uuid = componentObj.getString("uuid");
+ if (StringUtils.isBlank(uuid)) {
+ return null;
+ }
+ String handler = componentObj.getString("handler");
+ if (StringUtils.isBlank(handler)) {
+ return null;
+ }
+ FormAttributeVo formAttributeVo = new FormAttributeVo();
+ formAttributeVo.setUuid(uuid);
+ formAttributeVo.setHandler(handler);
+ String label = componentObj.getString("label");
+ formAttributeVo.setLabel(label);
+ String type = componentObj.getString("type");
+ formAttributeVo.setType(type);
+ JSONObject config = componentObj.getJSONObject("config");
+ if (MapUtils.isNotEmpty(config)) {
+ boolean isRequired = config.getBooleanValue("isRequired");
+ formAttributeVo.setRequired(isRequired);
+ String defaultValue = config.getString("defaultValue");
+ formAttributeVo.setData(defaultValue);
+ formAttributeVo.setConfig(config);
+ }
+ formAttributeVo.setParent(parent);
+ return formAttributeVo;
+ }
+
+}
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 0f03de5416d52820274a7f108900104f4abee9cd..0764dca7d876dea8b5602dd8c2b8f7d523cea1b4 100644
--- a/src/main/java/neatlogic/module/framework/dependency/handler/Matrix2FormAttributeDependencyHandler.java
+++ b/src/main/java/neatlogic/module/framework/dependency/handler/Matrix2FormAttributeDependencyHandler.java
@@ -12,7 +12,7 @@ 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 neatlogic.framework.util.FormUtil;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
@@ -27,9 +27,6 @@ public class Matrix2FormAttributeDependencyHandler extends FixedTableDependencyH
@Resource
private FormMapper formMapper;
- @Resource
- private FormService formService;
-
@Override
protected DependencyInfoVo parse(DependencyVo dependencyVo) {
JSONObject config = dependencyVo.getConfig();
@@ -56,7 +53,7 @@ public class Matrix2FormAttributeDependencyHandler extends FixedTableDependencyH
pathList.add(formVo.getName());
pathList.add(formVersionVo.getVersion().toString());
String sceneUuid = config.getString("sceneUuid");
- FormAttributeVo formAttribute = formService.getFormAttribute(formVersionVo.getFormConfig(), dependencyVo.getTo(), sceneUuid);
+ FormAttributeVo formAttribute = FormUtil.getFormAttribute(formVersionVo.getFormConfig(), dependencyVo.getTo(), sceneUuid);
if (formAttribute == null) {
return null;
}
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 985ddd84388c0afaffb13072477380c36370699b..1317360c21454bbcd73d106ad498a70b3308b40a 100644
--- a/src/main/java/neatlogic/module/framework/form/service/FormService.java
+++ b/src/main/java/neatlogic/module/framework/form/service/FormService.java
@@ -19,97 +19,26 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import neatlogic.framework.form.dto.AttributeDataVo;
import neatlogic.framework.form.dto.FormAttributeVo;
-import neatlogic.framework.form.dto.FormVersionVo;
-import neatlogic.framework.form.exception.AttributeValidException;
import java.util.List;
public interface FormService {
- /**
- * 保存表单属性与其他功能的引用关系
- * @param formVersion
- */
- void saveDependency(FormVersionVo formVersion);
-
- /**
- * 删除表单属性与其他功能的引用关系
- * @param formVersion
- */
- void deleteDependency(FormVersionVo formVersion);
-
- /**
- * 表格输入组件密码类型加密
- * @param data
- */
- JSONArray staticListPasswordEncrypt(JSONArray data, JSONObject config);
-
- JSONArray textConversionValueForSelectHandler(Object text, JSONObject config);
/**
- * 校验表单数据有效性,并针对特殊组件数据进行相应处理,如密码类型组件对数据进行加密处理
- * @param formVersionVo
- * @param formAttributeDataList
- * @throws AttributeValidException
- */
- void formAttributeValueValid(FormVersionVo formVersionVo, JSONArray formAttributeDataList) throws AttributeValidException;
-
- JSONObject getMyDetailedDataForSelectHandler(AttributeDataVo attributeDataVo, JSONObject configObj);
-
- /**
- * 判断是否修改了表单数据
- * @param formAttributeList 表单属性列表
- * @param newFormAttributeDataList 新的表单属性数据列表
- * @param oldFormAttributeDataList 旧的表单属性数据列表
+ * 表单下拉框通过text值查找value值
+ * @param text
+ * @param config
* @return
*/
- boolean isModifiedFormData(List formAttributeList,
- List extends AttributeDataVo> newFormAttributeDataList,
- List extends AttributeDataVo> oldFormAttributeDataList);
-
- /**
- * 根据表单配置信息解析出表单的所有组件列表,包括子表单中的组件
- * @param formConfig
- * @return
- */
- List getAllFormAttributeList(JSONObject formConfig);
-
- /**
- * 根据表单配置信息解析出表单的所有组件列表,包括子表单中的组件
- * @param formConfig
- * @return
- */
- List getAllFormAttributeList(String formConfig);
-
- /**
- * 根据表单配置信息,表单组件uuid,场景uuid,获取表单组件信息
- * @param formConfig
- * @param attributeUuid
- * @param sceneUuid
- * @return
- */
- FormAttributeVo getFormAttribute(JSONObject formConfig, String attributeUuid, String sceneUuid);
+ JSONArray textConversionValueForSelectHandler(Object text, JSONObject config);
/**
- * 根据表单配置信息,表单组件uuid,场景uuid,获取表单组件信息
- * @param formConfig
- * @param attributeUuid
- * @return
- */
- FormAttributeVo getFormAttribute(String formConfig, String attributeUuid);
- /**
- * 获取表单组件类型
- * @param attributeUuid 属性唯一标识
- * @param formConfig 表单版本配置信息
+ * 表单下拉框通过原始数据获取详细数据
+ * @param attributeDataVo
+ * @param configObj
* @return
*/
- String getFormAttributeHandler(String attributeUuid, JSONObject formConfig);
- /**
- * 获取表单组件类型
- * @param attributeUuid 属性唯一标识
- * @param formConfig 表单版本配置信息
- * @return
- */
- String getFormAttributeHandler(String attributeUuid, String formConfig);
+ JSONObject getMyDetailedDataForSelectHandler(AttributeDataVo attributeDataVo, JSONObject configObj);
/**
* 获取表单组件列表
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 90d7d81fbdbc71d7b11e3302f5de30dcd6f1eb50..798b725564c6d0f515d4a3d293b9afd0a02f7a96 100644
--- a/src/main/java/neatlogic/module/framework/form/service/FormServiceImpl.java
+++ b/src/main/java/neatlogic/module/framework/form/service/FormServiceImpl.java
@@ -15,20 +15,13 @@ along with this program. If not, see .*/
package neatlogic.module.framework.form.service;
-import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import neatlogic.framework.common.dto.ValueTextVo;
-import neatlogic.framework.dependency.core.DependencyManager;
-import neatlogic.framework.form.attribute.core.FormAttributeHandlerFactory;
-import neatlogic.framework.form.attribute.core.IFormAttributeHandler;
-import neatlogic.framework.form.constvalue.FormHandler;
import neatlogic.framework.form.dao.mapper.FormMapper;
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;
import neatlogic.framework.form.exception.FormActiveVersionNotFoundExcepiton;
import neatlogic.framework.form.service.IFormCrossoverService;
import neatlogic.framework.matrix.constvalue.SearchExpression;
@@ -42,8 +35,6 @@ import neatlogic.framework.matrix.dto.MatrixKeywordFilterVo;
import neatlogic.framework.matrix.dto.MatrixVo;
import neatlogic.framework.matrix.exception.MatrixDataSourceHandlerNotFoundException;
import neatlogic.framework.matrix.exception.MatrixNotFoundException;
-import neatlogic.module.framework.dependency.handler.Matrix2FormAttributeDependencyHandler;
-import neatlogic.module.framework.dependency.handler.MatrixAttr2FormAttrDependencyHandler;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
@@ -68,278 +59,6 @@ public class FormServiceImpl implements FormService, IFormCrossoverService {
@Resource
private MatrixMapper matrixMapper;
- @Override
- public void saveDependency(FormVersionVo formVersion) {
- saveOrDeleteDependency(true, formVersion);
- }
-
- @Override
- public void deleteDependency(FormVersionVo formVersion) {
- saveOrDeleteDependency(false, formVersion);
- }
-
- private void saveOrDeleteDependency(boolean isSave, FormVersionVo formVersion) {
- JSONObject formConfig = formVersion.getFormConfig();
- if (MapUtils.isEmpty(formConfig)) {
- return;
- }
- String sceneUuid = formConfig.getString("uuid");
- doSaveOrDeleteDependency(isSave, formVersion.getFormUuid(), formVersion.getUuid(), sceneUuid, formConfig);
- }
-
- private void doSaveOrDeleteDependency(boolean isSave, String formUuid, String formVersionUuid, String sceneUuid, JSONObject formConfig) {
- if (MapUtils.isEmpty(formConfig)) {
- return;
- }
- JSONArray tableList = formConfig.getJSONArray("tableList");
- if (CollectionUtils.isNotEmpty(tableList)) {
- for (int i = 0; i < tableList.size(); i++) {
- JSONObject tableObj = tableList.getJSONObject(i);
- if (MapUtils.isEmpty(tableObj)) {
- continue;
- }
- JSONObject component = tableObj.getJSONObject("component");
- doSaveOrDeleteComponentDependency(isSave, formUuid, formVersionUuid, sceneUuid, component);
-
- }
- }
- JSONArray sceneList = formConfig.getJSONArray("sceneList");
- if (CollectionUtils.isNotEmpty(sceneList)) {
- for (int i = 0; i < sceneList.size(); i++) {
- JSONObject sceneObj = sceneList.getJSONObject(i);
- String sceneUuid2 = sceneObj.getString("uuid");
- doSaveOrDeleteDependency(isSave, formUuid, formVersionUuid, sceneUuid2, sceneObj);
- }
- }
- }
-
- private void doSaveOrDeleteComponentDependency(boolean isSave, String formUuid, String formVersionUuid, String sceneUuid, JSONObject component) {
- if (MapUtils.isEmpty(component)) {
- return;
- }
- Boolean inherit = component.getBoolean("inherit");
- if (Objects.equals(inherit, true)) {
- return;
- }
- List handlerList = new ArrayList<>();
- handlerList.add(FormHandler.FORMSELECT.getHandler());
- handlerList.add(FormHandler.FORMRADIO.getHandler());
- handlerList.add(FormHandler.FORMCHECKBOX.getHandler());
- handlerList.add(FormHandler.FORMTABLESELECTOR.getHandler());
- String handler = component.getString("handler");
- if (handlerList.contains(handler)) {
- String uuid = component.getString("uuid");
- // 单选框、复选框、下拉框、表格选择组件
- JSONObject config = component.getJSONObject("config");
- if (MapUtils.isEmpty(config)) {
- return;
- }
- String dataSource = config.getString("dataSource");
- if (!Objects.equals(dataSource, "matrix")) {
- return;
- }
- String matrixUuid = config.getString("matrixUuid");
- if (StringUtils.isBlank(matrixUuid)) {
- return;
- }
- if (isSave) {
- JSONObject dependencyConfig = new JSONObject();
- dependencyConfig.put("formUuid", formUuid);
- dependencyConfig.put("formVersionUuid", formVersionUuid);
- dependencyConfig.put("sceneUuid", sceneUuid);
- DependencyManager.insert(Matrix2FormAttributeDependencyHandler.class, matrixUuid, uuid, dependencyConfig);
-
- dependencyConfig.put("matrixUuid", matrixUuid);
- if (Objects.equals(handler, FormHandler.FORMTABLESELECTOR.getHandler())) {
- JSONArray dataConfig = config.getJSONArray("dataConfig");
- if (CollectionUtils.isEmpty(dataConfig)) {
- return;
- }
- for (int i = 0; i < dataConfig.size(); i++) {
- JSONObject dataObj = dataConfig.getJSONObject(i);
- if (MapUtils.isEmpty(dataObj)) {
- continue;
- }
- String columnUuid = dataObj.getString("uuid");
- if (StringUtils.isBlank(columnUuid)) {
- continue;
- }
- DependencyManager.insert(MatrixAttr2FormAttrDependencyHandler.class, columnUuid, uuid, dependencyConfig);
- }
- } else {
- JSONObject mapping = config.getJSONObject("mapping");
- if (MapUtils.isEmpty(mapping)) {
- return;
- }
- String value = mapping.getString("value");
- String text = mapping.getString("text");
- if (StringUtils.isNotBlank(value)) {
- DependencyManager.insert(MatrixAttr2FormAttrDependencyHandler.class, value, uuid, dependencyConfig);
- }
- if (StringUtils.isNotBlank(text)) {
- DependencyManager.insert(MatrixAttr2FormAttrDependencyHandler.class, text, uuid, dependencyConfig);
- }
- }
- } else {
- DependencyManager.delete(Matrix2FormAttributeDependencyHandler.class, uuid);
- DependencyManager.delete(MatrixAttr2FormAttrDependencyHandler.class, uuid);
- }
- } else if (Objects.equals(handler, FormHandler.FORMTABLEINPUTER.getHandler())) {
- // 表格输入组件
- JSONObject config = component.getJSONObject("config");
- if (MapUtils.isEmpty(config)) {
- return;
- }
- JSONArray dataConfig = config.getJSONArray("dataConfig");
- for (int i = 0; i < dataConfig.size(); i++) {
- JSONObject dataObj = dataConfig.getJSONObject(i);
- if (Objects.equals(dataObj.getString("handler"), "formtable")) {
- JSONObject config1 = dataObj.getJSONObject("config");
- if (MapUtils.isEmpty(config1)) {
- continue;
- }
- JSONArray dataConfig1 = config1.getJSONArray("dataConfig");
- for (int j = 0; j < dataConfig1.size(); j++) {
- JSONObject dataObj1 = dataConfig1.getJSONObject(j);
- doSaveOrDeleteComponentDependency(isSave, formUuid, formVersionUuid, sceneUuid, dataObj1);
- }
- } else {
- doSaveOrDeleteComponentDependency(isSave, formUuid, formVersionUuid, sceneUuid, dataObj);
- }
- }
- } else if (Objects.equals(handler, FormHandler.FORMTAB.getHandler()) || Objects.equals(handler, FormHandler.FORMCOLLAPSE.getHandler())) {
- // 选项卡、折叠面板
- JSONArray componentArray = component.getJSONArray("component");
- for (int i = 0; i < componentArray.size(); i++) {
- JSONObject componentObj = componentArray.getJSONObject(i);
- doSaveOrDeleteComponentDependency(isSave, formUuid, formVersionUuid, sceneUuid, componentObj);
- }
- } else if (Objects.equals(handler, FormHandler.FORMSUBASSEMBLY.getHandler())) {
- // 子表单
- JSONObject formData = component.getJSONObject("formData");
- if (MapUtils.isEmpty(formData)) {
- return;
- }
- JSONObject formConfig = formData.getJSONObject("formConfig");
- doSaveOrDeleteDependency(isSave, formUuid, formVersionUuid, sceneUuid, formConfig);
- }
- }
-
- @Override
- public JSONArray staticListPasswordEncrypt(JSONArray data, JSONObject config) {
- if (CollectionUtils.isEmpty(data)) {
- return data;
- }
- List passwordTypeAttributeUuidList = new ArrayList<>();
- List tableTypeAttributeUuidList = new ArrayList<>();
- JSONArray attributeList = config.getJSONArray("attributeList");
- if (CollectionUtils.isEmpty(attributeList)) {
- return data;
- }
- for (int i = 0; i < attributeList.size(); i++) {
- JSONObject attributeObj = attributeList.getJSONObject(i);
- if (MapUtils.isEmpty(attributeObj)) {
- continue;
- }
- String attributeUuid = attributeObj.getString("attributeUuid");
- String type = attributeObj.getString("type");
- if (Objects.equals(type, "password")) {
- passwordTypeAttributeUuidList.add(attributeUuid);
- } else if (Objects.equals(type, "table")) {
- tableTypeAttributeUuidList.add(attributeUuid);
- JSONObject attrConfig = attributeObj.getJSONObject("attrConfig");
- if (MapUtils.isEmpty(attrConfig)) {
- continue;
- }
- JSONArray attributeArray = attrConfig.getJSONArray("attributeList");
- if (CollectionUtils.isEmpty(attributeArray)) {
- continue;
- }
- for (int j = 0; j < attributeArray.size(); j++) {
- JSONObject attributeObject = attributeArray.getJSONObject(j);
- if (MapUtils.isEmpty(attributeObject)) {
- continue;
- }
- String attrUuid = attributeObject.getString("attributeUuid");
- if (Objects.equals(attributeObject.getString("type"), "password")) {
- passwordTypeAttributeUuidList.add(attrUuid);
- }
- }
- }
- }
-// JSONObject extendedData = data.getJSONObject("extendedData");
-// if (MapUtils.isNotEmpty(extendedData)) {
-// for (Map.Entry entry : extendedData.entrySet()) {
-// JSONObject rowDataObj = (JSONObject) entry.getValue();
-// for (String key : rowDataObj.keySet()) {
-// if (passwordTypeAttributeUuidList.contains(key)) {
-// String value = rowDataObj.getString(key);
-// if (StringUtils.isNotBlank(value)) {
-// rowDataObj.put(key, RC4Util.encrypt(value));
-// }
-// } else if (tableTypeAttributeUuidList.contains(key)) {
-// JSONObject tableDataObj = rowDataObj.getJSONObject(key);
-// for (Map.Entry tableEntry : tableDataObj.entrySet()) {
-// JSONObject tableRowDataObj = (JSONObject) tableEntry.getValue();
-// List keyList = new ArrayList<>(tableRowDataObj.keySet());
-// for (String tableRowKey : keyList) {
-// if (passwordTypeAttributeUuidList.contains(tableRowKey)) {
-// String value = tableRowDataObj.getString(tableRowKey);
-// if (StringUtils.isNotBlank(value)) {
-// tableRowDataObj.put(tableRowKey, RC4Util.encrypt(value));
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// JSONObject detailData = data.getJSONObject("detailData");
-// if (MapUtils.isNotEmpty(detailData)) {
-// for (Map.Entry entry : detailData.entrySet()) {
-// JSONObject rowDataObj = (JSONObject) entry.getValue();
-// for (String key : rowDataObj.keySet()) {
-// if (passwordTypeAttributeUuidList.contains(key)) {
-// JSONObject valueObj = rowDataObj.getJSONObject(key);
-// if (MapUtils.isNotEmpty(valueObj)) {
-// String value = valueObj.getString("value");
-// if (StringUtils.isNotBlank(value)) {
-// valueObj.put("value", RC4Util.encrypt(value));
-// }
-// String text = valueObj.getString("text");
-// if (StringUtils.isNotBlank(text)) {
-// valueObj.put("text", RC4Util.encrypt(text));
-// }
-// }
-// } else if (tableTypeAttributeUuidList.contains(key)) {
-// JSONObject tableDataObj = rowDataObj.getJSONObject(key);
-// tableDataObj = tableDataObj.getJSONObject("value");
-// for (Map.Entry tableEntry : tableDataObj.entrySet()) {
-// JSONObject tableRowDataObj = (JSONObject) tableEntry.getValue();
-// for (String tableRowKey : tableRowDataObj.keySet()) {
-// if (passwordTypeAttributeUuidList.contains(tableRowKey)) {
-// JSONObject valueObj = tableRowDataObj.getJSONObject(tableRowKey);
-// if (MapUtils.isNotEmpty(valueObj)) {
-// String value = valueObj.getString("value");
-// if (StringUtils.isNotBlank(value)) {
-// valueObj.put("value", RC4Util.encrypt(value));
-// }
-// String text = valueObj.getString("text");
-// if (StringUtils.isNotBlank(text)) {
-// valueObj.put("text", RC4Util.encrypt(text));
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// }
-// }
- return data;
- }
-
@Override
public JSONArray textConversionValueForSelectHandler(Object text, JSONObject config) {
JSONArray valueList = new JSONArray();
@@ -434,38 +153,6 @@ public class FormServiceImpl implements FormService, IFormCrossoverService {
return null;
}
- @Override
- public void formAttributeValueValid(FormVersionVo formVersionVo, JSONArray formAttributeDataList) throws AttributeValidException {
- if (formVersionVo == null) {
- return;
- }
- List formAttributeList = formVersionVo.getFormAttributeList();
- if (CollectionUtils.isEmpty(formAttributeList)) {
- return;
- }
- Map formAttributeMap = formAttributeList.stream().collect(Collectors.toMap(FormAttributeVo::getUuid, e -> e));
- for (int i = 0; i < formAttributeDataList.size(); i++) {
- JSONObject formAttributeDataObj = formAttributeDataList.getJSONObject(i);
- String attributeUuid = formAttributeDataObj.getString("attributeUuid");
- FormAttributeVo formAttributeVo = formAttributeMap.get(attributeUuid);
- if (formAttributeVo == null) {
- continue;
- }
- IFormAttributeHandler formAttributeHandler = FormAttributeHandlerFactory.getHandler(formAttributeVo.getHandler());
- if (formAttributeHandler == null) {
- continue;
- }
- Object dataList = formAttributeHandler.conversionDataType(formAttributeDataObj.get("dataList"), formAttributeVo.getLabel());
- formAttributeDataObj.put("dataList", dataList);
-// AttributeDataVo attributeDataVo = new AttributeDataVo();
-// attributeDataVo.setAttributeUuid(formAttributeVo.getUuid());
-// attributeDataVo.setAttributeLabel(formAttributeVo.getLabel());
-// attributeDataVo.setDataObj(formAttributeDataObj.get("dataList"));
-// formAttributeHandler.valid(attributeDataVo, formAttributeVo.getConfigObj());
-// formAttributeDataObj.put("dataList", attributeDataVo.getDataObj());
- }
- }
-
@Override
public JSONObject getMyDetailedDataForSelectHandler(AttributeDataVo attributeDataVo, JSONObject configObj) {
JSONObject resultObj = new JSONObject();
@@ -605,68 +292,6 @@ public class FormServiceImpl implements FormService, IFormCrossoverService {
return resultObj;
}
- @Override
- public boolean isModifiedFormData(List formAttributeList,
- List extends AttributeDataVo> newFormAttributeDataList,
- List extends AttributeDataVo> oldFormAttributeDataList) {
- boolean isModified = false;
- Map newFormAttributeDataMap = newFormAttributeDataList.stream().collect(Collectors.toMap(AttributeDataVo::getAttributeUuid, e -> e));
- Map oldFormAttributeDataMap = oldFormAttributeDataList.stream().collect(Collectors.toMap(AttributeDataVo::getAttributeUuid, e -> e));
- for (FormAttributeVo formAttributeVo : formAttributeList) {
- String attributeUuid = formAttributeVo.getUuid();
- AttributeDataVo newProcessTaskFormAttributeDataVo = newFormAttributeDataMap.get(attributeUuid);
- AttributeDataVo oldProcessTaskFormAttributeDataVo = oldFormAttributeDataMap.get(attributeUuid);
- if (oldProcessTaskFormAttributeDataVo == null && newProcessTaskFormAttributeDataVo == null) {
- continue;
- }
- // 在此之前如果该属性的值,在数据库中没有对应的旧数据
- if (oldProcessTaskFormAttributeDataVo == null) {
- if (newProcessTaskFormAttributeDataVo.getDataObj() != null) {
- // 现在要保存该属性的值不为null,则将该属性值保存到数据库中,但标记为已修改
- isModified = true;
- }
- } else if (newProcessTaskFormAttributeDataVo == null) {
- // 如果现在接口参数中没有该属性值,则表示不修改该属性值
- } else if (!Objects.equals(oldProcessTaskFormAttributeDataVo.getDataObj(), newProcessTaskFormAttributeDataVo.getDataObj())) {
- isModified = true;
- }
- }
- return isModified;
- }
-
- @Override
- public Object getFormSelectAttributeValueByOriginalValue(Object originalValue) {
- return getFormSelectAttributeValueByOriginalValue(originalValue, "value");
- }
-
- @Override
- public Object getFormSelectAttributeValueByOriginalValue(Object originalValue, String hiddenField) {
- if (originalValue == null) {
- return null;
- }
- if (originalValue instanceof JSONArray) {
- JSONArray valueList = new JSONArray();
- JSONArray originalValueArray = (JSONArray) originalValue;
- for (int i = 0; i < originalValueArray.size(); i++) {
- Object originalValueObject = originalValueArray.get(i);
- if (originalValueObject instanceof JSONObject) {
- JSONObject originalValueObj = (JSONObject) originalValueObject;
- Object value = originalValueObj.get(hiddenField);
- if (value != null) {
- valueList.add(value);
- }
- } else {
- valueList.add(originalValueObject);
- }
- }
- return valueList;
- } else if (originalValue instanceof JSONObject) {
- JSONObject originalValueObj = (JSONObject) originalValue;
- return originalValueObj.get(hiddenField);
- }
- return originalValue;
- }
-
private String getValue(String matrixUuid, ValueTextVo mapping, String text) {
if (StringUtils.isBlank(text)) {
return text;
@@ -764,177 +389,6 @@ public class FormServiceImpl implements FormService, IFormCrossoverService {
return null;
}
- @Override
- public List getAllFormAttributeList(JSONObject formConfig) {
- JSONArray tableList = formConfig.getJSONArray("tableList");
- return getAllFormAttributeList(tableList, null);
- }
-
- @Override
- public List getAllFormAttributeList(String formConfig) {
- return getAllFormAttributeList(JSON.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 FormAttributeVo getFormAttribute(String formConfig, String attributeUuid) {
- return getFormAttribute(JSON.parseObject(formConfig), attributeUuid, null);
- }
-
- @Override
- public String getFormAttributeHandler(String attributeUuid, JSONObject formConfig) {
- List formAttributeList = getAllFormAttributeList(formConfig);
- for (FormAttributeVo formAttributeVo : formAttributeList) {
- if (Objects.equals(formAttributeVo.getUuid(), attributeUuid)) {
- return formAttributeVo.getHandler();
- }
- }
- return null;
- }
-
- @Override
- public String getFormAttributeHandler(String attributeUuid, String formConfig) {
- return getFormAttributeHandler(attributeUuid, JSON.parseObject(formConfig));
- }
-
- private List getAllFormAttributeList(JSONArray tableList, FormAttributeParentVo parent) {
- List resultList = new ArrayList<>();
- if (CollectionUtils.isEmpty(tableList)) {
- return resultList;
- }
- for (int i = 0; i < tableList.size(); i++) {
- JSONObject cellObj = tableList.getJSONObject(i);
- if (MapUtils.isEmpty(cellObj)) {
- continue;
- }
- JSONObject componentObj = cellObj.getJSONObject("component");
- if (MapUtils.isEmpty(componentObj)) {
- continue;
- }
- 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");
- if (MapUtils.isNotEmpty(config2)) {
- JSONArray dataConfigList2 = config2.getJSONArray("dataConfig");
- if (CollectionUtils.isNotEmpty(dataConfigList2)) {
- 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)) {
- 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");
- if (MapUtils.isNotEmpty(formConfig)) {
- JSONArray tableList2 = formConfig.getJSONArray("tableList");
- resultList.addAll(getAllFormAttributeList(tableList2, parent2));
- }
- }
- } else {
- 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));
- }
- }
- }
- }
- return resultList;
- }
-
- private FormAttributeVo createFormAttribute(JSONObject componentObj, FormAttributeParentVo parent) {
- String uuid = componentObj.getString("uuid");
- if (StringUtils.isBlank(uuid)) {
- return null;
- }
- String handler = componentObj.getString("handler");
- if (StringUtils.isBlank(handler)) {
- return null;
- }
- FormAttributeVo formAttributeVo = new FormAttributeVo();
- formAttributeVo.setUuid(uuid);
- formAttributeVo.setHandler(handler);
- String label = componentObj.getString("label");
- formAttributeVo.setLabel(label);
- String type = componentObj.getString("type");
- formAttributeVo.setType(type);
- JSONObject config = componentObj.getJSONObject("config");
- if (MapUtils.isNotEmpty(config)) {
- boolean isRequired = config.getBooleanValue("isRequired");
- formAttributeVo.setRequired(isRequired);
- String defaultValue = config.getString("defaultValue");
- formAttributeVo.setData(defaultValue);
- formAttributeVo.setConfig(config);
- }
- formAttributeVo.setParent(parent);
- return formAttributeVo;
- }
-
@Override
public List getFormAttributeList(String formUuid, String formName, String tag) {
FormVersionVo formVersion = formMapper.getActionFormVersionByFormUuid(formUuid);
diff --git a/src/main/java/neatlogic/module/framework/importexport/handler/FormImportExportHandler.java b/src/main/java/neatlogic/module/framework/importexport/handler/FormImportExportHandler.java
index 219c57a836e3cf01f41e872beda7cc1320db773d..0e4266ce0cd6d1dd9dbca977bba267bb585b7db3 100644
--- a/src/main/java/neatlogic/module/framework/importexport/handler/FormImportExportHandler.java
+++ b/src/main/java/neatlogic/module/framework/importexport/handler/FormImportExportHandler.java
@@ -3,7 +3,6 @@ package neatlogic.module.framework.importexport.handler;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import neatlogic.framework.asynchronization.threadlocal.UserContext;
-import neatlogic.framework.crossover.CrossoverServiceFactory;
import neatlogic.framework.form.constvalue.FormHandler;
import neatlogic.framework.form.dao.mapper.FormMapper;
import neatlogic.framework.form.dto.FormAttributeVo;
@@ -11,13 +10,13 @@ import neatlogic.framework.form.dto.FormVersionVo;
import neatlogic.framework.form.dto.FormVo;
import neatlogic.framework.form.exception.FormActiveVersionNotFoundExcepiton;
import neatlogic.framework.form.exception.FormNotFoundException;
-import neatlogic.framework.form.service.IFormCrossoverService;
import neatlogic.framework.importexport.constvalue.FrameworkImportExportHandlerType;
import neatlogic.framework.importexport.core.ImportExportHandlerBase;
import neatlogic.framework.importexport.core.ImportExportHandlerType;
import neatlogic.framework.importexport.dto.ImportExportBaseInfoVo;
import neatlogic.framework.importexport.dto.ImportExportPrimaryChangeVo;
import neatlogic.framework.importexport.dto.ImportExportVo;
+import neatlogic.framework.util.FormUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
@@ -104,14 +103,13 @@ public class FormImportExportHandler extends ImportExportHandlerBase {
importHandle(formVersion, primaryChangeList);
- IFormCrossoverService formCrossoverService = CrossoverServiceFactory.getApi(IFormCrossoverService.class);
// 处理表单版本
formVersion.setFormUuid(form.getUuid());
formVersion.setIsActive(0);
FormVersionVo oldFormVersion = formMapper.getFormVersionByUuid(formVersion.getUuid());
if (oldFormVersion != null) {
// 删除依赖
- formCrossoverService.deleteDependency(oldFormVersion);
+ FormUtil.deleteDependency(oldFormVersion);
formVersion.setLcu(UserContext.get().getUserUuid());
formMapper.updateFormVersion(formVersion);
} else {
@@ -126,7 +124,7 @@ public class FormImportExportHandler extends ImportExportHandlerBase {
formMapper.insertFormVersion(formVersion);
}
// 插入依赖
- formCrossoverService.saveDependency(formVersion);
+ FormUtil.saveDependency(formVersion);
List formAttributeList = formVersion.getFormAttributeList();
// 激活版本
FormVersionVo oldActiveFormVersion = formMapper.getActionFormVersionByFormUuid(form.getUuid());
diff --git a/src/main/resources/neatlogic/resources/framework/changelog/2024-04-25/neatlogic_tenant.sql b/src/main/resources/neatlogic/resources/framework/changelog/2024-04-25/neatlogic_tenant.sql
new file mode 100644
index 0000000000000000000000000000000000000000..6b25fffc273e54484e600a6d33dfbbf4bc7a488d
--- /dev/null
+++ b/src/main/resources/neatlogic/resources/framework/changelog/2024-04-25/neatlogic_tenant.sql
@@ -0,0 +1,3 @@
+ALTER TABLE `form_extend_attribute`
+DROP PRIMARY KEY,
+ ADD PRIMARY KEY (`form_uuid`, `formversion_uuid`, `tag`, `uuid`);
\ No newline at end of file
diff --git a/src/main/resources/neatlogic/resources/framework/changelog/2024-04-25/version.json b/src/main/resources/neatlogic/resources/framework/changelog/2024-04-25/version.json
new file mode 100644
index 0000000000000000000000000000000000000000..29cbecd1bb66cb1f28e8ce16d593263a0cc56190
--- /dev/null
+++ b/src/main/resources/neatlogic/resources/framework/changelog/2024-04-25/version.json
@@ -0,0 +1,10 @@
+{
+ "content":[
+ {
+ "type":"新增功能",
+ "detail":[
+ {"msg":"1.增加表单提供消费用的扩展组件"}
+ ]
+ }
+ ]
+}