diff --git a/src/main/java/neatlogic/module/tenant/api/form/FormSaveApi.java b/src/main/java/neatlogic/module/tenant/api/form/FormSaveApi.java index c16ef9057165cf26e84feb71f9f013815bb86895..8f6fd5b47e0a2a64d405d789522d74c29c52cc5f 100644 --- a/src/main/java/neatlogic/module/tenant/api/form/FormSaveApi.java +++ b/src/main/java/neatlogic/module/tenant/api/form/FormSaveApi.java @@ -1,5 +1,6 @@ package neatlogic.module.tenant.api.form; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.auth.label.FORM_MODIFY; @@ -21,6 +22,7 @@ import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.util.RegexUtils; import neatlogic.framework.util.UuidUtil; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -60,7 +62,8 @@ public class FormSaveApi extends PrivateApiComponentBase { @Param(name = "uuid", type = ApiParamType.STRING, desc = "common.uuid", isRequired = true), @Param(name = "name", type = ApiParamType.REGEX, rule = RegexUtils.NAME, isRequired = true, maxLength = 50, desc = "common.name"), @Param(name = "currentVersionUuid", type = ApiParamType.STRING, desc = "common.versionuuid", help = "当前版本的uuid,为空代表创建一个新版本"), - @Param(name = "formConfig", type = ApiParamType.JSONOBJECT, desc = "common.config", isRequired = true) + @Param(name = "formConfig", type = ApiParamType.JSONOBJECT, desc = "common.config", isRequired = true), + @Param(name = "formExtendConfig", type = ApiParamType.JSONOBJECT, desc = "common.config") }) @Output({ @Param(name = "uuid", type = ApiParamType.STRING, desc = "common.uuid"), @@ -119,6 +122,8 @@ public class FormSaveApi extends PrivateApiComponentBase { } else { formVersionVo.getUuid(); } + String mainSceneUuid = formVo.getFormConfig().getString("uuid"); + formVersionVo.setSceneUuid(mainSceneUuid); List formAttributeList = formVersionVo.getFormAttributeList(); if (CollectionUtils.isNotEmpty(formAttributeList)) { //判断组件名是否重复 @@ -185,6 +190,39 @@ public class FormSaveApi extends PrivateApiComponentBase { } } } + formMapper.deleteFormExtendAttributeByFormUuidAndFormVersionUuid(formUuid, currentVersionUuid); + JSONObject formExtendConfig = jsonObj.getJSONObject("formExtendConfig"); + if (MapUtils.isNotEmpty(formExtendConfig)) { + JSONArray attributeArray = formExtendConfig.getJSONArray("attributeList"); + if (CollectionUtils.isNotEmpty(attributeArray)) { + for (int i = 0; i < attributeArray.size(); i++) { + JSONObject attributeObj = attributeArray.getJSONObject(i); + if (MapUtils.isEmpty(attributeObj)) { + continue; + } + String parentUuid = attributeObj.getString("parentUuid"); + String tag = attributeObj.getString("tag"); + String key = attributeObj.getString("key"); + String uuid = UuidUtil.getCustomUUID(parentUuid + "#" + key); + String label = attributeObj.getString("label"); + String type = attributeObj.getString("type"); + String handler = attributeObj.getString("handler"); + JSONObject config = attributeObj.getJSONObject("config"); + FormAttributeVo formAttributeVo = new FormAttributeVo(); + formAttributeVo.setFormUuid(formUuid); + formAttributeVo.setFormVersionUuid(currentVersionUuid); + formAttributeVo.setParentUuid(parentUuid); + formAttributeVo.setTag(tag); + formAttributeVo.setKey(key); + formAttributeVo.setUuid(uuid); + formAttributeVo.setLabel(label); + formAttributeVo.setType(type); + formAttributeVo.setHandler(handler); + formAttributeVo.setConfig(config); + formMapper.insertFormExtendAttribute(formAttributeVo); + } + } + } return resultObj; } } diff --git a/src/main/java/neatlogic/module/tenant/api/form/GetFormAttributeListApi.java b/src/main/java/neatlogic/module/tenant/api/form/GetFormAttributeListApi.java new file mode 100644 index 0000000000000000000000000000000000000000..9cacd147e01f383695ca614d3fc1cbdd91a224d8 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/form/GetFormAttributeListApi.java @@ -0,0 +1,72 @@ +/* + * 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.module.tenant.api.form; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.crossover.CrossoverServiceFactory; +import neatlogic.framework.form.dao.mapper.FormMapper; +import neatlogic.framework.form.dto.FormAttributeVo; +import neatlogic.framework.form.dto.FormVo; +import neatlogic.framework.form.exception.FormNotFoundException; +import neatlogic.framework.form.service.IFormCrossoverService; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +@Service + +@OperationType(type = OperationTypeEnum.SEARCH) +public class GetFormAttributeListApi extends PrivateApiComponentBase { + + @Resource + private FormMapper formMapper; + + @Override + public String getName() { + return "nmtaf.getformattributelistapi.getname"; + } + + @Input({ + @Param(name = "formUuid", type = ApiParamType.STRING, desc = "term.framework.formuuid", isRequired = true), + @Param(name = "tag", type = ApiParamType.STRING, desc = "common.tag") + }) + @Output({ + @Param(name = "tbodyList", explode = FormAttributeVo[].class, desc = "common.tbodylist") + }) + @Description(desc = "nmtaf.getformattributelistapi.getname") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + String formUuid = paramObj.getString("formUuid"); + String tag = paramObj.getString("tag"); + FormVo form = formMapper.getFormByUuid(formUuid); + if (form == null) { + throw new FormNotFoundException(formUuid); + } + IFormCrossoverService formCrossoverService = CrossoverServiceFactory.getApi(IFormCrossoverService.class); + return formCrossoverService.getFormAttributeList(formUuid, form.getName(), tag); + } + + @Override + public String getToken() { + return "form/attribute/list"; + } +}