diff --git a/src/main/java/neatlogic/module/tenant/api/form/FormCopyApi.java b/src/main/java/neatlogic/module/tenant/api/form/FormCopyApi.java index e40bca1aef1ac9417d3074b743fe15f3a9975c84..09d6aabe8d7e40323cefff57905b6e8f98c69e66 100644 --- a/src/main/java/neatlogic/module/tenant/api/form/FormCopyApi.java +++ b/src/main/java/neatlogic/module/tenant/api/form/FormCopyApi.java @@ -29,9 +29,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; +import java.util.*; @Service @Transactional @@ -89,7 +87,11 @@ public class FormCopyApi extends PrivateApiComponentBase { throw new FormNotFoundException(formVersionVo.getFormUuid()); } newFrom.setIsActive(formVo.getIsActive()); - newFormVersionList.add(copyFormVersion(formVersionVo, newFrom.getUuid())); + Map formAttributeOldUuid2NewUuidMap = new HashMap<>(); + FormVersionVo newFormVersion = copyFormVersion(formVersionVo, newFrom.getUuid(), formAttributeOldUuid2NewUuidMap); + List formVersionExtendAttributeList = copyFormVersionExtendAttributeList(formVersionVo.getFormUuid(), formVersionVo.getUuid(), newFormVersion.getFormUuid(), newFormVersion.getUuid(), formAttributeOldUuid2NewUuidMap); + newFormVersion.setFormExtendAttributeList(formVersionExtendAttributeList); + newFormVersionList.add(newFormVersion); } else if(StringUtils.isNotBlank(uuid)) { FormVo formVo = formMapper.getFormByUuid(uuid); if (formVo == null) { @@ -98,7 +100,11 @@ public class FormCopyApi extends PrivateApiComponentBase { newFrom.setIsActive(formVo.getIsActive()); List formVersionList = formMapper.getFormVersionByFormUuid(uuid); for (FormVersionVo formVersionVo : formVersionList) { - newFormVersionList.add(copyFormVersion(formVersionVo, newFrom.getUuid())); + Map formAttributeOldUuid2NewUuidMap = new HashMap<>(); + FormVersionVo newFormVersion = copyFormVersion(formVersionVo, newFrom.getUuid(), formAttributeOldUuid2NewUuidMap); + List formVersionExtendAttributeList = copyFormVersionExtendAttributeList(formVersionVo.getFormUuid(), formVersionVo.getUuid(), newFormVersion.getFormUuid(), newFormVersion.getUuid(), formAttributeOldUuid2NewUuidMap); + newFormVersion.setFormExtendAttributeList(formVersionExtendAttributeList); + newFormVersionList.add(newFormVersion); } } else { throw new ParamNotExistsException("uuid", "currentVersionUuid"); @@ -128,6 +134,12 @@ public class FormCopyApi extends PrivateApiComponentBase { formMapper.insertFormAttribute(formAttributeVo); } } + List formVersionExtendAttributeList = formVersionVo.getFormExtendAttributeList(); + if (CollectionUtils.isNotEmpty(formVersionExtendAttributeList)) { + for (FormAttributeVo formAttributeVo : formVersionExtendAttributeList) { + formMapper.insertFormExtendAttribute(formAttributeVo); + } + } } return newFrom; } @@ -148,7 +160,7 @@ public class FormCopyApi extends PrivateApiComponentBase { * @param newFormUuid * @return */ - private FormVersionVo copyFormVersion(FormVersionVo oldFormVersionVo, String newFormUuid) { + private FormVersionVo copyFormVersion(FormVersionVo oldFormVersionVo, String newFormUuid, Map formAttributeOldUuid2NewUuidMap) { JSONObject formConfig = oldFormVersionVo.getFormConfig(); // 更新各种唯一标识uuid,防止不同表单版本之间唯一标识uuid相同 // 更新场景uuid @@ -176,7 +188,9 @@ public class FormCopyApi extends PrivateApiComponentBase { List allFormAttributeList = FormUtil.getAllFormAttributeList(formConfig); for (FormAttributeVo formAttributeVo : allFormAttributeList) { // 更新表单属性uuid - content = content.replace(formAttributeVo.getUuid(), UuidUtil.randomUuid()); + String formAttributeNewUuid = UuidUtil.randomUuid(); + formAttributeOldUuid2NewUuidMap.put(formAttributeVo.getUuid(), formAttributeNewUuid); + content = content.replace(formAttributeVo.getUuid(), formAttributeNewUuid); } FormVersionVo formVersionVo = new FormVersionVo(); formVersionVo.setVersion(oldFormVersionVo.getVersion()); @@ -185,4 +199,15 @@ public class FormCopyApi extends PrivateApiComponentBase { formVersionVo.setFormConfig(JSONObject.parseObject(content)); return formVersionVo; } + + private List copyFormVersionExtendAttributeList(String oldFormUuid, String oldFormVersionUuid, String newFormUuid, String newFormVersionUuid, Map formAttributeOldUuid2NewUuidMap) { + List formExtendAttributeList = formMapper.getFormExtendAttributeListByFormUuidAndFormVersionUuid(oldFormUuid, oldFormVersionUuid); + for (FormAttributeVo formAttributeVo : formExtendAttributeList) { + String newParentUuid = formAttributeOldUuid2NewUuidMap.get(formAttributeVo.getParentUuid()); + formAttributeVo.setParentUuid(newParentUuid); + formAttributeVo.setFormUuid(newFormUuid); + formAttributeVo.setFormVersionUuid(newFormVersionUuid); + } + return formExtendAttributeList; + } } diff --git a/src/main/java/neatlogic/module/tenant/api/form/FormDeleteApi.java b/src/main/java/neatlogic/module/tenant/api/form/FormDeleteApi.java index 3fea0a570fd50ce3f63a7128048378729cec5551..1500d580f6c8b283d31c055aecd5f6f6ca7fb3ab 100644 --- a/src/main/java/neatlogic/module/tenant/api/form/FormDeleteApi.java +++ b/src/main/java/neatlogic/module/tenant/api/form/FormDeleteApi.java @@ -63,6 +63,7 @@ public class FormDeleteApi extends PrivateApiComponentBase { if (CollectionUtils.isNotEmpty(formVersionList)) { for (FormVersionVo formVersionVo : formVersionList) { FormUtil.deleteDependency(formVersionVo); + formMapper.deleteFormExtendAttributeByFormUuidAndFormVersionUuid(formVersionVo.getFormUuid(), formVersionVo.getUuid()); } } formMapper.deleteFormByUuid(uuid); diff --git a/src/main/java/neatlogic/module/tenant/api/form/FormExportApi.java b/src/main/java/neatlogic/module/tenant/api/form/FormExportApi.java index 37610813bc5a4a87a1e545afd2e0072aeba6ca7f..baa66a9f3f3e280e7d13fa332e19faea25d82ff5 100644 --- a/src/main/java/neatlogic/module/tenant/api/form/FormExportApi.java +++ b/src/main/java/neatlogic/module/tenant/api/form/FormExportApi.java @@ -17,6 +17,7 @@ package neatlogic.module.tenant.api.form; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.form.dao.mapper.FormMapper; +import neatlogic.framework.form.dto.FormAttributeVo; import neatlogic.framework.form.dto.FormVersionVo; import neatlogic.framework.form.dto.FormVo; import neatlogic.framework.form.exception.FormNotFoundException; @@ -27,6 +28,7 @@ import neatlogic.framework.restful.annotation.Param; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateBinaryStreamApiComponentBase; import com.alibaba.fastjson.JSONObject; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.IOUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -55,7 +57,7 @@ public class FormExportApi extends PrivateBinaryStreamApiComponentBase { @Override public String getName() { - return "表单导出接口"; + return "nmtaf.formexportapi.getname"; } @Override @@ -64,9 +66,9 @@ public class FormExportApi extends PrivateBinaryStreamApiComponentBase { } @Input({ - @Param(name = "uuid", type = ApiParamType.STRING, desc = "表单uuid", isRequired = true) + @Param(name = "uuid", type = ApiParamType.STRING, desc = "term.framework.formuuid", isRequired = true) }) - @Description(desc = "表单导出接口") + @Description(desc = "nmtaf.formexportapi.getname") @Override public Object myDoService(JSONObject paramObj, HttpServletRequest request, HttpServletResponse response) throws Exception { String uuid = paramObj.getString("uuid"); @@ -77,6 +79,12 @@ public class FormExportApi extends PrivateBinaryStreamApiComponentBase { } //获取表单的所有版本 List formVersionLsit = formMapper.getFormVersionByFormUuid(uuid); + for (FormVersionVo formVersion : formVersionLsit) { + List formExtendAttributeList = formMapper.getFormExtendAttributeListByFormUuidAndFormVersionUuid(formVersion.getFormUuid(), formVersion.getUuid()); + if (CollectionUtils.isNotEmpty(formExtendAttributeList)) { + formVersion.setFormExtendAttributeList(formExtendAttributeList); + } + } formVo.setVersionList(formVersionLsit); //设置导出文件名, 表单名称_版本号 diff --git a/src/main/java/neatlogic/module/tenant/api/form/FormImportApi.java b/src/main/java/neatlogic/module/tenant/api/form/FormImportApi.java index 4e50ace1e7f138f9fea232c6416bac25dd473bcf..8e0a3337cae1ab380636cccb753515705065052b 100755 --- a/src/main/java/neatlogic/module/tenant/api/form/FormImportApi.java +++ b/src/main/java/neatlogic/module/tenant/api/form/FormImportApi.java @@ -49,7 +49,7 @@ public class FormImportApi extends PrivateBinaryStreamApiComponentBase { @Override public String getName() { - return "表单导入接口"; + return "nmtaf.formimportapi.getname"; } @Override @@ -58,9 +58,9 @@ public class FormImportApi extends PrivateBinaryStreamApiComponentBase { } @Output({ - @Param(name = "Return", type = ApiParamType.JSONARRAY, desc = "导入结果") + @Param(name = "Return", type = ApiParamType.JSONARRAY, desc = "nmtaf.formimportapi.output.param.desc.return") }) - @Description(desc = "表单导入接口") + @Description(desc = "nmtaf.formimportapi.getname") @Override public Object myDoService(JSONObject paramObj, HttpServletRequest request, HttpServletResponse response) throws Exception { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; @@ -117,6 +117,14 @@ public class FormImportApi extends PrivateBinaryStreamApiComponentBase { } } resultList.add("新增版本" + formVersion.getVersion()); + List formExtendAttributeList = formVersion.getFormExtendAttributeList(); + if (CollectionUtils.isNotEmpty(formExtendAttributeList)) { + for (FormAttributeVo formAttributeVo : formExtendAttributeList) { + formAttributeVo.setFormUuid(formVersion.getFormUuid()); + formAttributeVo.setFormVersionUuid(formVersion.getUuid()); + formMapper.insertFormExtendAttribute(formAttributeVo); + } + } } } else { resultList.add("更新表单:" + formVo.getName()); @@ -135,12 +143,21 @@ public class FormImportApi extends PrivateBinaryStreamApiComponentBase { } formVersion.setVersion(version); formVersion.setIsActive(0); - formVersion.setUuid(null); + if (existsFormVersionVo != null) { + formVersion.setUuid(null); + } formMapper.insertFormVersion(formVersion); resultList.add("新增版本" + version); } + List formExtendAttributeList = formVersion.getFormExtendAttributeList(); + if (CollectionUtils.isNotEmpty(formExtendAttributeList)) { + for (FormAttributeVo formAttributeVo : formExtendAttributeList) { + formAttributeVo.setFormUuid(formVersion.getFormUuid()); + formAttributeVo.setFormVersionUuid(formVersion.getUuid()); + formMapper.insertFormExtendAttribute(formAttributeVo); + } + } } - } return resultList; } else { 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 4c7826effe5989ace56099f9d2b6e71791f968e5..8b079575f483dd653830260818b42ca578aede92 100644 --- a/src/main/java/neatlogic/module/tenant/api/form/FormSaveApi.java +++ b/src/main/java/neatlogic/module/tenant/api/form/FormSaveApi.java @@ -29,9 +29,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; @Service @@ -150,7 +148,7 @@ public class FormSaveApi extends PrivateApiComponentBase { //更新表单信息 formMapper.updateForm(formVo); } - + Map formAttributeOldUuid2NewUuidMap = new HashMap<>(); //插入表单版本信息 if (StringUtils.isBlank(currentVersionUuid)) { Integer version = formMapper.getMaxVersionByFormUuid(formUuid); @@ -167,6 +165,7 @@ public class FormSaveApi extends PrivateApiComponentBase { String oldUuid = formAttributeVo.getUuid(); String newUuid = UuidUtil.randomUuid(); formConfigStr = formConfigStr.replace(oldUuid, newUuid); + formAttributeOldUuid2NewUuidMap.put(oldUuid, newUuid); } formVersionVo.setFormConfig(JSONObject.parseObject(formConfigStr)); formVersionVo.setFormAttributeList(null); @@ -202,9 +201,13 @@ public class FormSaveApi extends PrivateApiComponentBase { continue; } String parentUuid = attributeObj.getString("parentUuid"); + String newParentUuid = formAttributeOldUuid2NewUuidMap.get(parentUuid); + if (StringUtils.isNotBlank(newParentUuid)) { + parentUuid = newParentUuid; + } String tag = attributeObj.getString("tag"); String key = attributeObj.getString("key"); - String uuid = UuidUtil.getCustomUUID(parentUuid + "#" + key); + String uuid = UuidUtil.getCustomUUID(parentUuid + "#" + tag + "#" + key); String label = attributeObj.getString("label"); String type = attributeObj.getString("type"); String handler = attributeObj.getString("handler"); diff --git a/src/main/java/neatlogic/module/tenant/api/form/FormVersionDeleteApi.java b/src/main/java/neatlogic/module/tenant/api/form/FormVersionDeleteApi.java index 5432cf69328ee298e6c15028391c33387dfaeb75..920c7035781a927bda47b4c214365cfd4e124113 100644 --- a/src/main/java/neatlogic/module/tenant/api/form/FormVersionDeleteApi.java +++ b/src/main/java/neatlogic/module/tenant/api/form/FormVersionDeleteApi.java @@ -57,6 +57,7 @@ public class FormVersionDeleteApi extends PrivateApiComponentBase { } //删除表单版本 formMapper.deleteFormVersionByUuid(uuid); + formMapper.deleteFormExtendAttributeByFormUuidAndFormVersionUuid(formVersion.getFormUuid(), formVersion.getUuid()); FormUtil.deleteDependency(formVersion); return null; } diff --git a/src/main/java/neatlogic/module/tenant/api/form/FormVersionExportApi.java b/src/main/java/neatlogic/module/tenant/api/form/FormVersionExportApi.java index 8cd1416149838315c0c965e9543a73987f3f5586..5b521cee8e8be44cec709f9f3b3871687dbd6797 100644 --- a/src/main/java/neatlogic/module/tenant/api/form/FormVersionExportApi.java +++ b/src/main/java/neatlogic/module/tenant/api/form/FormVersionExportApi.java @@ -17,6 +17,7 @@ package neatlogic.module.tenant.api.form; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.form.dao.mapper.FormMapper; +import neatlogic.framework.form.dto.FormAttributeVo; import neatlogic.framework.form.dto.FormVersionVo; import neatlogic.framework.form.dto.FormVo; import neatlogic.framework.form.exception.FormNotFoundException; @@ -28,6 +29,7 @@ import neatlogic.framework.restful.annotation.Param; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateBinaryStreamApiComponentBase; import com.alibaba.fastjson.JSONObject; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.IOUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -39,6 +41,7 @@ import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.util.List; @Service @@ -55,7 +58,7 @@ public class FormVersionExportApi extends PrivateBinaryStreamApiComponentBase { @Override public String getName() { - return "表单版本导出接口"; + return "nmtaf.formversionexportapi.getname"; } @Override @@ -64,9 +67,9 @@ public class FormVersionExportApi extends PrivateBinaryStreamApiComponentBase { } @Input({ - @Param(name = "formVersionUuid", type = ApiParamType.STRING, desc = "表单版本uuid", isRequired = true) + @Param(name = "formVersionUuid", type = ApiParamType.STRING, desc = "term.framework.formversionuuid", isRequired = true) }) - @Description(desc = "表单版本导出接口") + @Description(desc = "nmtaf.formversionexportapi.getname") @Override public Object myDoService(JSONObject paramObj, HttpServletRequest request, HttpServletResponse response) throws Exception { String formVersionUuid = paramObj.getString("formVersionUuid"); @@ -80,6 +83,10 @@ public class FormVersionExportApi extends PrivateBinaryStreamApiComponentBase { if (formVo == null) { throw new FormNotFoundException(formVersion.getFormUuid()); } + List formExtendAttributeList = formMapper.getFormExtendAttributeListByFormUuidAndFormVersionUuid(formVersion.getFormUuid(), formVersion.getUuid()); + if (CollectionUtils.isNotEmpty(formExtendAttributeList)) { + formVersion.setFormExtendAttributeList(formExtendAttributeList); + } formVersion.setFormName(formVo.getName()); //设置导出文件名, 表单名称_版本号 String fileNameEncode = formVersion.getFormName() + "_" + formVersion.getVersion() + ".formversion"; diff --git a/src/main/java/neatlogic/module/tenant/api/form/FormVersionImportApi.java b/src/main/java/neatlogic/module/tenant/api/form/FormVersionImportApi.java index a5d323eaf05bf50285defb0a9fb72dc887288ca8..ff6e382fb1ec904af86650cb4eff4bfe39c86ec9 100755 --- a/src/main/java/neatlogic/module/tenant/api/form/FormVersionImportApi.java +++ b/src/main/java/neatlogic/module/tenant/api/form/FormVersionImportApi.java @@ -1,17 +1,19 @@ package neatlogic.module.tenant.api.form; +import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.auth.label.FORM_MODIFY; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.exception.file.FileExtNotAllowedException; import neatlogic.framework.exception.file.FileNotUploadException; import neatlogic.framework.form.dao.mapper.FormMapper; +import neatlogic.framework.form.dto.FormAttributeVo; import neatlogic.framework.form.dto.FormVersionVo; import neatlogic.framework.form.exception.FormNotFoundException; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateBinaryStreamApiComponentBase; -import com.alibaba.fastjson.JSONObject; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,6 +24,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.ObjectInputStream; +import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -41,7 +44,7 @@ public class FormVersionImportApi extends PrivateBinaryStreamApiComponentBase { @Override public String getName() { - return "表单版本导入接口"; + return "nmtaf.formversionimportapi.getname"; } @Override @@ -50,13 +53,13 @@ public class FormVersionImportApi extends PrivateBinaryStreamApiComponentBase { } @Input({ - @Param(name = "uuid", type = ApiParamType.STRING, desc = "表单uuid", isRequired = true) + @Param(name = "uuid", type = ApiParamType.STRING, desc = "term.framework.formuuid", isRequired = true) }) @Output({ @Param(name = "versionUuid", type = ApiParamType.INTEGER, desc = "导入版本号"), - @Param(name = "result", type = ApiParamType.STRING, desc = "导入结果") + @Param(name = "result", type = ApiParamType.STRING, desc = "nmtaf.formimportapi.output.param.desc.return") }) - @Description(desc = "表单版本导入接口") + @Description(desc = "nmtaf.formversionimportapi.getname") @Override public Object myDoService(JSONObject paramObj, HttpServletRequest request, HttpServletResponse response) throws Exception { String uuid = paramObj.getString("uuid"); @@ -100,7 +103,6 @@ public class FormVersionImportApi extends PrivateBinaryStreamApiComponentBase { formMapper.updateFormVersion(formVersionVo); resultObj.put("versionUuid", formVersionVo.getUuid()); resultObj.put("result", "版本" + existsFormVersionVo.getVersion() + "被覆盖"); - return resultObj; } else { Integer version = formMapper.getMaxVersionByFormUuid(uuid); if (version == null) { @@ -110,13 +112,22 @@ public class FormVersionImportApi extends PrivateBinaryStreamApiComponentBase { } formVersionVo.setIsActive(0); formVersionVo.setVersion(version); - formVersionVo.setUuid(null); + if (existsFormVersionVo != null) { + formVersionVo.setUuid(null); + } formMapper.insertFormVersion(formVersionVo); resultObj.put("versionUuid", formVersionVo.getUuid()); resultObj.put("result", "新增版本" + version); - return resultObj; } - + List formExtendAttributeList = formVersionVo.getFormExtendAttributeList(); + if (CollectionUtils.isNotEmpty(formExtendAttributeList)) { + for (FormAttributeVo formAttributeVo : formExtendAttributeList) { + formAttributeVo.setFormUuid(formVersionVo.getFormUuid()); + formAttributeVo.setFormVersionUuid(formVersionVo.getUuid()); + formMapper.insertFormExtendAttribute(formAttributeVo); + } + } + return resultObj; } else { throw new FileExtNotAllowedException(multipartFile.getOriginalFilename()); }