From b6068f9a44520802cbd11f532c439aa2f6cf5046 Mon Sep 17 00:00:00 2001 From: guozhiqi Date: Thu, 12 Jan 2023 14:39:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E4=BD=93=E8=BD=AC=E6=8D=A2=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=A7=81=E6=9C=89=E9=9D=99=E6=80=81=E5=86=85?= =?UTF-8?q?=E9=83=A8=E7=B1=BB=EF=BC=8C=E9=81=BF=E5=85=8D=E6=9A=B4=E9=9C=B2?= =?UTF-8?q?=E8=BF=87=E5=A4=9A=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/entity/FormScriptCacheContent.java | 2 + .../converter/FormProjectCacheConverter.java | 67 --------------- .../FormScriptCacheContentConverter.java | 67 --------------- .../converter/FormScriptCacheConverter.java | 61 ------------- .../domain/entity/FormProjectCacheEntity.java | 86 +++++++++++++++++-- .../entity/FormScriptCacheContentEntity.java | 70 +++++++++++++++ .../domain/entity/FormScriptCacheEntity.java | 73 +++++++++++++++- .../manager/FormProjectCacheManager.java | 7 +- .../FormScriptCacheContentManager.java | 3 +- .../manager/FormScriptCacheManager.java | 16 ++-- .../manager/ScriptCacheVersionManager.java | 17 ++-- .../common/converter/WebEntityConverter.java | 19 ++++ 12 files changed, 257 insertions(+), 231 deletions(-) delete mode 100644 runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/converter/FormProjectCacheConverter.java delete mode 100644 runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/converter/FormScriptCacheContentConverter.java delete mode 100644 runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/converter/FormScriptCacheConverter.java create mode 100644 web-common/src/main/java/com/inspur/edp/web/common/converter/WebEntityConverter.java diff --git a/runtime-scriptcache-api/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/api/entity/FormScriptCacheContent.java b/runtime-scriptcache-api/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/api/entity/FormScriptCacheContent.java index 653f912c..81c03dee 100644 --- a/runtime-scriptcache-api/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/api/entity/FormScriptCacheContent.java +++ b/runtime-scriptcache-api/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/api/entity/FormScriptCacheContent.java @@ -1,5 +1,6 @@ package com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity; +import com.inspur.edp.web.common.converter.WebEntityConverter; import com.inspur.edp.web.common.utility.StringUtility; import java.util.Date; @@ -85,4 +86,5 @@ public class FormScriptCacheContent { public void setLastModifyTime(Date lastModifyTime) { this.lastModifyTime = lastModifyTime; } + } diff --git a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/converter/FormProjectCacheConverter.java b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/converter/FormProjectCacheConverter.java deleted file mode 100644 index a70ea897..00000000 --- a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/converter/FormProjectCacheConverter.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.inspur.edp.web.jitruntimebuild.scriptcache.domain.converter; - -import com.inspur.edp.web.common.utility.CommonUtility; -import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormProjectCache; -import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.entity.FormProjectCacheEntity; - -/** - * description: - * - * @author Noah Guo - * @date 2020/09/29 - */ -public class FormProjectCacheConverter { - /** - * 实体与domain的转换 将projectCache转换成对应的projectCacheEntity domain实体 - * - * @param projectCache - * @return - */ - public static FormProjectCacheEntity convert(FormProjectCache projectCache) { - FormProjectCacheEntity projectCacheEntity = new FormProjectCacheEntity(); - if (projectCache == null) { - return projectCacheEntity; - } - projectCacheEntity.setId(projectCache.getId()); - projectCacheEntity.setCreateDate(projectCache.getCreateDate()); - projectCacheEntity.setCreator(projectCache.getCreator()); - projectCacheEntity.setLastModifier(projectCache.getLastModifier()); - if (projectCache.getLastModifyTime() == null) { - projectCacheEntity.setLastModifyTime(CommonUtility.getCurrentDate()); - } else { - projectCacheEntity.setLastModifyTime(projectCache.getLastModifyTime()); - } - - projectCacheEntity.setProjectCode(projectCache.getProjectCode()); - projectCacheEntity.setProjectName(projectCache.getProjectName()); - projectCacheEntity.setProjectRelativePath(projectCache.getProjectRelativePath()); - projectCacheEntity.setVersion(projectCache.getVersion()); - return projectCacheEntity; - - } - - /** - * 将domain实体转换成对应的entity - * - * @param projectCacheEntity - * @return - */ - public static FormProjectCache convertReverse(FormProjectCacheEntity projectCacheEntity) { - - FormProjectCache projectCache = new FormProjectCache(); - if (projectCacheEntity == null) { - return projectCache; - } - projectCache.setId(projectCacheEntity.getId()); - projectCache.setCreateDate(projectCacheEntity.getCreateDate()); - projectCache.setCreator(projectCacheEntity.getCreator()); - projectCache.setLastModifier(projectCacheEntity.getLastModifier()); - projectCache.setLastModifyTime(CommonUtility.getCurrentDate()); - projectCache.setProjectCode(projectCacheEntity.getProjectCode()); - projectCache.setProjectName(projectCacheEntity.getProjectName()); - projectCache.setProjectRelativePath(projectCacheEntity.getProjectRelativePath()); - projectCache.setVersion(projectCacheEntity.getVersion()); - return projectCache; - } - -} diff --git a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/converter/FormScriptCacheContentConverter.java b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/converter/FormScriptCacheContentConverter.java deleted file mode 100644 index ea3951b4..00000000 --- a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/converter/FormScriptCacheContentConverter.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.inspur.edp.web.jitruntimebuild.scriptcache.domain.converter; - -import com.inspur.edp.web.common.encrypt.EncryptUtility; -import com.inspur.edp.web.common.utility.CommonUtility; -import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormScriptCacheContent; -import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.entity.FormScriptCacheContentEntity; - -/** - * description: - * - * @author Noah Guo - * @date 2020/09/29 - */ -public class FormScriptCacheContentConverter { - - /** - * @param scriptCacheContent - * @return - */ - public static FormScriptCacheContentEntity convert(FormScriptCacheContent scriptCacheContent) { - - FormScriptCacheContentEntity cacheContentEntity = new FormScriptCacheContentEntity(); - if (scriptCacheContent == null) { - return cacheContentEntity; - } - String encodeContent = scriptCacheContent.getContent(); - // 如果内容进行了base64编码 那么进行base64解码之后返回 - // 保存的脚本内容永远进行base64编码 - encodeContent = EncryptUtility.getInstance().Base64Encode(encodeContent); - - cacheContentEntity.setContent(encodeContent); - cacheContentEntity.setCreateDate(scriptCacheContent.getCreateDate()); - cacheContentEntity.setCreator(scriptCacheContent.getCreator()); - cacheContentEntity.setId(scriptCacheContent.getId()); - cacheContentEntity.setLastModifier(scriptCacheContent.getLastModifier()); - if (scriptCacheContent.getLastModifyTime() == null) { - cacheContentEntity.setLastModifyTime(CommonUtility.getCurrentDate()); - } else { - cacheContentEntity.setLastModifyTime(scriptCacheContent.getLastModifyTime()); - } - - return cacheContentEntity; - } - - public static FormScriptCacheContent convertReverse(FormScriptCacheContentEntity contentEntity) { - - FormScriptCacheContent cacheContent = new FormScriptCacheContent(); - if (contentEntity == null) { - return cacheContent; - } - - String decodeContent = contentEntity.getContent(); - // 获取到的脚本永远进行解码操作 - if(EncryptUtility.getInstance().isBase64(decodeContent)){ - decodeContent=EncryptUtility.getInstance().Base64Decode(decodeContent); - } - cacheContent.setContent(decodeContent); - cacheContent.setId(contentEntity.getId()); - cacheContent.setCreateDate(contentEntity.getCreateDate()); - cacheContent.setCreator(contentEntity.getCreator()); - cacheContent.setLastModifier(contentEntity.getLastModifier()); - cacheContent.setLastModifyTime(contentEntity.getLastModifyTime()); - return cacheContent; - } - - -} diff --git a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/converter/FormScriptCacheConverter.java b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/converter/FormScriptCacheConverter.java deleted file mode 100644 index 5ddb894e..00000000 --- a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/converter/FormScriptCacheConverter.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.inspur.edp.web.jitruntimebuild.scriptcache.domain.converter; - -import com.inspur.edp.web.common.utility.CommonUtility; -import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormScriptCache; -import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.entity.FormScriptCacheEntity; - -/** - * description: - * - * @author Noah Guo - * @date 2020/09/29 - */ -public class FormScriptCacheConverter { - public static FormScriptCacheEntity convert(FormScriptCache scriptCache) { - - FormScriptCacheEntity cacheEntity = new FormScriptCacheEntity(); - if (scriptCache == null) { - return cacheEntity; - } - cacheEntity.setCreateDate(scriptCache.getCreateDate()); - cacheEntity.setCreator(scriptCache.getCreator()); - cacheEntity.setFormMetadataId(scriptCache.getFormMetadataId()); - cacheEntity.setId(scriptCache.getId()); - cacheEntity.setLastModifier(scriptCache.getLastModifier()); - if (scriptCache.getLastModifyTime() == null) { - cacheEntity.setLastModifyTime(CommonUtility.getCurrentDate()); - } else { - cacheEntity.setLastModifyTime(scriptCache.getLastModifyTime()); - } - - cacheEntity.setProjectVersionId(scriptCache.getProjectVersionId()); - cacheEntity.setScriptCode(scriptCache.getScriptCode()); - cacheEntity.setScriptContentId(scriptCache.getScriptContentId()); - cacheEntity.setScriptName(scriptCache.getScriptName()); - cacheEntity.setScriptRelativePath(scriptCache.getScriptRelativePath()); - cacheEntity.setVersion(scriptCache.getVersion()); - return cacheEntity; - } - - public static FormScriptCache convertReverse(FormScriptCacheEntity scriptCacheEntity) { - - FormScriptCache scriptCache = new FormScriptCache(); - if (scriptCacheEntity == null) { - return scriptCache; - } - scriptCache.setScriptContent(scriptCacheEntity.getScriptContentId()); - scriptCache.setScriptContentId(scriptCacheEntity.getScriptContentId()); - scriptCache.setScriptRelativePath(scriptCacheEntity.getScriptRelativePath()); - scriptCache.setScriptCode(scriptCacheEntity.getScriptCode()); - scriptCache.setScriptName(scriptCacheEntity.getScriptName()); - scriptCache.setVersion(scriptCacheEntity.getVersion()); - scriptCache.setProjectVersionId(scriptCacheEntity.getProjectVersionId()); - scriptCache.setId(scriptCacheEntity.getId()); - scriptCache.setFormMetadataId(scriptCacheEntity.getFormMetadataId()); - scriptCache.setCreateDate(scriptCacheEntity.getCreateDate()); - scriptCache.setCreator(scriptCacheEntity.getCreator()); - scriptCache.setLastModifier(scriptCacheEntity.getLastModifier()); - scriptCache.setLastModifyTime(scriptCacheEntity.getLastModifyTime()); - return scriptCache; - } -} diff --git a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/entity/FormProjectCacheEntity.java b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/entity/FormProjectCacheEntity.java index afabf2ed..63022b90 100644 --- a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/entity/FormProjectCacheEntity.java +++ b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/entity/FormProjectCacheEntity.java @@ -1,5 +1,8 @@ package com.inspur.edp.web.jitruntimebuild.scriptcache.domain.entity; +import com.inspur.edp.web.common.converter.WebEntityConverter; +import com.inspur.edp.web.common.utility.CommonUtility; +import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormProjectCache; import lombok.Data; import javax.persistence.Entity; @@ -9,33 +12,33 @@ import java.util.Date; @Data @Entity -@Table(name="formprojectcache") +@Table(name = "formprojectcache") public class FormProjectCacheEntity { /** * 主键字段 */ @Id - private String id; + private String id; /** * 工程名称 */ - private String projectName; + private String projectName; /** * 工程编码 */ - private String projectCode; + private String projectCode; /** * 工程相对路径 */ - private String projectRelativePath; + private String projectRelativePath; /** * 工程对应版本 */ - private String version; + private String version; public String getId() { return id; @@ -117,18 +120,83 @@ public class FormProjectCacheEntity { /** * 创建人 */ - private String creator; + private String creator; /** * 最后修改人 */ - private String lastModifier; + private String lastModifier; /** * 最后修改时间 */ - private Date lastModifyTime; + private Date lastModifyTime; + /** + * 将当前实体转换成为ProjectCache实例 + * @return + */ + public FormProjectCache convertTo() { + return new ProjectCacheConverter().convertTo(this); + } + + /** + * 将ProjectCache实例转换为当前实例 + * 完成实体的转换操作 + * static 方法 + * @param projectCache + * @return + */ + public static FormProjectCacheEntity convertFrom(FormProjectCache projectCache) { + return new ProjectCacheConverter().convertFrom(projectCache); + } + + /** + * 使用内部类 封装对应的转换操作 + */ + private static class ProjectCacheConverter implements WebEntityConverter { + + @Override + public FormProjectCache convertTo(FormProjectCacheEntity source) { + FormProjectCache projectCache = new FormProjectCache(); + if (source == null) { + return projectCache; + } + projectCache.setId(source.getId()); + projectCache.setCreateDate(source.getCreateDate()); + projectCache.setCreator(source.getCreator()); + projectCache.setLastModifier(source.getLastModifier()); + projectCache.setLastModifyTime(CommonUtility.getCurrentDate()); + projectCache.setProjectCode(source.getProjectCode()); + projectCache.setProjectName(source.getProjectName()); + projectCache.setProjectRelativePath(source.getProjectRelativePath()); + projectCache.setVersion(source.getVersion()); + return projectCache; + } + + @Override + public FormProjectCacheEntity convertFrom(FormProjectCache projectCache) { + FormProjectCacheEntity projectCacheEntity = new FormProjectCacheEntity(); + if (projectCache == null) { + return projectCacheEntity; + } + projectCacheEntity.setId(projectCache.getId()); + projectCacheEntity.setCreateDate(projectCache.getCreateDate()); + projectCacheEntity.setCreator(projectCache.getCreator()); + projectCacheEntity.setLastModifier(projectCache.getLastModifier()); + if (projectCache.getLastModifyTime() == null) { + projectCacheEntity.setLastModifyTime(CommonUtility.getCurrentDate()); + } else { + projectCacheEntity.setLastModifyTime(projectCache.getLastModifyTime()); + } + + projectCacheEntity.setProjectCode(projectCache.getProjectCode()); + projectCacheEntity.setProjectName(projectCache.getProjectName()); + projectCacheEntity.setProjectRelativePath(projectCache.getProjectRelativePath()); + projectCacheEntity.setVersion(projectCache.getVersion()); + return projectCacheEntity; + } + } } diff --git a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/entity/FormScriptCacheContentEntity.java b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/entity/FormScriptCacheContentEntity.java index 71c4e3e8..a7b11c7b 100644 --- a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/entity/FormScriptCacheContentEntity.java +++ b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/entity/FormScriptCacheContentEntity.java @@ -1,5 +1,10 @@ package com.inspur.edp.web.jitruntimebuild.scriptcache.domain.entity; +import com.inspur.edp.web.common.converter.WebEntityConverter; +import com.inspur.edp.web.common.encrypt.EncryptUtility; +import com.inspur.edp.web.common.utility.CommonUtility; +import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormScriptCache; +import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormScriptCacheContent; import lombok.Data; import javax.persistence.Entity; @@ -80,4 +85,69 @@ public class FormScriptCacheContentEntity { public void setLastModifyTime(Date lastModifyTime) { this.lastModifyTime = lastModifyTime; } + + /** + * 将FormScriptCacheContentEntity 转换成为FormScriptCacheContent + * @return + */ + public FormScriptCacheContent convertTo() { + return new ScriptCacheContentConverter().convertTo(this); + } + + public static FormScriptCacheContentEntity convertFrom(FormScriptCacheContent cacheContent) { + return new ScriptCacheContentConverter().convertFrom(cacheContent); + } + + /** + * 使用内部类 封装转换操作 + * 不对外提供 + */ + private static class ScriptCacheContentConverter implements WebEntityConverter { + + @Override + public FormScriptCacheContent convertTo(FormScriptCacheContentEntity contentEntity) { + FormScriptCacheContent cacheContent = new FormScriptCacheContent(); + if (contentEntity == null) { + return cacheContent; + } + + String decodeContent = contentEntity.getContent(); + // 获取到的脚本永远进行解码操作 + if (EncryptUtility.getInstance().isBase64(decodeContent)) { + decodeContent = EncryptUtility.getInstance().Base64Decode(decodeContent); + } + cacheContent.setContent(decodeContent); + cacheContent.setId(contentEntity.getId()); + cacheContent.setCreateDate(contentEntity.getCreateDate()); + cacheContent.setCreator(contentEntity.getCreator()); + cacheContent.setLastModifier(contentEntity.getLastModifier()); + cacheContent.setLastModifyTime(contentEntity.getLastModifyTime()); + return cacheContent; + } + + @Override + public FormScriptCacheContentEntity convertFrom(FormScriptCacheContent scriptCacheContent) { + FormScriptCacheContentEntity cacheContentEntity = new FormScriptCacheContentEntity(); + if (scriptCacheContent == null) { + return cacheContentEntity; + } + String encodeContent = scriptCacheContent.getContent(); + // 如果内容进行了base64编码 那么进行base64解码之后返回 + // 保存的脚本内容永远进行base64编码 + encodeContent = EncryptUtility.getInstance().Base64Encode(encodeContent); + + cacheContentEntity.setContent(encodeContent); + cacheContentEntity.setCreateDate(scriptCacheContent.getCreateDate()); + cacheContentEntity.setCreator(scriptCacheContent.getCreator()); + cacheContentEntity.setId(scriptCacheContent.getId()); + cacheContentEntity.setLastModifier(scriptCacheContent.getLastModifier()); + if (scriptCacheContent.getLastModifyTime() == null) { + cacheContentEntity.setLastModifyTime(CommonUtility.getCurrentDate()); + } else { + cacheContentEntity.setLastModifyTime(scriptCacheContent.getLastModifyTime()); + } + + return cacheContentEntity; + } + } } diff --git a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/entity/FormScriptCacheEntity.java b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/entity/FormScriptCacheEntity.java index 162d17db..53d3ca57 100644 --- a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/entity/FormScriptCacheEntity.java +++ b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/entity/FormScriptCacheEntity.java @@ -1,5 +1,8 @@ package com.inspur.edp.web.jitruntimebuild.scriptcache.domain.entity; +import com.inspur.edp.web.common.converter.WebEntityConverter; +import com.inspur.edp.web.common.utility.CommonUtility; +import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormScriptCache; import lombok.Data; import javax.persistence.Entity; @@ -9,7 +12,7 @@ import java.util.Date; @Data @Entity -@Table(name="formscriptcache") +@Table(name = "formscriptcache") public class FormScriptCacheEntity { @Id @@ -58,4 +61,72 @@ public class FormScriptCacheEntity { private String lastModifier; + /** + * 将FormScriptCacheEntity 转换成为 FormScriptCache + * @return + */ + public FormScriptCache convertTo() { + return new ScriptCacheConverter().convertTo(this); + } + + /** + * 将FormScriptCache 转换成为 FormScriptCacheEntity 实体 + * static + * @param scriptCache + * @return + */ + public static FormScriptCacheEntity convertFrom(FormScriptCache scriptCache) { + return new ScriptCacheConverter().convertFrom(scriptCache); + } + + private static class ScriptCacheConverter implements WebEntityConverter { + + @Override + public FormScriptCache convertTo(FormScriptCacheEntity scriptCacheEntity) { + FormScriptCache scriptCache = new FormScriptCache(); + if (scriptCacheEntity == null) { + return scriptCache; + } + scriptCache.setScriptContent(scriptCacheEntity.getScriptContentId()); + scriptCache.setScriptContentId(scriptCacheEntity.getScriptContentId()); + scriptCache.setScriptRelativePath(scriptCacheEntity.getScriptRelativePath()); + scriptCache.setScriptCode(scriptCacheEntity.getScriptCode()); + scriptCache.setScriptName(scriptCacheEntity.getScriptName()); + scriptCache.setVersion(scriptCacheEntity.getVersion()); + scriptCache.setProjectVersionId(scriptCacheEntity.getProjectVersionId()); + scriptCache.setId(scriptCacheEntity.getId()); + scriptCache.setFormMetadataId(scriptCacheEntity.getFormMetadataId()); + scriptCache.setCreateDate(scriptCacheEntity.getCreateDate()); + scriptCache.setCreator(scriptCacheEntity.getCreator()); + scriptCache.setLastModifier(scriptCacheEntity.getLastModifier()); + scriptCache.setLastModifyTime(scriptCacheEntity.getLastModifyTime()); + return scriptCache; + } + + @Override + public FormScriptCacheEntity convertFrom(FormScriptCache scriptCache) { + FormScriptCacheEntity cacheEntity = new FormScriptCacheEntity(); + if (scriptCache == null) { + return cacheEntity; + } + cacheEntity.setCreateDate(scriptCache.getCreateDate()); + cacheEntity.setCreator(scriptCache.getCreator()); + cacheEntity.setFormMetadataId(scriptCache.getFormMetadataId()); + cacheEntity.setId(scriptCache.getId()); + cacheEntity.setLastModifier(scriptCache.getLastModifier()); + if (scriptCache.getLastModifyTime() == null) { + cacheEntity.setLastModifyTime(CommonUtility.getCurrentDate()); + } else { + cacheEntity.setLastModifyTime(scriptCache.getLastModifyTime()); + } + + cacheEntity.setProjectVersionId(scriptCache.getProjectVersionId()); + cacheEntity.setScriptCode(scriptCache.getScriptCode()); + cacheEntity.setScriptContentId(scriptCache.getScriptContentId()); + cacheEntity.setScriptName(scriptCache.getScriptName()); + cacheEntity.setScriptRelativePath(scriptCache.getScriptRelativePath()); + cacheEntity.setVersion(scriptCache.getVersion()); + return cacheEntity; + } + } } diff --git a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/manager/FormProjectCacheManager.java b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/manager/FormProjectCacheManager.java index 786c4b2d..984e5755 100644 --- a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/manager/FormProjectCacheManager.java +++ b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/manager/FormProjectCacheManager.java @@ -1,7 +1,6 @@ package com.inspur.edp.web.jitruntimebuild.scriptcache.domain.manager; import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormProjectCache; -import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.converter.FormProjectCacheConverter; import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.entity.FormProjectCacheEntity; import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.repository.FormProjectCacheRepository; @@ -62,8 +61,8 @@ public class FormProjectCacheManager { findProjectCacheEntity.set(item); } }); - if (findProjectCacheEntity != null && findProjectCacheEntity.get() != null) { - return FormProjectCacheConverter.convertReverse(findProjectCacheEntity.get()); + if (findProjectCacheEntity.get() != null) { + return findProjectCacheEntity.get().convertTo(); } return null; } @@ -76,6 +75,6 @@ public class FormProjectCacheManager { */ public FormProjectCache getById(String formProjectId) { Optional formProjectCacheEntity = this.repository.findFormProjectCacheById(formProjectId); - return formProjectCacheEntity.map(FormProjectCacheConverter::convertReverse).orElse(null); + return formProjectCacheEntity.map(FormProjectCacheEntity::convertTo).orElse(null); } } diff --git a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/manager/FormScriptCacheContentManager.java b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/manager/FormScriptCacheContentManager.java index d98da83d..8fda1270 100644 --- a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/manager/FormScriptCacheContentManager.java +++ b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/manager/FormScriptCacheContentManager.java @@ -1,7 +1,6 @@ package com.inspur.edp.web.jitruntimebuild.scriptcache.domain.manager; import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormScriptCacheContent; -import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.converter.FormScriptCacheContentConverter; import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.entity.FormScriptCacheContentEntity; import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.repository.FormScriptCacheContentRepository; import org.springframework.transaction.annotation.Transactional; @@ -48,7 +47,7 @@ public class FormScriptCacheContentManager { */ public FormScriptCacheContent findById(String scriptContentId) { Optional scriptCacheContentEntity = this.repository.findById(scriptContentId); - return scriptCacheContentEntity.map(FormScriptCacheContentConverter::convertReverse).orElse(null); + return scriptCacheContentEntity.map(FormScriptCacheContentEntity::convertTo).orElse(null); } diff --git a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/manager/FormScriptCacheManager.java b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/manager/FormScriptCacheManager.java index 87658f62..d46b2691 100644 --- a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/manager/FormScriptCacheManager.java +++ b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/domain/manager/FormScriptCacheManager.java @@ -3,13 +3,13 @@ package com.inspur.edp.web.jitruntimebuild.scriptcache.domain.manager; import com.inspur.edp.web.common.io.FileUtility; import com.inspur.edp.web.common.utility.StringUtility; import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormScriptCache; -import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.converter.FormScriptCacheConverter; import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.entity.FormScriptCacheEntity; import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.repository.FormScriptCacheRepository; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Optional; /** @@ -77,7 +77,7 @@ public class FormScriptCacheManager { return null; } - return FormScriptCacheConverter.convertReverse(formScriptCacheEntity.get()); + return formScriptCacheEntity.get().convertTo(); } /** @@ -93,11 +93,8 @@ public class FormScriptCacheManager { } List formScriptCacheList = new ArrayList<>(); // 创建并行流 进行数据转换 - formScriptCacheEntityList.parallelStream().forEach((cacheEntityItem) -> { - FormScriptCache formScriptCache = FormScriptCacheConverter.convertReverse(cacheEntityItem); - if (formScriptCache != null) { - formScriptCacheList.add(formScriptCache); - } + formScriptCacheEntityList.stream().filter(Objects::nonNull).forEach((cacheEntityItem) -> { + formScriptCacheList.add(cacheEntityItem.convertTo()); }); return formScriptCacheList; } @@ -114,9 +111,8 @@ public class FormScriptCacheManager { return null; } List formScriptCacheList = new ArrayList<>(); - formScriptCacheEntityList.forEach((cacheEntityItem) -> { - FormScriptCache formScriptCache = FormScriptCacheConverter.convertReverse(cacheEntityItem); - formScriptCacheList.add(formScriptCache); + formScriptCacheEntityList.stream().filter(Objects::nonNull).forEach((cacheEntityItem) -> { + formScriptCacheList.add(cacheEntityItem.convertTo()); }); return formScriptCacheList; } diff --git a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/manager/ScriptCacheVersionManager.java b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/manager/ScriptCacheVersionManager.java index 9d26a2ea..0413da03 100644 --- a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/manager/ScriptCacheVersionManager.java +++ b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/manager/ScriptCacheVersionManager.java @@ -6,9 +6,6 @@ import com.inspur.edp.web.common.utility.StringUtility; import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormProjectCache; import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormScriptCache; import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormScriptCacheContent; -import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.converter.FormProjectCacheConverter; -import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.converter.FormScriptCacheContentConverter; -import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.converter.FormScriptCacheConverter; import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.entity.FormProjectCacheEntity; import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.entity.FormScriptCacheContentEntity; import com.inspur.edp.web.jitruntimebuild.scriptcache.domain.entity.FormScriptCacheEntity; @@ -68,7 +65,7 @@ public class ScriptCacheVersionManager { if (StringUtility.isNullOrEmpty(formProjectCache.getId())) { formProjectCache.setId(CommonUtility.generateRandomId()); } - FormProjectCacheEntity projectCacheEntity = FormProjectCacheConverter.convert(formProjectCache); + FormProjectCacheEntity projectCacheEntity = FormProjectCacheEntity.convertFrom(formProjectCache); this.formProjectCacheManager.save(projectCacheEntity); } @@ -82,7 +79,7 @@ public class ScriptCacheVersionManager { if (StringUtility.isNullOrEmpty(formProjectCache.getId())) { formProjectCache.setId(CommonUtility.generateRandomId()); } - FormProjectCacheEntity projectCacheEntity = FormProjectCacheConverter.convert(formProjectCache); + FormProjectCacheEntity projectCacheEntity = FormProjectCacheEntity.convertFrom(formProjectCache); this.formProjectCacheManager.save(projectCacheEntity); } @@ -96,7 +93,7 @@ public class ScriptCacheVersionManager { if (StringUtility.isNullOrEmpty(formScriptCache.getId())) { formScriptCache.setId(CommonUtility.generateRandomId()); } - FormScriptCacheEntity scriptCacheEntity = FormScriptCacheConverter.convert(formScriptCache); + FormScriptCacheEntity scriptCacheEntity = FormScriptCacheEntity.convertFrom(formScriptCache); this.formScriptCacheManager.save(scriptCacheEntity); } @@ -110,7 +107,7 @@ public class ScriptCacheVersionManager { if (StringUtility.isNullOrEmpty(formScriptCache.getId())) { formScriptCache.setId(CommonUtility.generateRandomId()); } - FormScriptCacheEntity scriptCacheEntity = FormScriptCacheConverter.convert(formScriptCache); + FormScriptCacheEntity scriptCacheEntity = FormScriptCacheEntity.convertFrom(formScriptCache); this.formScriptCacheManager.update(scriptCacheEntity); } @@ -124,7 +121,7 @@ public class ScriptCacheVersionManager { if (StringUtility.isNullOrEmpty(formScriptCacheContent.getId())) { formScriptCacheContent.setId(CommonUtility.generateRandomId()); } - FormScriptCacheContentEntity contentEntity = FormScriptCacheContentConverter.convert(formScriptCacheContent); + FormScriptCacheContentEntity contentEntity = FormScriptCacheContentEntity.convertFrom(formScriptCacheContent); this.formScriptCacheContentManager.save(contentEntity); } @@ -138,7 +135,7 @@ public class ScriptCacheVersionManager { if (StringUtility.isNullOrEmpty(formScriptCacheContent.getId())) { formScriptCacheContent.setId(CommonUtility.generateRandomId()); } - FormScriptCacheContentEntity contentEntity = FormScriptCacheContentConverter.convert(formScriptCacheContent); + FormScriptCacheContentEntity contentEntity = FormScriptCacheContentEntity.convertFrom(formScriptCacheContent); this.formScriptCacheContentManager.update(contentEntity); } @@ -167,7 +164,7 @@ public class ScriptCacheVersionManager { public FormScriptCache getFormScriptCacheByMulCondition(String projectVersionId, String scriptName, String strScriptRelativePath) { // 脚本相对文件路径 strScriptRelativePath = FileUtility.getPlatformIndependentPath(strScriptRelativePath); - return this.formScriptCacheManager.getFormScriptCacheByMulCondition(projectVersionId,null, scriptName, strScriptRelativePath); + return this.formScriptCacheManager.getFormScriptCacheByMulCondition(projectVersionId, null, scriptName, strScriptRelativePath); } /** diff --git a/web-common/src/main/java/com/inspur/edp/web/common/converter/WebEntityConverter.java b/web-common/src/main/java/com/inspur/edp/web/common/converter/WebEntityConverter.java new file mode 100644 index 00000000..9f2a9d30 --- /dev/null +++ b/web-common/src/main/java/com/inspur/edp/web/common/converter/WebEntityConverter.java @@ -0,0 +1,19 @@ +package com.inspur.edp.web.common.converter; + + +public interface WebEntityConverter { + /** + * 执行转换操作 + * + * @param source + * @return + */ + T convertTo(S source); + + /** + * 从目标转换 + * @param source + * @return + */ + S convertFrom(T source); +} -- Gitee